TT#68300 Fix coding style, indentation and spacing

Change-Id: I380ca0cffc1b163ff7af914dcd069b79891cf634
changes/50/34750/2
Guillem Jover 6 years ago
parent 82af7f6424
commit f69d3e8bc2

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use NGCP::API::Client; use NGCP::API::Client;
@ -20,19 +22,24 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 1, -verbose => 1,
-message => $missing ? "Missing parameters: $missing" : '', -message => $missing ? "Missing parameters: $missing" : '',
); );
return; return;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -25,20 +27,25 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99, -verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '', -message => $missing ? "Missing parameters: $missing" : '',
); );
return; return;
} }
@ -48,8 +55,9 @@ sub main {
my $client = NGCP::API::Client->new(verbose => $opts->{verbose}); my $client = NGCP::API::Client->new(verbose => $opts->{verbose});
my $uri = '/api/customers/'; my $uri = '/api/customers/';
my %data = map { $_ => $opts->{$_} } my %data = map {
qw(billing_profile_id contact_id type status); $_ => $opts->{$_}
} qw(billing_profile_id contact_id type status);
my $res = $client->request('POST', $uri, \%data); my $res = $client->request('POST', $uri, \%data);
print $res->result . "\n"; print $res->result . "\n";

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -27,6 +29,7 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $arg (@ARGV) { foreach my $arg (@ARGV) {
if ($arg =~ /^[^-]/) { if ($arg =~ /^[^-]/) {
$opts->{domain} = $arg; $opts->{domain} = $arg;
@ -37,16 +40,20 @@ sub check_params {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99, -verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '', -message => $missing ? "Missing parameters: $missing" : '',
); );
return; return;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -30,20 +32,25 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99, -verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '', -message => $missing ? "Missing parameters: $missing" : '',
); );
return; return;
} }
@ -59,8 +66,9 @@ sub main {
} }
my $uri = '/api/subscribers/'; my $uri = '/api/subscribers/';
my %data = map { $_ => $opts->{$_} } my %data = map {
qw(customer_id username password webpassword); $_ => $opts->{$_}
} qw(customer_id username password webpassword);
$data{primary_number} = { map { $_ => $opts->{$_} } qw(cc ac sn) }; $data{primary_number} = { map { $_ => $opts->{$_} } qw(cc ac sn) };
$data{administrative} = $opts->{admin}; $data{administrative} = $opts->{admin};
my $tmp = $dom->as_hash->{_embedded}->{'ngcp:domains'}; my $tmp = $dom->as_hash->{_embedded}->{'ngcp:domains'};

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -31,25 +33,33 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 1, -verbose => 1,
-message => $missing ? "Missing parameters: $missing" : '', -message => $missing ? "Missing parameters: $missing" : '',
); );
return; return;
} }
sub load_config { sub load_config {
$config = XML::Simple->new()->XMLin($config_file, ForceArray => [ 'credit_warnings' ]) $config = XML::Simple->new()->XMLin(
or die "Cannot load config: $config_file: $ERRNO\n"; $config_file,
ForceArray => [ 'credit_warnings' ],
) or die "Cannot load config: $config_file: $ERRNO\n";
return; return;
} }
@ -58,9 +68,11 @@ sub send_email {
my $template = get_email_template() || return; my $template = get_email_template() || return;
my $vars = { domain => $cwarning->{domain}, my $vars = {
domain => $cwarning->{domain},
threshold => $cwarning->{threshold}, threshold => $cwarning->{threshold},
adminmail => $config->{adminmail} }; adminmail => $config->{adminmail},
};
foreach my $data (@{$contracts}) { foreach my $data (@{$contracts}) {
if (exists $data->{threshold}) { if (exists $data->{threshold}) {
@ -108,6 +120,7 @@ sub get_data {
verbose => $opts->{verbose}, verbose => $opts->{verbose},
page_rows => $page_size, page_rows => $page_size,
); );
my @result = (); my @result = ();
while (my $res = $client->next_page($uri)) { while (my $res = $client->next_page($uri)) {
die "$res->result\n" unless $res->is_success; die "$res->result\n" unless $res->is_success;
@ -115,11 +128,11 @@ sub get_data {
my $data = $res_hash->{_embedded}{'ngcp:' . $link}; my $data = $res_hash->{_embedded}{'ngcp:' . $link};
if ('ARRAY' eq ref $data) { if ('ARRAY' eq ref $data) {
unless ($process_code->($data)) { unless ($process_code->($data)) {
push(@result,@$data); push @result, @{$data};
} }
} elsif ($data) { } elsif ($data) {
unless ($process_code->([ $data ])) { unless ($process_code->([ $data ])) {
push(@result,$data); push @result, $data;
} }
} }
} }
@ -138,6 +151,7 @@ sub get_email_template {
sub main { sub main {
check_params(); check_params();
load_config(); load_config();
my $cwarnings = ref $config->{credit_warnings} eq 'ARRAY' my $cwarnings = ref $config->{credit_warnings} eq 'ARRAY'
? $config->{credit_warnings} ? $config->{credit_warnings}
: [ $config->{credit_warnings} ]; : [ $config->{credit_warnings} ];
@ -158,7 +172,9 @@ sub main {
my $ratio = $balance->{ratio} // 1.0; my $ratio = $balance->{ratio} // 1.0;
my $threshold = $cwarning->{threshold} * $ratio; my $threshold = $cwarning->{threshold} * $ratio;
next if $balance->{cash_balance} >= $threshold; next if $balance->{cash_balance} >= $threshold;
my $data = { map { $_ => $balance->{$_} } qw(id cash_balance) }; my $data = {
map { $_ => $balance->{$_} } qw(id cash_balance)
};
$data->{threshold} = $threshold if $ratio < 1.0; $data->{threshold} = $threshold if $ratio < 1.0;
push @contracts, $data; push @contracts, $data;
} }
@ -172,6 +188,7 @@ sub main {
print $EVAL_ERROR if $EVAL_ERROR; print $EVAL_ERROR if $EVAL_ERROR;
} }
} }
return 0; return 0;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -26,20 +28,25 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99, -verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '', -message => $missing ? "Missing parameters: $missing" : '',
); );
return; return;
} }
@ -55,7 +62,9 @@ sub main {
} }
my $uri = '/api/domains/'; my $uri = '/api/domains/';
my %data = map { '_'.$_.'_reload' => $opts->{$_} } qw(skip_xmpp skip_sip); my %data = map {
'_' . $_ . '_reload' => $opts->{$_}
} qw(skip_xmpp skip_sip);
my $dom_id; my $dom_id;
my $tmp = $dom->as_hash->{_embedded}->{'ngcp:domains'}; my $tmp = $dom->as_hash->{_embedded}->{'ngcp:domains'};
if (ref $tmp eq 'ARRAY') { if (ref $tmp eq 'ARRAY') {

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -48,19 +50,24 @@ sub DESTROY {
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 1, -verbose => 1,
-message => $missing ? "Missing parameters: $missing" : '', -message => $missing ? "Missing parameters: $missing" : '',
); );
return; return;
} }
@ -85,9 +92,9 @@ sub get_data {
my $res_hash = $res->as_hash; my $res_hash = $res->as_hash;
my $data = $res_hash->{_embedded}{'ngcp:' . $link}; my $data = $res_hash->{_embedded}{'ngcp:' . $link};
if ('ARRAY' eq ref $data) { if ('ARRAY' eq ref $data) {
push(@result,@$data); push @result, @{$data};
} elsif ($data) { } elsif ($data) {
push(@result,$data); push @result, $data;
} }
if (defined $code and 'CODE' eq ref $code) { if (defined $code and 'CODE' eq ref $code) {
$code->(\@result); $code->(\@result);
@ -99,6 +106,7 @@ sub get_data {
sub get_email_template { sub get_email_template {
my $event = shift; my $event = shift;
my $lock_type = $event->{interval_lock} ? 'lock' : 'warning'; my $lock_type = $event->{interval_lock} ? 'lock' : 'warning';
my $reseller_id = $event->{reseller_id}; my $reseller_id = $event->{reseller_id};
my @templates_data = (); my @templates_data = ();
@ -130,7 +138,8 @@ sub send_email {
my $template = get_email_template($event); my $template = get_email_template($event);
my $vars = { adminmail => $config->{adminmail}, my $vars = {
adminmail => $config->{adminmail},
customer_id => $event->{contract_id}, customer_id => $event->{contract_id},
interval => $event->{interval}, interval => $event->{interval},
interval_cost => sprintf('%.2f', $event->{interval_cost} / 100), interval_cost => sprintf('%.2f', $event->{interval_cost} / 100),
@ -143,7 +152,8 @@ sub send_email {
$vars->{subscribers} .= sprintf "%s\@%s %s\n", $vars->{subscribers} .= sprintf "%s\@%s %s\n",
@{$subscriber}{qw(username domain)}, @{$subscriber}{qw(username domain)},
$subscriber->{external_id} $subscriber->{external_id}
? '('.$subscriber->{external_id}.')' : ''; ? '(' . $subscriber->{external_id} . ')'
: '';
} }
my $tt = Template->new(); my $tt = Template->new();
@ -184,19 +194,25 @@ sub update_notify_status {
my $now = strftime('%Y-%m-%d %H:%M:%S', localtime); my $now = strftime('%Y-%m-%d %H:%M:%S', localtime);
my $uri = '/api/customerfraudevents/' . $event->{id}; my $uri = '/api/customerfraudevents/' . $event->{id};
my $data = [ { op => 'replace', my $data = [
{
op => 'replace',
path => '/notify_status', path => '/notify_status',
value => 'notified' }, value => 'notified',
{ op => 'replace', },
{
op => 'replace',
path => '/notified_at', path => '/notified_at',
value => $now } ]; value => $now,
},
];
my $res = $client->request('PATCH', $uri, $data); my $res = $client->request('PATCH', $uri, $data);
return; return;
} }
sub main { sub main {
if (my $num = $pf->running) { if (my $num = $pf->running) {
print "$PROGRAM_BASE is already running.\n"; print "$PROGRAM_BASE is already running.\n";
$retcode = 1; $retcode = 1;
@ -207,8 +223,11 @@ sub main {
check_params(); check_params();
load_config(); load_config();
get_data( get_data(
sprintf('/api/customerfraudevents/?no_count=true&notify_status=%s','new'),'customerfraudevents', sub { sprintf('/api/customerfraudevents/?no_count=true&notify_status=%s', 'new'),
'customerfraudevents',
sub {
my $events = shift; my $events = shift;
foreach my $event (@{$events}) { foreach my $event (@{$events}) {
if ($event->{interval_notify}) { if ($event->{interval_notify}) {
@ -222,7 +241,8 @@ sub main {
print $EVAL_ERROR if $EVAL_ERROR; print $EVAL_ERROR if $EVAL_ERROR;
} }
} }
}); }
);
return; return;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -21,20 +23,25 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99, -verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '', -message => $missing ? "Missing parameters: $missing" : '',
); );
return; return;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -21,20 +23,25 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99, -verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '', -message => $missing ? "Missing parameters: $missing" : '',
); );
return; return;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -21,20 +23,25 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99, -verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '', -message => $missing ? "Missing parameters: $missing" : '',
); );
return; return;
} }
@ -44,9 +51,13 @@ sub main {
my $client = NGCP::API::Client->new(verbose => $opts->{verbose}); my $client = NGCP::API::Client->new(verbose => $opts->{verbose});
my $uri = '/api/customers/' . $opts->{customer_id}; my $uri = '/api/customers/' . $opts->{customer_id};
my $data = [ { op => 'replace', my $data = [
{
op => 'replace',
path => '/status', path => '/status',
value => 'terminated' } ]; value => 'terminated',
},
];
my $res = $client->request('PATCH', $uri, $data); my $res = $client->request('PATCH', $uri, $data);
print $res->result . "\n"; print $res->result . "\n";

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -22,20 +24,25 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99, -verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '', -message => $missing ? "Missing parameters: $missing" : '',
); );
return; return;
} }
@ -51,6 +58,7 @@ sub main {
my $sub_id; my $sub_id;
if ($sub->as_hash->{total_count} == 1) { if ($sub->as_hash->{total_count} == 1) {
my $tmp = $sub->as_hash->{_embedded}->{'ngcp:subscribers'}; my $tmp = $sub->as_hash->{_embedded}->{'ngcp:subscribers'};
if (ref $tmp eq 'ARRAY') { if (ref $tmp eq 'ARRAY') {
$sub_id = @{$tmp}[0]->{id}; $sub_id = @{$tmp}[0]->{id};
} else { } else {
@ -61,9 +69,13 @@ sub main {
die "Subscriber $opts->{username}\@$opts->{domain} not found\n"; die "Subscriber $opts->{username}\@$opts->{domain} not found\n";
} }
$uri = '/api/subscribers/' . $sub_id; $uri = '/api/subscribers/' . $sub_id;
my $data = [ { op => 'replace', my $data = [
{
op => 'replace',
path => '/status', path => '/status',
value => 'terminated' } ]; value => 'terminated',
},
];
my $res = $client->request('PATCH', $uri, $data); my $res = $client->request('PATCH', $uri, $data);
print $res->result . "\n"; print $res->result . "\n";

Loading…
Cancel
Save