line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::OneTimeSecret; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = "0.04"; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
2597
|
use common::sense; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
1020
|
use JSON; |
|
1
|
|
|
|
|
14063
|
|
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
1270
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
43294
|
|
|
1
|
|
|
|
|
34
|
|
8
|
1
|
|
|
1
|
|
8
|
use URI::Escape; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
81
|
|
9
|
1
|
|
|
1
|
|
1079
|
use Encode qw( encode_utf8 decode_utf8 ); |
|
1
|
|
|
|
|
10615
|
|
|
1
|
|
|
|
|
869
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $_USER_AGENT = LWP::UserAgent->new(); |
12
|
|
|
|
|
|
|
my $_API_VERSION = "v1"; |
13
|
|
|
|
|
|
|
my $_BASE_URL = 'https://%s:%s@onetimesecret.com/api/'.$_API_VERSION; |
14
|
|
|
|
|
|
|
my $_SECRET_TTL = 3600; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub __url_for { |
17
|
13
|
|
|
13
|
|
46
|
my ($self, $action, $user, $password) = @_; |
18
|
13
|
|
33
|
|
|
129
|
$user ||= $self->customerId(); |
19
|
13
|
|
33
|
|
|
90
|
$password ||= $self->apiKey(); |
20
|
|
|
|
|
|
|
|
21
|
13
|
|
|
|
|
93
|
return sprintf( |
22
|
|
|
|
|
|
|
$_BASE_URL, |
23
|
|
|
|
|
|
|
uri_escape( $user ), |
24
|
|
|
|
|
|
|
uri_escape( $password ) |
25
|
|
|
|
|
|
|
) . $action; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
1
|
|
|
1
|
0
|
9
|
my $class = shift; |
30
|
1
|
|
|
|
|
3
|
my $customerId = shift; |
31
|
1
|
|
|
|
|
1
|
my $apiKey = shift; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
2
|
my %options = ( @_ ); |
34
|
1
|
|
|
|
|
4
|
my $self = bless { |
35
|
|
|
|
|
|
|
_customerId => $customerId, |
36
|
|
|
|
|
|
|
_apiKey => $apiKey, |
37
|
|
|
|
|
|
|
}, $class; |
38
|
|
|
|
|
|
|
# process other options... |
39
|
1
|
|
|
|
|
3
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _post { |
43
|
12
|
|
|
12
|
|
597
|
my ($self, $url, $data) = @_; |
44
|
12
|
|
100
|
|
|
61
|
$data ||= {}; |
45
|
12
|
|
|
|
|
54
|
foreach my $key (keys %$data) { |
46
|
13
|
100
|
|
|
|
35
|
delete $data->{$key} unless defined $data->{$key}; |
47
|
|
|
|
|
|
|
} |
48
|
12
|
|
|
|
|
72
|
my $response = $_USER_AGENT->post( $url, 'Content' => $data ); |
49
|
12
|
|
|
|
|
3868505
|
return from_json( decode_utf8( $response->decoded_content ) ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _get { |
53
|
1
|
|
|
1
|
|
57
|
my ($self, $url) = @_; |
54
|
1
|
|
|
|
|
11
|
my $response = $_USER_AGENT->get( $url ); |
55
|
1
|
|
|
|
|
71599
|
return from_json( $response->decoded_content ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub status { |
59
|
1
|
|
|
1
|
1
|
936
|
my ($self) = @_; |
60
|
1
|
|
|
|
|
9
|
return $self->_get( $self->__url_for( "/status" ) ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub shareSecret { |
64
|
3
|
|
|
3
|
1
|
1961
|
my $self = shift; |
65
|
3
|
|
|
|
|
8
|
my $secret = shift; |
66
|
3
|
|
|
|
|
8
|
my $options = { @_ }; |
67
|
|
|
|
|
|
|
|
68
|
3
|
|
33
|
|
|
17
|
return $self->_post( $self->__url_for( "/share" ), { |
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
69
|
|
|
|
|
|
|
secret => $secret, |
70
|
|
|
|
|
|
|
ttl => $options->{ttl} || $_SECRET_TTL, |
71
|
|
|
|
|
|
|
recipient => $options->{recipient} || undef, |
72
|
|
|
|
|
|
|
passphrase => $options->{passphrase} || undef, |
73
|
|
|
|
|
|
|
}); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub generateSecret { |
77
|
1
|
|
|
1
|
1
|
838
|
my $self = shift; |
78
|
1
|
|
|
|
|
3
|
my $options = { @_ }; |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
7
|
return $self->_post( $self->__url_for( "/generate" )); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub retrieveSecret { |
84
|
6
|
|
|
6
|
1
|
7092
|
my $self = shift; |
85
|
6
|
|
|
|
|
17
|
my $key = shift; |
86
|
6
|
|
|
|
|
22
|
my $options = { @_ }; |
87
|
6
|
|
|
|
|
57
|
return $self->_post( $self->__url_for( sprintf("/secret/%s", $key) ), $options ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub retrieveMetadata { |
91
|
2
|
|
|
2
|
1
|
3461
|
my ($self, $key) = @_; |
92
|
2
|
|
|
|
|
24
|
return $self->_post( $self->__url_for( sprintf("/private/%s", $key) ) ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
13
|
|
|
13
|
0
|
104
|
sub customerId { return $_[0]->{_customerId} }; |
96
|
0
|
|
|
0
|
0
|
0
|
sub setCustomerId { $_[0]->{_customerId} = shift }; |
97
|
13
|
|
|
13
|
0
|
66
|
sub apiKey { return $_[0]->{_apiKey} }; |
98
|
0
|
|
|
0
|
0
|
|
sub setApiKey { $_[0]->{_apiKey} = shift }; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
__END__ |