| 1 | package Apigee::Edge::Helper; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.08'; ## VERSION | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use base 'Apigee::Edge'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use URI::Split qw(uri_split); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use vars qw/$errstr/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub errstr { return $errstr || Apigee::Edge->errstr } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errstr: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/3
$Apigee::Edge::Helper::errstr || 'Apigee::Edge'->errstr
MC/DC0%0/2
$Apigee::Edge::Helper::errstr || 'Apigee::Edge'->errstr
$Apigee::Edge::Helper::errstr
'Apigee::Edge'->errstr
Truth table0%0/3
A || B
A= $Apigee::Edge::Helper::errstrB= 'Apigee::Edge'->errstr
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub get_top_developer_app { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_top_developer_app: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | my ($self, $email) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my $apps = $self->get_developer_apps($email, {expand => 'true'}); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | return unless ($apps and $apps->{app} and scalar(@{$apps->{app}})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$apps and $apps->{"app"} and scalar @{$apps->{"app"};}
$apps and $apps->{"app"}
MC/DC0%0/2
$apps and $apps->{"app"} and scalar @{$apps->{"app"};}
$apps
$apps->{"app"}
Truth table0%0/3
A and B
A= $appsB= $apps->{"app"}
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my $my_app = $apps->{app}->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # flatten attrs into $my_app | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my %attrs = map { $_->{name} => $_->{value} } @{$my_app->{attributes}}; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | $my_app = {%$my_app, %attrs}; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | $my_app->{display_name} = $attrs{DisplayName} || $my_app->{name}; # shortcut | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$attrs{'DisplayName'} || $my_app->{'name'}
MC/DC0%0/2
$attrs{'DisplayName'} || $my_app->{'name'}
$attrs{'DisplayName'}
$my_app->{'name'}
Truth table0%0/3
A || B
A= $attrs{'DisplayName'}B= $my_app->{'name'}
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | return $my_app; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub refresh_developer_app { ## no critic (ArgUnpacking) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
refresh_developer_app: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my %params = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $name = $params{name}; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if (!$name) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $errstr = 'Application Name must be provided.'; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } elsif ($name !~ /^[\w\s-]{5,30}$/) { # restrict to only 5-30 alphanumerics or spaces. | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $errstr = 'Application Name data is invalid.'; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $callback_url = $params{callbackUrl}; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if (!$callback_url) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $errstr = 'Callback URL must be provided.'; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } elsif ($callback_url =~ /['"<>]/) { # rule out quotes or anglebrackets. | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $errstr = 'Callback URL data is invalid.'; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my ($scheme, $host, $path) = uri_split($callback_url); | |||||||||||||||||||||||||||||||||||||||||
| 52 | # in theory a uri can be almost anything; but for sanity insist on at least this much.. | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | unless ($scheme && $host && $path) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$scheme and $host and $path
$scheme and $host
MC/DC0%0/3
$scheme and $host and $path
$scheme
$host
$path
Truth table0%0/4
A and B and C
A= $schemeB= $hostC= $path
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $errstr = 'Callback URL format is invalid. '; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $email = $params{email}; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $my_app = $params{app}; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | unless (exists $params{app}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $my_app = $self->get_top_developer_app($email); | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ($my_app) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | # update app | ||||||||||||||||||||||||||||||||||||||||||
| 67 | $self->update_developer_app( | ||||||||||||||||||||||||||||||||||||||||||
| 68 | $email, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | $my_app->{name}, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | attributes => [{ | |||||||||||||||||||||||||||||||||||||||||
| 72 | name => 'DisplayName', | ||||||||||||||||||||||||||||||||||||||||||
| 73 | value => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 76 | callbackUrl => $callback_url, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $my_app->{display_name} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $my_app->{callbackUrl} = $callback_url; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $errstr = 'Update successful'; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $developer = $self->get_developer($email); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | unless ($developer and $developer->{developerId}) { # create on demand | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$developer and $developer->{"developerId"}
MC/DC0%0/2
$developer and $developer->{"developerId"}
$developer
$developer->{"developerId"}
Truth table0%0/3
A and B
A= $developerB= $developer->{"developerId"}
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | $developer = $self->create_developer( | ||||||||||||||||||||||||||||||||||||||||||
| 85 | "email" => $email, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | "firstName" => $params{firstName}, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | "lastName" => $params{lastName}, | ||||||||||||||||||||||||||||||||||||||||||
| 88 | "userName" => $params{userName}, | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | $my_app = $self->create_developer_app( | ||||||||||||||||||||||||||||||||||||||||||
| 93 | $email, | ||||||||||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 96 | callbackUrl => $callback_url, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $params{apiProducts} ? (apiProducts => $params{apiProducts}) : (), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ($my_app->{message}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $errstr = $my_app->{message}; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $my_app->{display_name} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $errstr = "$name has been registered. New OAuth credentials are available"; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | return $my_app; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub get_all_clients { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all_clients: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | my $apps = $self->get_apps( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | expand => 'true', | ||||||||||||||||||||||||||||||||||||||||||
| 115 | includeCred => 'true' | ||||||||||||||||||||||||||||||||||||||||||
| 116 | ) or croak "Apigee::Edge failure: " . $self->errstr; | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $CLIENTS = {}; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | for my $app (@{$apps->{app}}) { | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | next unless $app->{status} eq 'approved'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | my $consumerKey = eval { | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
my $credentials = $app->{'credentials'};
$credentials->[0]{'consumerKey'}
}
} || (next)
MC/DC0%0/1
eval {
do {
my $credentials = $app->{'credentials'};
$credentials->[0]{'consumerKey'}
}
} || (next)
eval {
do {
my $credentials = $app->{'credentials'};
$credentials->[0]{'consumerKey'}
}
}
Truth table0%0/2
A
A= eval {
do {
my $credentials = $app->{'credentials'};
$credentials->[0]{'consumerKey'}
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $credentials = $app->{credentials}; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $credentials->[0]->{consumerKey}; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } || next; | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if (my $attrs = $app->{attributes}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my %attrs = map { $_->{name} => $_->{value} } @$attrs; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | $app->{name} = $attrs{DisplayName} if $attrs{DisplayName}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $CLIENTS->{$consumerKey} = $app->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | return $CLIENTS; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 134 | __END__ | ||||||||||||||||||||||||||||||||||||||||||