ackage Net::Etcd;
# ABSTRACT: Provide access to the etcd v3 API.
use strict;
use warnings;
use JSON;
use MIME::Base64;
use Types::Standard qw(Str Int Bool HashRef);
use Net::Etcd::Auth;
use Net::E
e utf8;
package Net::Etcd::Role::Actions;
use strict;
use warnings;
use Moo::Role;
use AE;
use JSON;
use MIME::Base64;
use Types::Standard qw(InstanceOf);
use AnyEvent::HTTP;
use Carp;
use Data::Du
isa => InstanceOf ['Net::Etcd'],
);
=head2 json_args
arguments that will be sent to the api
=cut
has json_args => ( is => 'lazy', );
sub _build_json_args {
my ($self) = @_;
my $args;
) {
unless ( $key =~ /(?:etcd|cb|cv|hold|json_args|endpoint)$/ ) {
$args->{$key} = $self->{$key};
}
}
return to_json($args);
}
=head2 cb
AnyEvent callback must be
use Moo;
use Types::Standard qw(Str Int Bool HashRef ArrayRef);
use Data::Dumper;
use Carp;
use JSON;
with 'Net::Etcd::Role::Actions';
use namespace::clean;
=head1 NAME
Net::Etcd::Lease
=cut
o
s => 'ro',
isa => Bool,
coerce => sub { no strict 'refs'; return $_[0] ? JSON::true : JSON::false }
);
=head1 PUBLIC METHODS
=head2 grant
LeaseGrant creates a lease which expires
ng leases.
$etcd->lease()->leases
=cut
sub leases {
my $self = shift;
$self->{endpoint} = '/kv/lease/leases';
$self->{json_args} = '{}';
$self->request;
return $self;
}
1;
{
my ( $self, $options ) = @_;
my $cb = pop if ref $_[-1] eq 'CODE';
$self->{endpoint} = '/cluster/member/list';
$self->{json_args} = '{}';
$self->request;
return $self;
}
1;
y $cb = pop if ref $_[-1] eq 'CODE';
$self->{endpoint} = '/maintenance/snapshot';
$self->{json_args} = '{}';
$self->request;
return $self;
}
=head2 status
Status gets the status of t
my $cb = pop if ref $_[-1] eq 'CODE';
$self->{endpoint} = '/maintenance/status';
$self->{json_args} = '{}';
$self->request;
return $self;
}
=head2 defragment
Defragment defragments
$cb = pop if ref $_[-1] eq 'CODE';
$self->{endpoint} = '/maintenance/defragment';
$self->{json_args} = '{}';
$self->request;
return $self;
}
=head2 version
Returns the member version
o;
use Types::Standard qw(Str Int Bool HashRef ArrayRef);
use MIME::Base64;
use Data::Dumper;
use JSON;
with 'Net::Etcd::Role::Actions';
use namespace::clean;
=head1 NAME
Net::Etcd::KV::Compare
=
use utf8;
package Net::Etcd::Auth;
use strict;
use warnings;
=encoding utf8
=cut
use JSON;
use Carp;
use Types::Standard qw(Str);
use Net::Etcd::Auth::Role;
use Moo;
with 'Net::Etcd::Role::Action
nless ($self->password && $self->name);
$self->request;
my $auth;
eval { $auth = from_json($self->{response}{content}) };
if ($@) {
$self->{response}{content} = 'error: ' . $@;
sub enable {
my ( $self, $options ) = @_;
$self->{endpoint} = '/auth/enable';
$self->{json_args} = '{}';
$self->request;
# init token
$self->etcd->auth()->authenticate;
re
o;
use Types::Standard qw(Str Int Bool HashRef ArrayRef);
use MIME::Base64;
use Data::Dumper;
use JSON;
with 'Net::Etcd::Role::Actions';
use namespace::clean;
=head1 NAME
Net::Etcd::Watch
=cut
o
is => 'ro',
isa => Bool,
coerce => sub { no strict 'refs'; return $_[0] ? JSON::true : JSON::false }
);
=head2 filters
filter out put event. filter out delete event. filters filter
is => 'ro',
isa => Bool,
coerce => sub { no strict 'refs'; return $_[0] ? JSON::true : JSON::false }
);
=head2 watch_id
watch_id is the watcher id to cancel so that no more events
warnings;
use Moo;
use Types::Standard qw(Str Int Bool HashRef ArrayRef);
use MIME::Base64;
use JSON;
with 'Net::Etcd::Role::Actions';
use namespace::clean;
=head1 NAME
Net::Etcd::Range
=cut
o
is => 'ro',
isa => Bool,
coerce => sub { no strict 'refs'; return $_[0] ? JSON::true : JSON::false }
);
=head2 limit
limit is a limit on the number of keys returned for the reques
is => 'ro',
isa => Bool,
coerce => sub { no strict 'refs'; return $_[0] ? JSON::true : JSON::false }
);
=head2 keys_only
keys_only when set returns only the keys and not the values
use Moo;
use Types::Standard qw(Str Int Bool HashRef ArrayRef);
use MIME::Base64;
use Carp;
use JSON;
with 'Net::Etcd::Role::Actions';
use namespace::clean;
=head1 NAME
Net::Etcd::Auth::Role
=c
return $self;
}
=head2 list
List roles
=cut
sub list {
my ($self) = @_;
$self->{endpoint} = '/auth/role/list';
$self->{json_args} = '{}';
$self->request;
return $self;
}
1;
warnings;
use Moo;
use Types::Standard qw(Str Int Bool HashRef ArrayRef);
use MIME::Base64;
use JSON;
with 'Net::Etcd::Role::Actions';
use namespace::clean;
=head1 NAME
Net::Etcd::Put
=cut
our
value pair will be returned in the put response.
=cut
has prev_kv => (
is => 'ro',
isa => Bool,
coerce => sub { no strict 'refs'; return $_[0] ? JSON::true : JSON::false }
);
1;
use Moo;
use Types::Standard qw(Str Int Bool HashRef ArrayRef);
use MIME::Base64;
use Carp;
use JSON;
use Data::Dumper;
with 'Net::Etcd::Role::Actions';
use namespace::clean;
=head1 NAME
Net::Et
sub grant {;
my ($self) = @_;
$self->{endpoint} = '/auth/role/grant';
$self->{json_args} = to_json( {name => $self->name, perm => $self->perm } );
$self->request;
return $self;
}
s::Standard qw(InstanceOf Str Int Bool HashRef ArrayRef);
use MIME::Base64;
use Data::Dumper;
use JSON;
with 'Net::Etcd::Role::Actions';
use namespace::clean;
=head1 NAME
Net::Etcd::KV::Txn
=cut
failure;
$txn .= '"failure":[ ' . join(',', @$failure) . ']' if defined $failure;
$self->{json_args} = '{' . $txn . '}';
# print STDERR Dumper($self);
$self->request;
return $self;
s::Standard qw(InstanceOf Str Int Bool HashRef ArrayRef);
use MIME::Base64;
use Data::Dumper;
use JSON;
with 'Net::Etcd::Role::Actions';
use namespace::clean;
=head1 NAME
Net::Etcd::KV::Op
=cut
=head2 create
create op
=cut
#TODO this dirty hack should be a perl data object and then make json.
sub create {
my $self = shift;
my @op;
my $put = $self->request_put;
my $range
Put":' . $put->json_args . '}' if defined $put;
push @op, '{"requestRange":' . $range->json_args . '}' if defined $range;
push @op, '{"requestDeleteRange":' . $delete_range->json_args . '}' if
warnings;
use Moo;
use Types::Standard qw(Str Int Bool HashRef ArrayRef);
use MIME::Base64;
use JSON;
with 'Net::Etcd::Role::Actions';
use namespace::clean;
=head1 NAME
Net::Etcd::DeleteRange
=
is => 'ro',
isa => Bool,
coerce => sub { no strict 'refs'; return $_[0] ? JSON::true : JSON::false }
);
=head2 range_end
range_end is the upper bound on the requested range [key, r
$options ) = @_;
my $cb = pop if ref $_[-1] eq 'CODE';
my $cmp = Net::Etcd::KV::Compare->new(
%$self,
( $options ? %$options : () ),
);
return $cmp->json_args;
}
1;