| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Command::credentials; |
|
2
|
|
|
|
|
|
|
$Mojolicious::Command::credentials::VERSION = '0.007'; |
|
3
|
1
|
|
|
1
|
|
263201
|
use Mojo::Base 'Mojolicious::Command', -signatures; |
|
|
1
|
|
|
|
|
17067
|
|
|
|
1
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
422271
|
use Env '$EDITOR'; |
|
|
1
|
|
|
|
|
3446
|
|
|
|
1
|
|
|
|
|
18
|
|
|
6
|
1
|
|
|
1
|
|
999
|
use File::Slurper qw/read_binary write_binary/; |
|
|
1
|
|
|
|
|
4799
|
|
|
|
1
|
|
|
|
|
102
|
|
|
7
|
1
|
|
|
1
|
|
10
|
use File::Temp 'tempfile'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
90
|
|
|
8
|
1
|
|
|
1
|
|
12
|
use Getopt::Long 'GetOptionsFromArray'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
10
|
|
|
9
|
1
|
|
|
1
|
|
1147
|
use IPC::Cmd 'can_run'; |
|
|
1
|
|
|
|
|
62530
|
|
|
|
1
|
|
|
|
|
108
|
|
|
10
|
1
|
|
|
1
|
|
14
|
use List::Util 'first'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
83
|
|
|
11
|
1
|
|
|
1
|
|
11
|
use Text::ParseWords 'shellwords'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
59
|
|
|
12
|
1
|
|
|
1
|
|
1064
|
use YAML::PP 'LoadFile'; |
|
|
1
|
|
|
|
|
157027
|
|
|
|
1
|
|
|
|
|
1101
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has description => 'Edit the applications credentials'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has usage => sub { shift->extract_usage }; |
|
17
|
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
1
|
|
sub run($self, $command, @args) { |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
die $self->usage unless defined $command; |
|
20
|
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my $credentials = $self->app->credentials; |
|
22
|
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
if ($command eq 'edit') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
24
|
0
|
|
0
|
0
|
|
|
my $editor = $EDITOR // first { can_run($_) } qw/editor vi nano/; |
|
|
0
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
die 'Could not find an editor' if not defined $editor; |
|
26
|
0
|
0
|
|
|
|
|
GetOptionsFromArray(\@args, 'yaml' => \my $yaml, 'editor=s' => \$editor) or die "Invalid arguments"; |
|
27
|
0
|
0
|
|
|
|
|
my $name = shift @args or die 'No credential name given'; |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
my $suffix = $yaml ? '.yaml' : undef; |
|
30
|
0
|
|
|
|
|
|
my ($fh, $filename) = tempfile(UNLINK => 1, SUFFIX => $suffix); |
|
31
|
0
|
0
|
|
|
|
|
write_binary($filename, $credentials->get($name)) if $credentials->has($name); |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
system shellwords($editor), $filename and die 'Could not save file'; |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $data = read_binary($filename); |
|
36
|
0
|
|
|
|
|
|
write_binary($filename, scalar('\0' x length $data)); |
|
37
|
0
|
0
|
|
|
|
|
YAML::PP->new->load_string($data) if $yaml; # YAML validity check |
|
38
|
0
|
|
|
|
|
|
$credentials->put($name, $data); |
|
39
|
|
|
|
|
|
|
} elsif ($command eq 'show') { |
|
40
|
0
|
0
|
|
|
|
|
my $name = shift @args or die 'No credential name given'; |
|
41
|
0
|
|
|
|
|
|
print $credentials->get($name); |
|
42
|
|
|
|
|
|
|
} elsif ($command eq 'list') { |
|
43
|
0
|
|
|
|
|
|
say for $credentials->list; |
|
44
|
|
|
|
|
|
|
} elsif ($command eq 'remove') { |
|
45
|
0
|
0
|
|
|
|
|
my $name = shift @args or die 'No credential name given'; |
|
46
|
0
|
|
|
|
|
|
$credentials->remove($name); |
|
47
|
|
|
|
|
|
|
} elsif ($command eq 'recode') { |
|
48
|
0
|
|
|
|
|
|
print 'Please input new key in hex form: '; |
|
49
|
0
|
|
|
|
|
|
chomp(my $encoded_key = <>); |
|
50
|
0
|
|
|
|
|
|
my $key = pack "H*", $encoded_key; |
|
51
|
0
|
|
|
|
|
|
$credentials->recode($key); |
|
52
|
|
|
|
|
|
|
} else { |
|
53
|
0
|
|
|
|
|
|
die "Unknown subcommand $command" |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# ABSTRACT: Manage your app's credentials |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |