-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathConfiguration.pm
172 lines (114 loc) · 3.82 KB
/
Configuration.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
=begin comment
Kubernetes
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
The version of the OpenAPI document: v1.13.7
Generated by: https://openapi-generator.tech
=end comment
=cut
#
# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
# Do not edit the class manually.
# Ref: https://openapi-generator.tech
#
package Kubernetes::Configuration;
use strict;
use warnings;
use utf8;
use Log::Any qw($log);
use Carp;
use constant VERSION => '1.0.0';
=head1 Name
Kubernetes::Configuration - holds the configuration for all Kubernetes Modules
=head1 new(%parameters)
=over 4
=item http_timeout: (optional)
Integer. timeout for HTTP requests in seconds
default: 180
=item http_user_agent: (optional)
String. custom UserAgent header
default: OpenAPI-Generator/1.0.0/perl
=item api_key: (optional)
Hashref. Keyed on the name of each key (there can be multiple tokens).
api_key => {
secretKey => 'aaaabbbbccccdddd',
anotherKey => '1111222233334444',
};
=item api_key_prefix: (optional)
Hashref. Keyed on the name of each key (there can be multiple tokens). Note not all api keys require a prefix.
api_key_prefix => {
secretKey => 'string',
anotherKey => 'same or some other string',
};
=item api_key_in: (optional)
=item username: (optional)
String. The username for basic auth.
=item password: (optional)
String. The password for basic auth.
=item access_token: (optional)
String. The OAuth access token.
=item base_url: (optional)
String. The base URL of the API
default: http://localhost
=back
=cut
sub new {
my ( $self, %p ) = ( shift, @_ );
# class/static variables
$p{http_timeout} //= 180;
$p{http_user_agent} //= 'OpenAPI-Generator/1.0.0/perl';
# authentication setting
$p{api_key} //= {};
$p{api_key_prefix} //= {};
$p{api_key_in} //= {};
# username and password for HTTP basic authentication
$p{username} //= '';
$p{password} //= '';
# access token for OAuth
$p{access_token} //= '';
# base_url
$p{base_url} //= 'http://localhost';
return bless \%p => $self;
}
sub get_tokens {
my $self = shift;
my $tokens = {};
$tokens->{username} = $self->{username} if $self->{username};
$tokens->{password} = $self->{password} if $self->{password};
$tokens->{access_token} = $self->{access_token} if $self->{access_token};
foreach my $token_name ( keys %{ $self->{api_key} } ) {
$tokens->{$token_name}->{token} = $self->{api_key}{$token_name};
$tokens->{$token_name}->{prefix} = $self->{api_key_prefix}{$token_name};
$tokens->{$token_name}->{in} = $self->{api_key_in}{$token_name};
}
return $tokens;
}
sub clear_tokens {
my $self = shift;
my %tokens = %{ $self->get_tokens }; # copy
$self->{username} = '';
$self->{password} = '';
$self->{access_token} = '';
$self->{api_key} = {};
$self->{api_key_prefix} = {};
$self->{api_key_in} = {};
return \%tokens;
}
sub accept_tokens {
my ( $self, $tokens ) = @_;
foreach my $known_name (qw(username password access_token)) {
next unless $tokens->{$known_name};
$self->{$known_name} = delete $tokens->{$known_name};
}
foreach my $token_name ( keys %$tokens ) {
$self->{api_key}{$token_name} = $tokens->{$token_name}{token};
if ( $tokens->{$token_name}{prefix} ) {
$self->{api_key_prefix}{$token_name} =
$tokens->{$token_name}{prefix};
}
my $in = $tokens->{$token_name}->{in} || 'head';
croak "Tokens can only go in 'head' or 'query' (not in '$in')"
unless $in =~ /^(?:head|query)$/;
$self->{api_key_in}{$token_name} = $in;
}
}
1;