| 1 | package Net::Kubernetes::Resource::Secret; | ||||||||||||
| 2 | # ABSTRACT: Object representatioon of a Kubernetes Secret | ||||||||||||
| 3 | 4 | $Net::Kubernetes::Resource::Secret::VERSION = '0.19'; | |||||||||||
| 4 | 4 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 4 | ▶ | use File::Slurp qw(write_file); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 4 | ▶ | use MIME::Base64 qw(decode_base64); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 4 | extends 'Net::Kubernetes::Resource'; | |||||||||||
| 10 | |||||||||||||
| 11 | 4 | has type => ( | |||||||||||
| 12 | is => 'ro', | ||||||||||||
| 13 | isa => 'Str', | ||||||||||||
| 14 | required => 1 | ||||||||||||
| 15 | ); | ||||||||||||
| 16 | |||||||||||||
| 17 | 4 | has data => ( | |||||||||||
| 18 | is => 'ro', | ||||||||||||
| 19 | isa => 'HashRef', | ||||||||||||
| 20 | required => 1 | ||||||||||||
| 21 | ); | ||||||||||||
| 22 | |||||||||||||
| 23 | |||||||||||||
| 24 | sub render { | ||||||||||||
| 25 | 1 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
render: called CC=5 SCAR=17.2
Pod
documented
| |||||||||||||
| 26 | |||||||||||||
| 27 | 1 | my(%args); | |||||||||||
| 28 | 1 | ▶ | if (ref($_[0])) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 0 | %args = %{ $_[0] }; | |||||||||||
| 30 | } else { | ||||||||||||
| 31 | 1 | %args = @_; | |||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | 1 | ▶ | $args{force} //= 0; | ||||||||||
|
Condition50%1/2
$args{"force"} //= 0
MC/DC0%0/1
$args{"force"} //= 0
$args{"force"}
Truth table50%1/2
A
A= $args{"force"}
| |||||||||||||
| 35 | |||||||||||||
| 36 | 1 | ▶ | if (! -d $args{directory}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | 0 | Throwable::Error->throw(message => "Directory must exist: $args{directory}"); | |||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | 1 | for my $file (keys %{$self->data}) { | |||||||||||
| 41 | write_file("$args{directory}/$file", | ||||||||||||
| 42 | { | ||||||||||||
| 43 | err_mode => 'croak', | ||||||||||||
| 44 | no_clobber => !$args{force}, | ||||||||||||
| 45 | binmode => ':raw', | ||||||||||||
| 46 | }, | ||||||||||||
| 47 | 2 | decode_base64 ${$self->data}{$file} | |||||||||||
| 48 | ); | ||||||||||||
| 49 | } | ||||||||||||
| 50 | # if we didn't write them all, we better have thrown an exception. | ||||||||||||
| 51 | 1 | return scalar keys %{$self->data}; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 4 | return 42; | |||||||||||
| 55 | |||||||||||||
| 56 | __END__ | ||||||||||||
| 57 | |||||||||||||
| 58 | =pod | ||||||||||||
| 59 | |||||||||||||
| 60 | =encoding UTF-8 | ||||||||||||
| 61 | |||||||||||||
| 62 | =head1 NAME | ||||||||||||
| 63 | |||||||||||||
| 64 | Net::Kubernetes::Resource::Secret - Object representatioon of a Kubernetes Secret | ||||||||||||
| 65 | |||||||||||||
| 66 | =head1 VERSION | ||||||||||||
| 67 | |||||||||||||
| 68 | version 0.19 | ||||||||||||
| 69 | |||||||||||||
| 70 | =head1 METHODS | ||||||||||||
| 71 | |||||||||||||
| 72 | =head2 render(directory => "/path/to/write/secret/files", [ force => 0/] ) | ||||||||||||
| 73 | |||||||||||||
| 74 | Render the contents of a Kubernetes secret into the specified directory. Will | ||||||||||||
| 75 | not overwrite files unless 'force' is specified. | ||||||||||||
| 76 | |||||||||||||
| 77 | Returns the number of files written. | ||||||||||||
| 78 | |||||||||||||
| 79 | =head1 AUTHOR | ||||||||||||
| 80 | |||||||||||||
| 81 | Dave Mueller <dave@perljedi.com> | ||||||||||||
| 82 | |||||||||||||
| 83 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 84 | |||||||||||||
| 85 | This software is Copyright (c) 2015 by Dave Mueller. | ||||||||||||
| 86 | |||||||||||||
| 87 | This is free software, licensed under: | ||||||||||||
| 88 | |||||||||||||
| 89 | The MIT (X11) License | ||||||||||||
| 90 | |||||||||||||
| 91 | =head1 SEE ALSO | ||||||||||||
| 92 | |||||||||||||
| 93 | Please see those modules/websites for more information related to this module. | ||||||||||||
| 94 | |||||||||||||
| 95 | =over 4 | ||||||||||||
| 96 | |||||||||||||
| 97 | =item * | ||||||||||||
| 98 | |||||||||||||
| 99 | L<Net::Kubernetes|Net::Kubernetes> | ||||||||||||
| 100 | |||||||||||||
| 101 | =back | ||||||||||||
| 102 | |||||||||||||
| 103 | =cut | ||||||||||||