line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Representation of a single Duo token for the Admin API. |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This class wraps the Duo representation of a single Duo token, as returned |
4
|
|
|
|
|
|
|
# by (for example) the Admin /tokens REST endpoint. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# SPDX-License-Identifier: MIT |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Net::Duo::Admin::Token 1.02; |
9
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
115
|
use 5.014; |
|
6
|
|
|
|
|
22
|
|
11
|
6
|
|
|
6
|
|
33
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
125
|
|
12
|
6
|
|
|
6
|
|
37
|
use warnings; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
240
|
|
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
6
|
|
36
|
use parent qw(Net::Duo::Object); |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
38
|
|
15
|
|
|
|
|
|
|
|
16
|
6
|
|
|
6
|
|
554
|
use Net::Duo::Admin::User; |
|
6
|
|
|
|
|
27
|
|
|
6
|
|
|
|
|
1490
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Data specification for converting JSON into our object representation. See |
19
|
|
|
|
|
|
|
# the Net::Duo::Object documentation for syntax information. |
20
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
21
|
|
|
|
|
|
|
sub _fields { |
22
|
|
|
|
|
|
|
return { |
23
|
13
|
|
|
13
|
|
68
|
serial => 'simple', |
24
|
|
|
|
|
|
|
token_id => 'simple', |
25
|
|
|
|
|
|
|
type => 'simple', |
26
|
|
|
|
|
|
|
users => 'Net::Duo::Admin::User', |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
## use critic |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Install our accessors. |
32
|
|
|
|
|
|
|
Net::Duo::Admin::Token->install_accessors; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Override the new method to support creating a token from an ID instead |
35
|
|
|
|
|
|
|
# of decoded JSON data. |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# $class - Class of object to create |
38
|
|
|
|
|
|
|
# $duo - Net::Duo object to use to create the object |
39
|
|
|
|
|
|
|
# $id_or_data - Token ID or reference to data |
40
|
|
|
|
|
|
|
# |
41
|
|
|
|
|
|
|
# Returns: Newly-created object |
42
|
|
|
|
|
|
|
# Throws: Net::Duo::Exception on any problem creating the object |
43
|
|
|
|
|
|
|
sub new { |
44
|
3
|
|
|
3
|
1
|
8
|
my ($class, $duo, $id_or_data) = @_; |
45
|
3
|
50
|
|
|
|
8
|
if (!ref($id_or_data)) { |
46
|
0
|
|
|
|
|
0
|
$id_or_data = $duo->call_json('GET', "/admin/v1/tokens/$id_or_data"); |
47
|
|
|
|
|
|
|
} |
48
|
3
|
|
|
|
|
12
|
return $class->SUPER::new($duo, $id_or_data); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Override the create method to add the appropriate URI. |
52
|
|
|
|
|
|
|
# |
53
|
|
|
|
|
|
|
# $class - Class of object to create |
54
|
|
|
|
|
|
|
# $duo - Net::Duo object to use to create the object |
55
|
|
|
|
|
|
|
# $data_ref - Data for new object as a reference to a hash |
56
|
|
|
|
|
|
|
# |
57
|
|
|
|
|
|
|
# Returns: Newly-created object |
58
|
|
|
|
|
|
|
# Throws: Net::Duo::Exception on any problem creating the object |
59
|
|
|
|
|
|
|
sub create { |
60
|
1
|
|
|
1
|
1
|
406
|
my ($class, $duo, $data_ref) = @_; |
61
|
1
|
|
|
|
|
12
|
return $class->SUPER::create($duo, '/admin/v1/tokens', $data_ref); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Delete the token from Duo. After this call, the object should be treated as |
65
|
|
|
|
|
|
|
# read-only since it can no longer be usefully updated. |
66
|
|
|
|
|
|
|
# |
67
|
|
|
|
|
|
|
# $self - The Net::Duo::Admin::Token object to delete |
68
|
|
|
|
|
|
|
# |
69
|
|
|
|
|
|
|
# Returns: undef |
70
|
|
|
|
|
|
|
# Throws: Net::Duo::Exception on any problem deleting the object |
71
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitBuiltinHomonyms) |
72
|
|
|
|
|
|
|
sub delete { |
73
|
1
|
|
|
1
|
1
|
4
|
my ($self) = @_; |
74
|
1
|
|
|
|
|
8
|
$self->{_duo}->call_json('DELETE', "/admin/v1/tokens/$self->{token_id}"); |
75
|
1
|
|
|
|
|
3
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
## use critic |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
__END__ |