CloudTrail.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 56 CC 3 SCAR 15.0
CC
3
Cov
0%
lookup_events
12.0
format_attributes
2.0
BEGIN
2.0
CRAP 4.5
1 #!/usr/bin/env perl
2  
3 package App::CloudTrail;
4  
5 use strict;
6 use warnings;
7  
8 use Carp;
9 use Data::Dumper;
10 use English qw(-no_match_vars);
11 use JSON;
12  
13 use Role::Tiny::With;
14 with 'App::AWS';
15  
16 use parent qw(App::Command);
17  
18 __PACKAGE__->follow_best_practice;
19 __PACKAGE__->mk_accessors(qw(profile region));
20  
21 ########################################################################
22 sub lookup_events {
23 ########################################################################
24 my ( $self, %args ) = @_;
25  
26 my ( $attributes, $start_time, $end_time ) = @args{qw(attributes start_time end_time)};
27  
28 my $result = $self->command(
29 'lookup-events' => [
30 '--lookup-attributes' => $self->format_attributes($attributes),
31 $start_time ? ( '--start-time' => $start_time ) : (),
32 $end_time ? ( '--end-time' => $end_time ) : (),
33 ]
34 );
35  
36 $self->check_result( message => 'ERROR: unable to lookup events' );
37  
38 foreach ( @{ $result->{Events} } ) {
39 $_->{CloudTrailEvent} = from_json( $_->{CloudTrailEvent} );
40 }
41  
42 return $result->{Events};
43 }
44  
45 ########################################################################
46 sub format_attributes {
47 ########################################################################
48 my ( $self, $events ) = @_;
49  
50 return map { sprintf 'AttributeKey=%s,AttributeValue=%s', $_, $events->{$_} } keys %{$events};
51 }
52  
53 1;