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