Composer/V1/EnvironmentsClient.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Orchestration/Airflow/Service/V1/Operations/Types.pm ↑ Summary Composer/V1/ImageVersionsClient.pm »
1 package Google::Cloud::Composer::V1::EnvironmentsClient;
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 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 0 ▶use Google::gRPC::Client;
Subroutine BEGIN: called CC=1 SCAR=2.6
7 use Google::Cloud::REST::Client;
8 use Google::Auth;
9 use Carp qw(croak);
10  
11 use Protobuf;
12 use Google::Api::Common;
13 use Google::Cloud::Orchestration::Airflow::Service::V1::Environments;
14 use Google::Cloud::Orchestration::Airflow::Service::V1::ImageVersions;
15 use Google::Cloud::Orchestration::Airflow::Service::V1::Operations;
16  
17 our $VERSION = '0.03';
18  
19 has credentials => ( is => 'ro', required => 0 );
20 has transport => ( is => 'rw' );
21  
22 sub BUILD {
23 my ($self) = @_;
24  
25 # Resolve credentials: use passed credentials object if it implements get_token, or default to ADC
26 my $auth = $self->credentials;
27 if (!$auth || !eval { $auth->can('get_token') }) {
28 $auth = Google::Auth->default();
29 }
30 my $token = $auth->get_token();
31  
32 my $target = 'localhost:50051';
33 my $t = $self->transport || 'grpc';
34  
35 if (ref($t) && eval { $t->can('call') }) {
36 # Already a transport object
37 } elsif (lc($t) eq 'rest') {
38 my $client = Google::Cloud::REST::Client->new(
39 target => $target,
40 auth_token => $token,
41 );
42 $self->transport($client);
43 } else {
44 # Default high-performance HTTP/2 gRPC client
45 my $client = Google::gRPC::Client->new(
46 target => $target,
47 auth_token => $token,
48 );
49 $self->transport($client);
50 }
51 }
52  
53 sub create_environment {
54 my ($self, %params) = @_;
55  
56 my $request_class = 'Google::Cloud::Orchestration::Airflow::Service::V1::Environments::CreateEnvironmentRequest';
57 my $request = eval { $request_class->new(\%params) } || eval { $request_class->new(%params) } || ($request_class->can('encode') ? $request_class->encode(\%params) : \%params);
58  
59 my $response_class = 'Google::Longrunning::Operations::Operation';
60 my $response = $self->transport->call({
61 service => 'google.cloud.orchestration.airflow.service.v1.Environments',
62 method => 'CreateEnvironment',
63 request => $request,
64 response_class => $response_class,
65 });
66  
67 return $response;
68 }
69 1; # End of Google::Cloud::Composer::V1::EnvironmentsClient
70  
71 __END__
« Orchestration/Airflow/Service/V1/Operations/Types.pm ↑ Summary Composer/V1/ImageVersionsClient.pm »