V1/BackupForGKEClient.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
« V1.pm ↑ Summary
1 package Google::Cloud::Gkebackup::V1::BackupForGKEClient;
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::Gkebackup::V1::RestorePlanBinding;
14 use Google::Cloud::Gkebackup::V1::Common;
15 use Google::Cloud::Gkebackup::V1::RestoreChannel;
16 use Google::Cloud::Gkebackup::V1::BackupChannel;
17 use Google::Cloud::Gkebackup::V1::BackupPlan;
18 use Google::Cloud::Gkebackup::V1::BackupPlanBinding;
19 use Google::Cloud::Gkebackup::V1::Backup;
20 use Google::Cloud::Gkebackup::V1::Volume;
21 use Google::Cloud::Gkebackup::V1::Restore;
22 use Google::Cloud::Gkebackup::V1::RestorePlan;
23 use Google::Cloud::Gkebackup::V1::Gkebackup;
24  
25 our $VERSION = '0.06';
26  
27 has credentials => ( is => 'ro', required => 0 );
28 has transport => ( is => 'rw' );
29  
30 sub BUILD {
31 my ($self) = @_;
32  
33 my $auth = $self->credentials;
34 if (!defined $auth) {
35 $auth = Google::Auth->default();
36 } elsif (!eval { $auth->can('get_token') }) {
37 croak 'Invalid credentials object: must implement get_token()';
38 }
39 my $token = $auth->get_token();
40  
41 my $target = 'gkebackup.googleapis.com:443';
42 my $t = $self->transport || 'grpc';
43  
44 if (ref($t) && eval { $t->can('call') }) {
45 # Already a transport object
46 } elsif (lc($t) eq 'rest') {
47 my $client = Google::Cloud::REST::Client->new(
48 target => $target,
49 auth_token => $token,
50 );
51 $self->transport($client);
52 } else {
53 my $client = Google::gRPC::Client->new(
54 target => $target,
55 auth_token => $token,
56 );
57 $self->transport($client);
58 }
59 }
60  
61 sub create_backup_plan {
62 my ($self, %params) = @_;
63  
64 my $request_class = 'Google::Cloud::Gkebackup::V1::Gkebackup::CreateBackupPlanRequest';
65 my $request = eval { $request_class->new(\%params) };
66 my $new_err = $@;
67 if (!$request) {
68 $request = eval { $request_class->new(%params) };
69 $new_err ||= $@;
70 }
71 if (!$request) {
72 croak 'Failed to construct ' . $request_class . ': ' . ($new_err || 'unknown error');
73 }
74  
75 my $response_class = 'Google::Longrunning::Operations::Operation';
76 if (eval { $self->transport->isa('Google::Cloud::REST::Client') }) {
77 return $self->transport->call({
78 http_method => 'POST',
79 path => '/google.cloud.gkebackup.v1.BackupForGKE/CreateBackupPlan',
80 request => $request,
81 response_class => $response_class,
82 });
83 }
84  
85 my $response = $self->transport->call({
86 service => 'google.cloud.gkebackup.v1.BackupForGKE',
87 method => 'CreateBackupPlan',
88 request => $request,
89 response_class => $response_class,
90 });
91  
92 return $response;
93 }
94 1; # End of Google::Cloud::Gkebackup::V1::BackupForGKEClient
95  
96 __END__
« V1.pm ↑ Summary