| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::OpenStack::Swift::InnerKeystone::Base; | 
| 2 | 6 |  |  | 6 |  | 55834 | use Carp; | 
|  | 6 |  |  |  |  | 16 |  | 
|  | 6 |  |  |  |  | 331 |  | 
| 3 | 6 |  |  | 6 |  | 363 | use Mouse; | 
|  | 6 |  |  |  |  | 19018 |  | 
|  | 6 |  |  |  |  | 43 |  | 
| 4 | 6 |  |  | 6 |  | 2984 | use JSON; | 
|  | 6 |  |  |  |  | 8829 |  | 
|  | 6 |  |  |  |  | 48 |  | 
| 5 | 6 |  |  | 6 |  | 2556 | use Furl; | 
|  | 6 |  |  |  |  | 113629 |  | 
|  | 6 |  |  |  |  | 188 |  | 
| 6 | 6 |  |  | 6 |  | 332 | use Data::Validator; | 
|  | 6 |  |  |  |  | 2414 |  | 
|  | 6 |  |  |  |  | 167 |  | 
| 7 | 6 |  |  | 6 |  | 1655 | use namespace::clean -except => 'meta'; | 
|  | 6 |  |  |  |  | 66536 |  | 
|  | 6 |  |  |  |  | 39 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | has auth_token      => ( is => 'rw' ); | 
| 10 |  |  |  |  |  |  | has service_catalog => ( is => 'rw' ); | 
| 11 |  |  |  |  |  |  | has auth_url        => ( is => 'rw', required => 1 ); | 
| 12 |  |  |  |  |  |  | has user            => ( is => 'rw', required => 1 ); | 
| 13 |  |  |  |  |  |  | has password        => ( is => 'rw', required => 1 ); | 
| 14 |  |  |  |  |  |  | has tenant_name     => ( is => 'rw' ); | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | #has verify_ssl      => (is => 'ro', default => sub {! $ENV{OSCOMPUTE_INSECURE}}); | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | has agent => ( | 
| 19 |  |  |  |  |  |  | is      => 'rw', | 
| 20 |  |  |  |  |  |  | lazy    => 1, | 
| 21 |  |  |  |  |  |  | default => sub { | 
| 22 |  |  |  |  |  |  | my $self  = shift; | 
| 23 |  |  |  |  |  |  | my $agent = Furl->new; | 
| 24 |  |  |  |  |  |  | return $agent; | 
| 25 |  |  |  |  |  |  | }, | 
| 26 |  |  |  |  |  |  | ); | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 0 |  |  | 0 | 0 | 0 | sub get_auth_params { die; } | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | sub service_catalog_url_for { | 
| 31 | 1 |  |  | 1 | 0 | 4548 | my $self = shift; | 
| 32 |  |  |  |  |  |  | my $rule = Data::Validator->new( | 
| 33 |  |  |  |  |  |  | endpoint_type => { | 
| 34 |  |  |  |  |  |  | isa     => 'Str', | 
| 35 | 0 |  |  | 0 |  | 0 | default => sub { 'object-store' } | 
| 36 |  |  |  |  |  |  | }, | 
| 37 |  |  |  |  |  |  | service_type => { | 
| 38 |  |  |  |  |  |  | isa     => 'Str', | 
| 39 | 0 |  |  | 0 |  | 0 | default => sub { 'publicURL' } | 
| 40 |  |  |  |  |  |  | }, | 
| 41 | 1 |  |  |  |  | 29 | region => { isa => 'Str', default => undef }, | 
| 42 |  |  |  |  |  |  | ); | 
| 43 | 1 |  |  |  |  | 199 | my $args = $rule->validate(@_); | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 1 |  |  |  |  | 65 | my $found_endpoint; | 
| 46 | 1 |  |  |  |  | 2 | foreach my $service_catelog ( @{ $self->service_catalog } ) { | 
|  | 1 |  |  |  |  | 4 |  | 
| 47 | 2 | 100 |  |  |  | 7 | if ( $args->{service_type} eq $service_catelog->{type} ) { | 
| 48 | 1 |  |  |  |  | 2 | foreach my $endpoint ( @{ $service_catelog->{endpoints} } ) { | 
|  | 1 |  |  |  |  | 3 |  | 
| 49 | 1 | 50 |  |  |  | 4 | if ( exists $endpoint->{ $args->{endpoint_type} } ) { | 
| 50 | 1 |  |  |  |  | 2 | $found_endpoint = $endpoint; | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | # filtering match Region | 
| 53 | 1 | 50 | 33 |  |  | 4 | if ( $args->{region} and $args->{region} ne $endpoint->{region} ) { | 
| 54 | 0 |  |  |  |  | 0 | $found_endpoint = undef; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  | } | 
| 60 | 1 | 50 |  |  |  | 5 | unless ($found_endpoint) { | 
| 61 | 0 |  |  |  |  | 0 | croak sprintf( "%s endpoint for %s service not found", $args->{endpoint_type}, $args->{service_type} ); | 
| 62 |  |  |  |  |  |  | } | 
| 63 | 1 |  |  |  |  | 11 | return $found_endpoint->{ $args->{endpoint_type} }; | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | package Net::OpenStack::Swift::InnerKeystone::V1_0; | 
| 67 | 6 |  |  | 6 |  | 4269 | use Carp; | 
|  | 6 |  |  |  |  | 14 |  | 
|  | 6 |  |  |  |  | 356 |  | 
| 68 | 6 |  |  | 6 |  | 36 | use JSON; | 
|  | 6 |  |  |  |  | 13 |  | 
|  | 6 |  |  |  |  | 52 |  | 
| 69 | 6 |  |  | 6 |  | 717 | use Mouse; | 
|  | 6 |  |  |  |  | 12 |  | 
|  | 6 |  |  |  |  | 47 |  | 
| 70 | 6 |  |  | 6 |  | 2449 | use namespace::clean -except => 'meta'; | 
|  | 6 |  |  |  |  | 12 |  | 
|  | 6 |  |  |  |  | 36 |  | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | extends 'Net::OpenStack::Swift::InnerKeystone::Base'; | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | sub get_auth_params { | 
| 75 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 76 |  |  |  |  |  |  | return { | 
| 77 | 0 |  |  |  |  |  | auth => { | 
| 78 |  |  |  |  |  |  | tenantName          => 'no-needed', | 
| 79 |  |  |  |  |  |  | passwordCredentials => { | 
| 80 |  |  |  |  |  |  | username => $self->user, | 
| 81 |  |  |  |  |  |  | password => $self->password, | 
| 82 |  |  |  |  |  |  | } | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  | }; | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | sub auth { | 
| 88 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 89 | 0 |  |  |  |  |  | my $res  = $self->agent->get( | 
| 90 |  |  |  |  |  |  | $self->auth_url, | 
| 91 |  |  |  |  |  |  | [ | 
| 92 |  |  |  |  |  |  | 'X-Auth-Key'  => $self->password, | 
| 93 |  |  |  |  |  |  | 'X-Auth-User' => $self->user | 
| 94 |  |  |  |  |  |  | ] | 
| 95 |  |  |  |  |  |  | ); | 
| 96 | 0 | 0 |  |  |  |  | croak "authorization failed: " . $res->status_line unless $res->is_success; | 
| 97 | 0 |  |  |  |  |  | my $body_params = from_json( $res->content ); | 
| 98 | 0 |  |  |  |  |  | my $url         = $body_params->{storage}->{ $self->tenant_name }; | 
| 99 | 0 |  |  |  |  |  | $self->auth_token( $res->header('X-Auth-Token') ); | 
| 100 | 0 |  |  |  |  |  | $self->service_catalog( | 
| 101 |  |  |  |  |  |  | [ | 
| 102 |  |  |  |  |  |  | { | 
| 103 |  |  |  |  |  |  | type      => 'object-store', | 
| 104 |  |  |  |  |  |  | endpoints => [ { endpoint_type => 'publicURL', publicURL => $url } ] | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  | ] | 
| 107 |  |  |  |  |  |  | ); | 
| 108 | 0 |  |  |  |  |  | return $self->auth_token(); | 
| 109 |  |  |  |  |  |  | } | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | package Net::OpenStack::Swift::InnerKeystone::V2_0; | 
| 112 | 6 |  |  | 6 |  | 3315 | use Carp; | 
|  | 6 |  |  |  |  | 12 |  | 
|  | 6 |  |  |  |  | 303 |  | 
| 113 | 6 |  |  | 6 |  | 45 | use JSON; | 
|  | 6 |  |  |  |  | 13 |  | 
|  | 6 |  |  |  |  | 22 |  | 
| 114 | 6 |  |  | 6 |  | 537 | use Mouse; | 
|  | 6 |  |  |  |  | 14 |  | 
|  | 6 |  |  |  |  | 39 |  | 
| 115 | 6 |  |  | 6 |  | 1930 | use namespace::clean -except => 'meta'; | 
|  | 6 |  |  |  |  | 12 |  | 
|  | 6 |  |  |  |  | 24 |  | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | extends 'Net::OpenStack::Swift::InnerKeystone::Base'; | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | sub get_auth_params { | 
| 120 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 121 |  |  |  |  |  |  | return { | 
| 122 | 0 |  |  |  |  |  | auth => { | 
| 123 |  |  |  |  |  |  | tenantName          => $self->tenant_name, | 
| 124 |  |  |  |  |  |  | passwordCredentials => { | 
| 125 |  |  |  |  |  |  | username => $self->user, | 
| 126 |  |  |  |  |  |  | password => $self->password, | 
| 127 |  |  |  |  |  |  | } | 
| 128 |  |  |  |  |  |  | } | 
| 129 |  |  |  |  |  |  | }; | 
| 130 |  |  |  |  |  |  | } | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | sub auth { | 
| 133 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 134 | 0 |  |  |  |  |  | my $res  = $self->agent->post( | 
| 135 |  |  |  |  |  |  | $self->auth_url . "/tokens", | 
| 136 |  |  |  |  |  |  | [ 'Content-Type' => 'application/json' ], | 
| 137 |  |  |  |  |  |  | to_json( $self->get_auth_params ), | 
| 138 |  |  |  |  |  |  | ); | 
| 139 | 0 | 0 |  |  |  |  | croak "authorization failed: " . $res->status_line unless $res->is_success; | 
| 140 | 0 |  |  |  |  |  | my $body_params = from_json( $res->content ); | 
| 141 | 0 |  |  |  |  |  | $self->auth_token( $body_params->{access}->{token}->{id} ); | 
| 142 | 0 |  |  |  |  |  | $self->service_catalog( $body_params->{access}->{serviceCatalog} ); | 
| 143 | 0 |  |  |  |  |  | return $self->auth_token(); | 
| 144 |  |  |  |  |  |  | } | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | package Net::OpenStack::Swift::InnerKeystone::V3_0; | 
| 147 | 6 |  |  | 6 |  | 3046 | use Carp; | 
|  | 6 |  |  |  |  | 11 |  | 
|  | 6 |  |  |  |  | 271 |  | 
| 148 | 6 |  |  | 6 |  | 65 | use JSON; | 
|  | 6 |  |  |  |  | 11 |  | 
|  | 6 |  |  |  |  | 21 |  | 
| 149 | 6 |  |  | 6 |  | 483 | use Mouse; | 
|  | 6 |  |  |  |  | 30 |  | 
|  | 6 |  |  |  |  | 23 |  | 
| 150 | 6 |  |  | 6 |  | 1736 | use namespace::clean -except => 'meta'; | 
|  | 6 |  |  |  |  | 12 |  | 
|  | 6 |  |  |  |  | 23 |  | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | extends 'Net::OpenStack::Swift::InnerKeystone::Base'; | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  | 0 | 0 |  | sub get_auth_params { | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | #return { | 
| 157 |  |  |  |  |  |  | #    auth => { | 
| 158 |  |  |  |  |  |  | #        identity => { | 
| 159 |  |  |  |  |  |  | #            methods => ['password'], | 
| 160 |  |  |  |  |  |  | #            password => { | 
| 161 |  |  |  |  |  |  | #                user => { | 
| 162 |  |  |  |  |  |  | #                    name => $self->user, | 
| 163 |  |  |  |  |  |  | #                    domain => {id => "default"}, | 
| 164 |  |  |  |  |  |  | #                    password => $self->password, | 
| 165 |  |  |  |  |  |  | #                } | 
| 166 |  |  |  |  |  |  | #            } | 
| 167 |  |  |  |  |  |  | #        } | 
| 168 |  |  |  |  |  |  | #    } | 
| 169 |  |  |  |  |  |  | #}; | 
| 170 |  |  |  |  |  |  | } | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | sub auth { | 
| 173 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 174 | 0 |  |  |  |  |  | croak "not implemented yet......"; | 
| 175 |  |  |  |  |  |  | } | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | 1; |