WebApi/Configuration.pm untested

filter: Statementstmt 0.0% 0 / 59 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 88 CC 8 SCAR 27.2
CC
8
Cov
0%
accept_tokens
30.0
get_tokens
20.0
clear_tokens
2.0
CRAP 15.2
1 =begin comment
2  
3 QueryBuilderApi
4  
5 Active Query Builder Web API lets create, analyze and modify SQL queries for different database servers using RESTful HTTP requests to a cloud-based service. It requires SQL execution context (information about database schema and used database server) to be stored under the registered account at https://webapi.activequerybuilder.com/.
6  
7 OpenAPI spec version: 1.1.8
8 Contact: support@activedbsoft.com
9 Generated by: https://github.com/swagger-api/swagger-codegen.git
10  
11 Licensed under the Apache License, Version 2.0 (the "License");
12 you may not use this file except in compliance with the License.
13 You may obtain a copy of the License at
14  
15 http://www.apache.org/licenses/LICENSE-2.0
16  
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22  
23 =end comment
24  
25 =cut
26  
27 #
28 # NOTE: This class is auto generated by the swagger code generator program.
29 # Do not edit the class manually.
30 # Ref: https://github.com/swagger-api/swagger-codegen
31 #
32 package SQL::QueryBuilder::WebApi::Configuration;
33  
34 use strict;
35 use warnings;
36 use utf8;
37  
38 use Log::Any qw($log);
39 use Carp;
40  
41 use constant VERSION => '1.1.8';
42  
43 # class/static variables
44 our $http_timeout = 180;
45 our $http_user_agent = 'Perl-Swagger';
46  
47 # authenticaiton setting
48 our $api_key = {};
49 our $api_key_prefix = {};
50 our $api_key_in = {};
51  
52 # username and password for HTTP basic authentication
53 our $username = '';
54 our $password = '';
55  
56 # access token for OAuth
57 our $access_token = '';
58  
59 sub get_tokens {
60 my $class = shift;
61
62 my $tokens = {};
63 $tokens->{username} = $username if $username;
64 $tokens->{password} = $password if $password;
65 $tokens->{access_token} = $access_token if $access_token;
66
67 foreach my $token_name (keys %{ $api_key }) {
68 $tokens->{$token_name}->{token} = $api_key->{$token_name};
69 $tokens->{$token_name}->{prefix} = $api_key_prefix->{$token_name};
70 $tokens->{$token_name}->{in} = $api_key_in->{$token_name};
71 }
72  
73 return $tokens;
74 }
75  
76 sub clear_tokens {
77 my $class = shift;
78 my %tokens = %{$class->get_tokens}; # copy
79
80 $username = undef;
81 $password = undef;
82 $access_token = undef;
83  
84 $api_key = {};
85 $api_key_prefix = {};
86 $api_key_in = {};
87
88 return \%tokens;
89 }
90  
91 sub accept_tokens {
92 my ($class, $tokens) = @_;
93
94 foreach my $known_name (qw(username password access_token)) {
95 next unless $tokens->{$known_name};
96 eval "\$$known_name = delete \$tokens->{\$known_name}";
97 die $@ if $@;
98 }
99
100 foreach my $token_name (keys %$tokens) {
101 $api_key->{$token_name} = $tokens->{$token_name}->{token};
102 if ($tokens->{$token_name}->{prefix}) {
103 $api_key_prefix->{$token_name} = $tokens->{$token_name}->{prefix};
104 }
105 my $in = $tokens->{$token_name}->{in} || 'head';
106 croak "Tokens can only go in 'head' or 'query' (not in '$in')" unless $in =~ /^(?:head|query)$/;
107 $api_key_in->{$token_name} = $in;
108 }
109 }
110  
111 1;