Configuration.pm untested

filter: Statementstmt 0.0% 0 / 64 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 123 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 Copyright (c) 2026 Aspose.Cells Cloud
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21
22 =end comment
23
24 =cut
25
26 package AsposeCellsCloud::Configuration;
27
28 use strict;
29 use warnings;
30 use utf8;
31
32 use Log::Any qw($log);
33 use Carp;
34
35 use constant VERSION => '26.3.1';
36
37 =head1 Name
38
39 AsposeCellsCloud::Configuration - holds the configuration for all AsposeCellsCloud Modules
40
41 =head1 new(%parameters)
42
43 =over 4
44
45 =item http_timeout: (optional)
46
47 Integer. timeout for HTTP requests in seconds
48
49 default: 180
50
51 =item http_user_agent: (optional)
52
53 String. custom UserAgent header
54
55 default: Swagger-CodeGen/22.5/perl
56
57 =item api_key: (optional)
58
59 Hashref. Keyed on the name of each key (there can be multiple tokens).
60
61 api_key => {
62 secretKey => 'aaaabbbbccccdddd',
63 anotherKey => '1111222233334444',
64 };
65
66 =item api_key_prefix: (optional)
67
68 Hashref. Keyed on the name of each key (there can be multiple tokens). Note not all api keys require a prefix.
69
70 api_key_prefix => {
71 secretKey => 'string',
72 anotherKey => 'same or some other string',
73 };
74
75 =item api_key_in: (optional)
76
77 =item username: (optional)
78
79 String. The username for basic auth.
80
81 =item password: (optional)
82
83 String. The password for basic auth.
84
85 =item access_token: (optional)
86
87 String. The OAuth access token.
88
89 =item base_url: (optional)
90
91 String. The base URL of the API
92
93 default: https://api.aspose.cloud/v3.0
94
95 =item client_id: (optional)
96 String. Application SID.
97
98 =item client_secret: (optional)
99 String. Application Key.
100
101 =item api_version:(optional)
102 String. api version.
103 default: v3.0
104
105 =back
106
107 =cut
108
109 sub new {
110 my ($self, %p) = (shift,@_);
111
112 # class/static variables
113 $p{http_timeout} //= 180;
114 $p{http_user_agent} //= 'Apose.Cells.Cloud.SDK/26.3.1/perl';
115
116 # authentication setting
117 $p{api_key} //= {};
118 $p{api_key_prefix} //= {};
119 $p{api_key_in} //= {};
120
121 # username and password for HTTP basic authentication
122 $p{username} //= '';
123 $p{password} //= '';
124
125 # access token for OAuth
126 $p{access_token} //= '';
127
128 # base_url
129 $p{base_url} //= 'https://api.aspose.cloud';
130 $p{api_version} //= 'v4.0';
131
132 return bless \%p => $self;
133 }
134
135
136 sub get_tokens {
137 my $self = shift;
138
139 my $tokens = {};
140 $tokens->{username} = $self->{username} if $self->{username};
141 $tokens->{password} = $self->{password} if $self->{password};
142 #$tokens->{client_id} = $self->{client_id} if $self->{client_id};
143 #$tokens->{client_secret} = $self->{client_secret} if $self->{client_secret};
144 $tokens->{access_token} = $self->{access_token} if $self->{access_token};
145
146 foreach my $token_name (keys %{ $self->{api_key} }) {
147 $tokens->{$token_name}->{token} = $self->{api_key}{$token_name};
148 $tokens->{$token_name}->{prefix} = $self->{api_key_prefix}{$token_name};
149 $tokens->{$token_name}->{in} = $self->{api_key_in}{$token_name};
150 }
151
152 return $tokens;
153 }
154
155 sub clear_tokens {
156 my $self = shift;
157 my %tokens = %{$self->get_tokens}; # copy
158
159 $self->{username} = '';
160 $self->{password} = '';
161 $self->{client_id} = '';
162 $self->{client_secret} = '';
163 $self->{access_token} = '';
164
165 $self->{api_key} = {};
166 $self->{api_key_prefix} = {};
167 $self->{api_key_in} = {};
168
169 return \%tokens;
170 }
171
172 sub accept_tokens {
173 my ($self, $tokens) = @_;
174
175 foreach my $known_name (qw(username password access_token)) {
176 next unless $tokens->{$known_name};
177 $self->{$known_name} = delete $tokens->{$known_name};
178 }
179
180 foreach my $token_name (keys %$tokens) {
181 $self->{api_key}{$token_name} = $tokens->{$token_name}{token};
182 if ($tokens->{$token_name}{prefix}) {
183 $self->{api_key_prefix}{$token_name} = $tokens->{$token_name}{prefix};
184 }
185 my $in = $tokens->{$token_name}->{in} || 'head';
186 croak "Tokens can only go in 'head' or 'query' (not in '$in')" unless $in =~ /^(?:head|query)$/;
187 $self->{api_key_in}{$token_name} = $in;
188 }
189 }
190
191 1;