File Coverage

blib/lib/Net/Duo/Admin/Integration.pm
Criterion Covered Total %
statement 23 23 100.0
branch 2 2 100.0
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 36 36 100.0


line stmt bran cond sub pod time code
1             # Representation of a single Duo integration for the Admin API.
2             #
3             # This class wraps the Duo representation of a single Duo integration, as
4             # returned by (for example) the Admin /integrations REST endpoint.
5              
6             package Net::Duo::Admin::Integration 1.01;
7              
8 6     6   95 use 5.014;
  6         19  
9 6     6   67 use strict;
  6         10  
  6         117  
10 6     6   28 use warnings;
  6         9  
  6         151  
11              
12 6     6   29 use parent qw(Net::Duo::Object);
  6         9  
  6         29  
13              
14             # Data specification for converting JSON into our object representation. See
15             # the Net::Duo::Object documentation for syntax information.
16             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
17             sub _fields {
18             return {
19 10     10   219 adminapi_admins => ['simple', 'zero_or_one'],
20             adminapi_info => ['simple', 'zero_or_one'],
21             adminapi_integrations => ['simple', 'zero_or_one'],
22             adminapi_read_log => ['simple', 'zero_or_one'],
23             adminapi_read_resource => ['simple', 'zero_or_one'],
24             adminapi_settings => ['simple', 'zero_or_one'],
25             adminapi_write_resource => ['simple', 'zero_or_one'],
26             enroll_policy => 'simple',
27             greeting => 'simple',
28             groups_allowed => 'array',
29             integration_key => 'simple',
30             ip_whitelist => 'array',
31             ip_whitelist_enroll_policy => 'simple',
32             name => 'simple',
33             notes => 'simple',
34             secret_key => 'simple',
35             trusted_device_days => 'simple',
36             type => 'simple',
37             username_normalization_policy => 'simple',
38             visual_style => 'simple',
39             };
40             }
41             ## use critic
42              
43             # Install our accessors.
44             Net::Duo::Admin::Integration->install_accessors;
45              
46             # Override the new method to support creating an integration from an ID
47             # instead of decoded JSON data.
48             #
49             # $class - Class of object to create
50             # $duo - Net::Duo object to use to create the object
51             # $id_or_data - Integration ID or reference to data
52             #
53             # Returns: Newly-created object
54             # Throws: Net::Duo::Exception on any problem creating the object
55             sub new {
56 2     2 1 93 my ($class, $duo, $id_or_data) = @_;
57 2 100       7 if (!ref($id_or_data)) {
58 1         4 my $uri = "/admin/v1/integrations/$id_or_data";
59 1         5 $id_or_data = $duo->call_json('GET', $uri);
60             }
61 2         15 return $class->SUPER::new($duo, $id_or_data);
62             }
63              
64             # Override the create method to add the appropriate URI.
65             #
66             # $class - Class of object to create
67             # $duo - Net::Duo object to use to create the object
68             # $data_ref - Data for new object as a reference to a hash
69             #
70             # Returns: Newly-created object
71             # Throws: Net::Duo::Exception on any problem creating the object
72             sub create {
73 1     1 1 89 my ($class, $duo, $data_ref) = @_;
74 1         11 return $class->SUPER::create($duo, '/admin/v1/integrations', $data_ref);
75             }
76              
77             # Delete the integration from Duo. After this call, the object should be
78             # treated as read-only since it can no longer be usefully updated.
79             #
80             # $self - The Net::Duo::Admin::Integration object to delete
81             #
82             # Returns: undef
83             # Throws: Net::Duo::Exception on any problem deleting the object
84             ## no critic (Subroutines::ProhibitBuiltinHomonyms)
85             sub delete {
86 1     1 1 71 my ($self) = @_;
87 1         3 my $id = $self->{integration_key};
88 1         8 $self->{_duo}->call_json('DELETE', "/admin/v1/integrations/$id");
89 1         3 return;
90             }
91             ## use critic
92              
93             1;
94             __END__