Fastly/Configuration.pm untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 125 CC 7 SCAR 24.0
CC
7
Cov
0%
get_tokens
20.0
accept_tokens
20.0
new
2.0
CRAP 11.0
1 =begin comment
2  
3 Fastly API
4  
5 Via the Fastly API you can perform any of the operations that are possible within the management console, including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/)
6  
7 The version of the API Spec document: 1.0.0
8 Contact: oss@fastly.com
9  
10 =end comment
11  
12 =cut
13  
14 #
15 # NOTE: This class is auto generated.
16 # Do not edit the class manually.
17 #
18 package WebService::Fastly::Configuration;
19  
20 use strict;
21 use warnings;
22 use utf8;
23  
24 use Log::Any qw($log);
25 use Carp;
26  
27 use constant VERSION => '16.01';
28  
29 =head1 Name
30  
31 WebService::Fastly::Configuration - holds the configuration for all WebService::Fastly Modules
32  
33 =head1 new(%parameters)
34  
35 =over 4
36  
37 =item http_timeout: (optional)
38  
39 Integer. timeout for HTTP requests in seconds
40  
41 default: 180
42  
43 =item http_user_agent: (optional)
44  
45 String. custom UserAgent header
46  
47 default: fastly-perl/16.01
48  
49 =item api_key: (optional)
50  
51 Hashref. Keyed on the name of each key (there can be multiple tokens).
52  
53 api_key => {
54 secretKey => 'aaaabbbbccccdddd',
55 anotherKey => '1111222233334444',
56 };
57  
58 =item api_key_prefix: (optional)
59  
60 Hashref. Keyed on the name of each key (there can be multiple tokens). Note not all api keys require a prefix.
61  
62 api_key_prefix => {
63 secretKey => 'string',
64 anotherKey => 'same or some other string',
65 };
66  
67 =item api_key_in: (optional)
68  
69 =item username: (optional)
70  
71 String. The username for basic auth.
72  
73 =item password: (optional)
74  
75 String. The password for basic auth.
76  
77 =item access_token: (optional)
78  
79 String. The OAuth access token.
80  
81 =item base_url: (optional)
82  
83 String. The base URL of the API
84  
85 default: https://api.fastly.com
86  
87 =back
88  
89 =cut
90  
91 sub new {
92 my ($self, %p) = (shift,@_);
93  
94 # class/static variables
95 $p{http_timeout} //= 180;
96 $p{http_user_agent} //= 'fastly-perl/16.01';
97  
98 # authentication setting
99 $p{api_key} //= {};
100 $p{api_key_prefix} //= {};
101 $p{api_key_in} //= {};
102  
103 # username and password for HTTP basic authentication
104 $p{username} //= '';
105 $p{password} //= '';
106  
107 # access token for OAuth
108 $p{access_token} //= '';
109  
110 # base_url
111 $p{base_url} //= 'https://api.fastly.com';
112  
113 # The last observed value of http header Fastly-RateLimit-Remaining
114 # https://www.fastly.com/documentation/reference/api/#rate-limiting
115 $p{rate_limit_remaining} //= 1000;
116  
117 # The last observed value of http header Fastly-RateLimit-Reset
118 $p{rate_limit_remaining} //= undef;
119  
120 return bless \%p => $self;
121 }
122  
123  
124 sub get_tokens {
125 my $self = shift;
126  
127 my $tokens = {};
128 $tokens->{username} = $self->{username} if $self->{username};
129 $tokens->{password} = $self->{password} if $self->{password};
130 $tokens->{access_token} = $self->{access_token} if $self->{access_token};
131  
132 foreach my $token_name (keys %{ $self->{api_key} }) {
133 $tokens->{$token_name}->{token} = $self->{api_key}{$token_name};
134 $tokens->{$token_name}->{prefix} = $self->{api_key_prefix}{$token_name};
135 $tokens->{$token_name}->{in} = $self->{api_key_in}{$token_name};
136 }
137  
138 return $tokens;
139 }
140  
141 sub clear_tokens {
142 my $self = shift;
143 my %tokens = %{$self->get_tokens}; # copy
144  
145 $self->{username} = '';
146 $self->{password} = '';
147 $self->{access_token} = '';
148  
149 $self->{api_key} = {};
150 $self->{api_key_prefix} = {};
151 $self->{api_key_in} = {};
152  
153 return \%tokens;
154 }
155  
156 sub accept_tokens {
157 my ($self, $tokens) = @_;
158  
159 foreach my $known_name (qw(username password access_token)) {
160 next unless $tokens->{$known_name};
161 $self->{$known_name} = delete $tokens->{$known_name};
162 }
163  
164 foreach my $token_name (keys %$tokens) {
165 $self->{api_key}{$token_name} = $tokens->{$token_name}{token};
166 if ($tokens->{$token_name}{prefix}) {
167 $self->{api_key_prefix}{$token_name} = $tokens->{$token_name}{prefix};
168 }
169 my $in = $tokens->{$token_name}->{in} || 'head';
170 croak "Tokens can only go in 'head' or 'query' (not in '$in')" unless $in =~ /^(?:head|query)$/;
171 $self->{api_key_in}{$token_name} = $in;
172 }
173 }
174  
175 1;