Etcd3

 view release on metacpan or  search on metacpan

lib/Etcd3/Auth.pm  view on Meta::CPAN

    $etcd->user_add( { name => 'samba', password =>'P@$$' });

    # add role
    $etcd->role( { name => 'myrole' })->add;

    # grant role
    $etcd->user_role( { user => 'samba', role => 'myrole' })->grant;

=cut

=head2 endpoint

=cut

has endpoint => (
    is       => 'ro',
    isa      => Str,
);

=head2 password

=cut

has name => (
    is       => 'ro',

lib/Etcd3/Auth.pm  view on Meta::CPAN

=head2 authenticate

Enable authentication, this requires name and password.

    $etcd->auth({ name => $user, password => $pass })->authenticate;

=cut

sub authenticate {
    my ( $self, $options ) = @_;
    $self->{endpoint} = '/auth/authenticate';
    confess 'name and password required for ' . __PACKAGE__ . '->authenticate'
      unless ($self->{password} && $self->{name});
    $self->request;
    return $self;
}

=head2 enable

Enable authentication.

    $etcd->auth()->enable;

=cut

sub enable {
    my ( $self, $options ) = @_;
    $self->{endpoint} = '/auth/enable';
    $self->{json_args} = '{}';
    $self->request;
    return $self;
}

=head2 disable

Disable authentication, this requires a valid root password.

    $etcd->auth({ name => 'root', $password => $pass })->disable;

=cut

sub disable {
    my ( $self, $options ) = @_;
    $self->{endpoint} = '/auth/disable';
    confess 'root name and password required for ' . __PACKAGE__ . '->disable'
      unless ($self->{password} && $self->{name});
    $self->request;
    return $self;
}

1;

lib/Etcd3/Auth/Role.pm  view on Meta::CPAN

Etcd3::Auth::Role

=cut

our $VERSION = '0.007';

=head1 DESCRIPTION

Role

=head2 endpoint

=cut

has endpoint => (
    is       => 'rwp',
    isa      => Str,
);

=head2 name

name of role

=cut

lib/Etcd3/Auth/Role.pm  view on Meta::CPAN

=head2 add

Add role

=cut

sub add {
    my ($self) = @_;
    confess 'name required for ' . __PACKAGE__ . '->add'
      unless $self->{name};
    $self->{endpoint} = '/auth/role/add';
    $self->request;
    return $self;
}

=head2 delete

Delete role

=cut

sub delete {
    my ($self) = @_;
    confess 'name required for ' . __PACKAGE__ . '->delete'
      unless $self->{role};
    $self->{endpoint} = '/auth/role/delete';
    $self->request;
    return $self;
}

=head2 get

Get role

=cut

sub get {
    my ($self) = @_;
    confess 'name required for ' . __PACKAGE__ . '->get'
      unless $self->{role};
    $self->{endpoint} = '/auth/role/get';
    $self->request;
    return $self;
}

=head2 list

List roles

=cut

sub list {
    my ($self) = @_;
    $self->{endpoint} = '/auth/role/list';
    $self->{json_args} = '{}';
    $self->request;
    return $self;
}
1;

lib/Etcd3/KV.pm  view on Meta::CPAN


    $etcd->range({key =>'test0', range_end => 'test100'})

=cut

sub range {
    my ( $self, $options ) = @_;
	my $cb = pop if ref $_[-1] eq 'CODE';
    my $range = Etcd3::KV::Range->new(
        %$self,
        endpoint => '/kv/range',
        etcd     => $self,
		cb       => $cb,
        ( $options ? %$options : () ),
    );
    $range->request;
    return $range;
}

=head2 put

lib/Etcd3/KV.pm  view on Meta::CPAN


    $etcd->range({key =>'test0', range_end => 'test100'})

=cut

sub put {
    my ( $self, $options ) = @_;
	my $cb = pop if ref $_[-1] eq 'CODE';
    my $range = Etcd3::KV::Put->new(
        %$self,
        endpoint => '/kv/put',
        etcd     => $self,
		cb       => $cb,
        ( $options ? %$options : () ),
    );
    $range->request;
    return $range;
}

1;

lib/Etcd3/KV/Put.pm  view on Meta::CPAN

our $VERSION = '0.007';

=head1 DESCRIPTION

Put puts the given key into the key-value store. A put request increments
the revision of the key-value store and generates one event in the event
history.

=head1 ACCESSORS

=head2 endpoint

=cut

has endpoint => (
    is      => 'ro',
    isa     => Str,
    default => '/kv/put'
);

=head2 key

key is the key, in bytes, to put into the key-value store.

=cut

lib/Etcd3/KV/Range.pm  view on Meta::CPAN

=cut

our $VERSION = '0.007';

=head1 DESCRIPTION

Range gets the keys in the range from the key-value store.

=head1 ACCESSORS

=head2 endpoint

=cut

has endpoint => (
    is      => 'ro',
    isa     => Str,
);

=head2 key

key is the first key for the range. If range_end is not given, the request only looks up key.
the key is encoded with base64.  type bytes

=cut

lib/Etcd3/KV/Range.pm  view on Meta::CPAN

DeleteRange deletes the given range from the key-value store. A delete request increments the
revision of the key-value store and generates a delete event in the event history for every
deleted key.

    $etcd->range({key =>'test0'})->delete

=cut

sub delete {
    my ( $self ) = @_;
    $self->{endpoint} => '/kv/deleterange',
    return $self->request;
}

1;

lib/Etcd3/Lease.pm  view on Meta::CPAN

our $VERSION = '0.007';

=head1 DESCRIPTION

LeaseGrant creates a lease which expires if the server does not receive a keepAlive within
a given time to live period. All keys attached to the lease will be expired and deleted if
the lease expires. Each expired key generates a delete event in the event history.

=head1 ACCESSORS

=head2 endpoint

=cut

has endpoint => (
    is      => 'rwp',
    isa     => Str,
);

=head2 TTL

TTL is the advisory time-to-live in seconds.

=cut

lib/Etcd3/Lease.pm  view on Meta::CPAN

a given time to live period. All keys attached to the lease will be expired and deleted if
the lease expires. Each expired key generates a delete event in the event history.


$etcd->lease({ name =>'foo' password => 'bar' })->grant

=cut

sub grant {
    my $self = shift;
    $self->{endpoint} = '/lease/grant';
    confess 'TTL and ID are required for ' . __PACKAGE__ . '->grant'
      unless ($self->{ID} &&  $self->{TTL});
    $self->request;
    return $self;
}

=head2 revoke

LeaseRevoke revokes a lease. All keys attached to the lease will expire and be deleted.

$etcd->lease({{ ID => 7587821338341002662 })->revoke

=cut

sub revoke {
    my $self = shift;
    $self->{endpoint} = '/kv/lease/revoke';
    confess 'ID is required for ' . __PACKAGE__ . '->revoke'
      unless $self->{ID};
    $self->request;
    return $self;
}

=head2 ttl

LeaseTimeToLive retrieves lease information.

$etcd->lease({{ ID => 7587821338341002662, keys => 1 })->ttl

=cut

sub ttl {
    my $self = shift;
    $self->{endpoint} = '/kv/lease/timetolive';
    confess 'ID is required for ' . __PACKAGE__ . '->ttl'
      unless $self->{ID};
    $self->request;
    return $self;
}


=head2 keepalive

LeaseKeepAlive keeps the lease alive by streaming keep alive requests from the client
to the server and streaming keep alive responses from the server to the client."

$etcd->lease({{ ID => 7587821338341002662 })->keepalive

=cut

sub keepalive {
    my $self = shift;
    $self->{endpoint} = '/lease/keepalive';
    confess 'ID is required for ' . __PACKAGE__ . '->keepalive'
      unless $self->{ID};
    $self->request;
    return $self;
}

1;

lib/Etcd3/Role/Actions.pm  view on Meta::CPAN

arguments that will be sent to the api

=cut

has json_args => ( is => 'lazy', );

sub _build_json_args {
    my ($self) = @_;
    my $args;
    for my $key ( keys %{$self} ) {
        unless ( $key =~ /(?:etcd|cb|cv|json_args|endpoint)$/ ) {
            $args->{$key} = $self->{$key};
        }
    }
    return to_json($args);
}

=head2 cb

AnyEvent callback must be a CodeRef

lib/Etcd3/Role/Actions.pm  view on Meta::CPAN

has request => ( is => 'lazy', );

sub _build_request {
    my ($self) = @_;
    $self->init;
    my $cb = $self->cb;
    my $cv = $self->cv ? $self->cv : AE::cv;
    $cv->begin;
    http_request(
        'POST',
        $self->etcd->api_path . $self->{endpoint},
        headers => $self->headers,
        body => $self->json_args,
        on_header => sub {
            my($headers) = @_;
            $self->{response}{headers} = $headers;
        },
        on_body   => sub {
            my ($data, $hdr) = @_;
            $self->{response}{content} = $data;
            $cb->($data, $hdr) if $cb;

lib/Etcd3/User.pm  view on Meta::CPAN

our $VERSION = '0.007';

=head1 DESCRIPTION

User class

=cut

=head1 ACCESSORS

=head2 endpoint

=cut

has endpoint => (
    is       => 'rwp',
    isa      => Str,
);

=head2 name

name of user

=cut

lib/Etcd3/User.pm  view on Meta::CPAN

=head1 PUBLIC METHODS

=head2 add

$etcd->user({ name =>'foo' password => 'bar' })->add

=cut

sub add {
    my $self = shift;
    $self->{endpoint} = '/auth/user/add';
    confess 'password required for ' . __PACKAGE__ . '->add'
      unless $self->{password};
    $self->request;
    return $self;
}

=head2 delete

$etcd->user({ name =>'foo' })->delete

=cut

sub delete {
    my $self = shift;
    $self->{endpoint} = '/auth/user/delete';
    $self->request;
    return $self;
}

1;

lib/Etcd3/User/Role.pm  view on Meta::CPAN

our $VERSION = '0.007';

=head1 DESCRIPTION

Use role

=cut

=head1 ACCESSORS

=head2 endpoint

=cut

has endpoint => (
    is       => 'ro',
    isa      => Str,
);

=head2 user

name of user

=cut

lib/Etcd3/User/Role.pm  view on Meta::CPAN

);

=head1 PUBLIC METHODS

=head2 grant

=cut

sub grant {
    my $self = shift;
    $self->{endpoint} = '/auth/user/grant';
    $self->request;
    return $self;
}

=head2 revoke

=cut

sub revoke {
    my $self = shift;
    $self->{endpoint} = '/auth/user/revoke';
    $self->request;
    return $self;
}

1;

lib/Etcd3/Watch.pm  view on Meta::CPAN


=head1 DESCRIPTION

Watch watches for events happening or that have happened. Both input and output are streams;
the input stream is for creating and canceling watchers and the output stream sends events.
One watch RPC can watch on multiple key ranges, streaming events for several watches at once.
The entire event history can be watched starting from the last compaction revision.

=head1 ACCESSORS

=head2 endpoint

=cut

has endpoint => (
    is      => 'ro',
    isa     => Str,
    default => '/watch'
);

=head2 key

key is the first key for the range. If range_end is not given, the request only looks up key.
the key is encoded with base64.  type bytes



( run in 1.169 second using v1.01-cache-2.11-cpan-2b1a40005be )