| 1 | package WWW::Hetzner::CLI::Cmd::Record; | ||||||||||||
| 2 | # ABSTRACT: DNS Record commands | ||||||||||||
| 3 | |||||||||||||
| 4 | 2 | our $VERSION = '0.102'; | |||||||||||
| 5 | |||||||||||||
| 6 | 2 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 2 | ▶ | use MooX::Cmd; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 2 | ▶ | use MooX::Options usage_string => 'USAGE: hcloud.pl record [list|describe|create|delete] --zone <zone-id> [options]'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 2 | ▶ | use JSON::MaybeXS qw(encode_json); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | |||||||||||||
| 12 | |||||||||||||
| 13 | 2 | ▶ | sub execute { | ||||||||||
|
Subroutine
execute: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 14 | 2 | my ($self, $args, $chain) = @_; | |||||||||||
| 15 | |||||||||||||
| 16 | # Default to list | ||||||||||||
| 17 | 2 | $self->_list($chain); | |||||||||||
| 18 | } | ||||||||||||
| 19 | |||||||||||||
| 20 | 2 | option zone => ( | |||||||||||
| 21 | is => 'ro', | ||||||||||||
| 22 | format => 's', | ||||||||||||
| 23 | short => 'z', | ||||||||||||
| 24 | doc => 'Zone ID (required)', | ||||||||||||
| 25 | ); | ||||||||||||
| 26 | |||||||||||||
| 27 | 2 | option type => ( | |||||||||||
| 28 | is => 'ro', | ||||||||||||
| 29 | format => 's', | ||||||||||||
| 30 | short => 't', | ||||||||||||
| 31 | doc => 'Filter by record type (A, AAAA, CNAME, MX, TXT, etc.)', | ||||||||||||
| 32 | ); | ||||||||||||
| 33 | |||||||||||||
| 34 | 2 | ▶ | sub _list { | ||||||||||
|
Subroutine
_list: called CC=8 SCAR=21.5
| |||||||||||||
| 35 | 2 | my ($self, $chain) = @_; | |||||||||||
| 36 | |||||||||||||
| 37 | 2 | ▶ | die "Usage: record --zone <zone-id>\n" unless $self->zone; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | |||||||||||||
| 39 | 2 | my $main = $chain->[0]; | |||||||||||
| 40 | 2 | my $cloud = $main->cloud; | |||||||||||
| 41 | |||||||||||||
| 42 | 2 | my %params; | |||||||||||
| 43 | 2 | ▶ | $params{type} = $self->type if $self->type; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | |||||||||||||
| 45 | 2 | my $rrsets = $cloud->zones->rrsets($self->zone); | |||||||||||
| 46 | 2 | my $records = $rrsets->list_all(%params); | |||||||||||
| 47 | |||||||||||||
| 48 | 2 | ▶ | if ($main->output eq 'json') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | 1 | print encode_json([ map { $_->data } @$records ]), "\n"; | |||||||||||
| 50 | 1 | return; | |||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | 1 | ▶ | if (!@$records) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 54 | 0 | print "No records found.\n"; | |||||||||||
| 55 | 0 | return; | |||||||||||
| 56 | } | ||||||||||||
| 57 | |||||||||||||
| 58 | 1 | printf "%-25s %-8s %-8s %s\n", | |||||||||||
| 59 | 'NAME', 'TYPE', 'TTL', 'VALUES'; | ||||||||||||
| 60 | 1 | print "-" x 80, "\n"; | |||||||||||
| 61 | |||||||||||||
| 62 | 1 | for my $r (@$records) { | |||||||||||
| 63 | 5 | ▶ | my $values = join(', ', map { $_->{value} } @{$r->records // []}); | ||||||||||
|
Condition50%1/2
$r->records // []
MC/DC0%0/1
$r->records // []
$r->records
Truth table50%1/2
A
A= $r->records
| |||||||||||||
| 64 | 5 | ▶ | printf "%-25s %-8s %-8s %s\n", | ||||||||||
|
Condition50%1/2
$r->ttl // "-"
MC/DC0%0/1
$r->ttl // "-"
$r->ttl
Truth table50%1/2
A
A= $r->ttl
| |||||||||||||
| 65 | $r->name, | ||||||||||||
| 66 | $r->type, | ||||||||||||
| 67 | $r->ttl // '-', | ||||||||||||
| 68 | $values; | ||||||||||||
| 69 | } | ||||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | 2 | 1; | |||||||||||
| 73 | |||||||||||||
| 74 | __END__ | ||||||||||||