| 1 | package Mojolicious::Command::credentials; | ||||||||||||||||||||||||||
| 2 | 1 | $Mojolicious::Command::credentials::VERSION = '0.007'; | |||||||||||||||||||||||||
| 3 | 1 | ▶ | use Mojo::Base 'Mojolicious::Command', -signatures; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Env '$EDITOR'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 6 | 1 | ▶ | use File::Slurper qw/read_binary write_binary/; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 7 | 1 | ▶ | use File::Temp 'tempfile'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Getopt::Long 'GetOptionsFromArray'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 9 | 1 | ▶ | use IPC::Cmd 'can_run'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 10 | 1 | ▶ | use List::Util 'first'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Text::ParseWords 'shellwords'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 12 | 1 | ▶ | use YAML::PP 'LoadFile'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||
| 14 | 1 | has description => 'Edit the applications credentials'; | |||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||
| 16 | 0 | ▶ | has usage => sub { shift->extract_usage }; | ||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub run($self, $command, @args) { | ||||||||||||||||||||||||
|
Subroutine
run: not called CC=18 SCAR=58.3
Pod
documented
| |||||||||||||||||||||||||||
| 19 | 0 | ▶ | die $self->usage unless defined $command; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||
| 21 | 0 | my $credentials = $self->app->credentials; | |||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | if ($command eq 'edit') { | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 24 | 0 | ▶ | my $editor = $EDITOR // first { can_run($_) } qw/editor vi nano/; | ||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$Mojolicious::Command::credentials::EDITOR // &first(sub {
can_run($_);
}
, "editor", "vi", "nano")
MC/DC0%0/2
$Mojolicious::Command::credentials::EDITOR // &first(sub {
can_run($_);
}
, "editor", "vi", "nano")
$Mojolicious::Command::credentials::EDITOR
&first(sub {
can_run($_);
}
, "editor", "vi", "nano")
Truth table0%0/3
A // B
A= $Mojolicious::Command::credentials::EDITORB= &first(sub {
can_run($_);
}
, "editor", "vi", "nano")
| |||||||||||||||||||||||||||
| 25 | 0 | ▶ | die 'Could not find an editor' if not defined $editor; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 26 | 0 | ▶ | GetOptionsFromArray(\@args, 'yaml' => \my $yaml, 'editor=s' => \$editor) or die "Invalid arguments"; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 27 | 0 | ▶ | my $name = shift @args or die 'No credential name given'; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | my $suffix = $yaml ? '.yaml' : undef; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 30 | 0 | my ($fh, $filename) = tempfile(UNLINK => 1, SUFFIX => $suffix); | |||||||||||||||||||||||||
| 31 | 0 | ▶ | write_binary($filename, $credentials->get($name)) if $credentials->has($name); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | system shellwords($editor), $filename and die 'Could not save file'; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||
| 35 | 0 | my $data = read_binary($filename); | |||||||||||||||||||||||||
| 36 | 0 | write_binary($filename, scalar('\0' x length $data)); | |||||||||||||||||||||||||
| 37 | 0 | ▶ | YAML::PP->new->load_string($data) if $yaml; # YAML validity check | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 38 | 0 | $credentials->put($name, $data); | |||||||||||||||||||||||||
| 39 | } elsif ($command eq 'show') { | ||||||||||||||||||||||||||
| 40 | 0 | ▶ | my $name = shift @args or die 'No credential name given'; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 41 | 0 | print $credentials->get($name); | |||||||||||||||||||||||||
| 42 | } elsif ($command eq 'list') { | ||||||||||||||||||||||||||
| 43 | 0 | say for $credentials->list; | |||||||||||||||||||||||||
| 44 | } elsif ($command eq 'remove') { | ||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $name = shift @args or die 'No credential name given'; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 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 | 1; | |||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||
| 59 | # ABSTRACT: Manage your app's credentials | ||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||