view release on metacpan or search on metacpan
56789101112131415161718192021222324250.026 2019-09-05 18:52:05+10:00 Australia/Melbourne
- Test updates
for
Test::Consul 0.14
0.025 2019-04-05 12:05:24+11:00 Australia/Melbourne
- Test updates
for
Test::Consul 0.013 / consul >= 1.4
0.024 2019-02-21 08:22:12+11:00 Australia/Melbourne
- Bugfix: Not all meta fields are required.
0.023 2018-01-21 11:31:20+11:00 Australia/Melbourne
- Bugfix: Setting a value to 0 in the KV store would store an empty
string. Now it stores 0.
0.022 2017-08-03 17:00:44+10:00 Australia/Melbourne
- Bugfix: get_all now returns empty array
when
no
nodes found
0.021 2017-07-21 17:54:30+10:00 Australia/Melbourne
- Support setting and getting null
values
in the KV store
0.020 2016-12-20 20:59:28+11:00 Australia/Melbourne
40414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394950.018 2016-09-23 13:47:43+10:00 Australia/Melbourne
- Fixup error_cb test to work even
when
there is an existing
Consul agent listening on port 8500.
- Update
for
Test-Consul 0.005 (Consul 0.6.1 through 0.7.0+)
0.017 2016-09-22 23:24:53+10:00 Australia/Melbourne
- Add support
for
enableTagOverride attribute on services
- Add support
for
ServiceAddress attribute on catalog entries
0.016 2016-02-19 08:54:46+11:00 Australia/Melbourne
- Error callback
for
individual endpoint methods
- Update
for
Test-Consul 0.003 (Consul 0.6.3)
0.015 2015-12-08 16:59:19+11:00 Australia/Melbourne
- Fix session/info on nonexistent session (Consul 0.6.0)
0.014 2015-12-07 17:05:57+11:00 Australia/Melbourne
- Implement Sessions API
0.013 2015-11-25 21:20:44+11:00 Australia/Melbourne
- Never call the endpoint callback
after
calling the error callback
0.012 2015-11-25 20:02:06+11:00 Australia/Melbourne
- API change: Switch request_cb to take and
return
a parameter object
- API change: Include original args
with
request, and request
with
response
0.011 2015-11-24 08:55:35+11:00 Australia/Melbourne
- API change: Rename req_cb to request_cb
- Separate error_cb attr
for
async modules to avoid croak
0.010 2015-11-23 20:13:16+11:00 Australia/Melbourne
- Add KV get_all endpoint method,
for
recursive get
0.009 2015-11-19 22:17:32+11:00 Australia/Melbourne
- Don't
use
defined
-or, gets things working on Perl 5.8
0.008 2015-11-18 12:58:37+11:00 Australia/Melbourne
- Fix _http builder, get it passing tests again
- Silence warning during croak
when
call fails without content
0.007 2015-11-18 08:51:27+11:00 Australia/Melbourne
- API change: Add timeout option, remove http option
0.006 2015-11-16 09:34:58+11:00 Australia/Melbourne
- API change: Return
undef
when
KV key not found
- API change: Return server meta from
"blocking"
endpoints
- Make Event::fire properly async
0.005 2015-11-13 21:21:52+11:00 Australia/Melbourne
- Support
for
async calls
0.004 2015-11-07 15:03:25+11:00 Australia/Melbourne
- Fix accessor defaults (Moo requires them to be coderefs)
- Don't
use
defined
-or, gets things working on Perl 5.8
0.003 2015-11-06 16:36:14+11:00 Australia/Melbourne
lib/Consul.pm view on Meta::CPAN
253254255256257258259260261262263264265266267268269270271272=item *
C<ssl>
Use SSL/TLS (ie HTTPS) when talking to the Consul server (default: off)
=item *
C<timeout>
Request timeout. If a request to Consul takes longer that this, the endpoint
method will fail (default: 15).
=item *
C<token>
Consul ACL token. This is used to set the C<X-Consul-Token> HTTP header. Typically
Consul agents are pre-configured with a default ACL token, or ACLs are not enabled
at all, so this option only needs to be set in certain cases.
lib/Consul.pm view on Meta::CPAN
318319320321322323324325326327328329330331332333334335336337338C<callback>
A callback to call
when
the request is completed. It takes a single
C<Consul::Response> object as its parameter.
=item *
C<args>
A hashref containing the original arguments passed in to the endpoint method.
=back
The C<callback> function should be called with a C<Consul::Response> object
containing the values returned by the Consul server in response to the request.
Create one with C<new>, passing the following attributes:
=over 4
=item *
lib/Consul.pm view on Meta::CPAN
365366367368369370371372373374375376377378379380381382383384The C<Consul::Request> object passed to the callback.
=back
Consul itself provides a default C<request_cb> that uses L<HTTP::Tiny> to make
calls to the server. If you provide one, you should honour the value of the
C<timeout> argument.
C<request_cb> can be used in conjunction with the C<cb> option to all API method
endpoints to get asynchronous behaviour. It's recommended however that you
don't use this directly, but rather use a module like L<AnyEvent::Consul> to
take care of that for you.
If you just want to use this module to make simple calls to your Consul
cluster, you can ignore this option entirely.
=item *
C<error_cb>
lib/Consul.pm view on Meta::CPAN
390391392393394395396397398399400401402403404405406407408409
my
(
$err
) =
@_
;
... output
$err
...
}
The
default
callback simply calls C<croak>.
=back
=head1 ENDPOINTS
Individual API endpoints are implemented in separate modules. The following
methods will return a context objects for the named API. Alternatively, you can
request an API context directly from the Consul package. In that case,
C<Consul-E<gt>new> is called implicitly.
# these are equivalent
my $agent = Consul->new( %args )->agent;
my $agent = Consul->agent( %args );
=head2 kv
lib/Consul.pm view on Meta::CPAN
433434435436437438439440441442443444445446447448449450451452453454=head2 event
User event API. See L<Consul::API::Event>.
=head2 status
System status API. See L<Consul::API::Status>.
=head1 METHOD OPTIONS
All API methods implemented by the endpoints can take a number of arguments.
Most of those are documented in the endpoint documentation. There are however
some that are common to all methods:
=over 4
=item *
C<cb>
A callback to call with the results of the method. Without this, the results
are returned from the method, but only if C<request_cb> is synchronous. If an
lib/Consul.pm view on Meta::CPAN
468469470471472473474475476477478479480481482483484485486487488489490491
... output
$err
...
}
The
default
callback calls the C<error_cb>
for
the API object itself, which by
default
, simply calls croak.
=back
=head1 BLOCKING QUERIES
Some Consul API endpoints support a feature called a "blocking query". These
endpoints allow long-polling for changes, and support some extra information
about the server state, including the Raft index, in the response headers.
The corresponding endpoint methods, when called in array context, will return a
second value. This is an object with three methods, C<index>, C<last_contact>
and C<known_leader>, corresponding to the similarly-named header fields. You
can use these to set up state watches, CAS writes, and so on.
See the Consul API docs for more information.
=head1 SEE ALSO
=over 4
lib/Consul/API/ACL.pm view on Meta::CPAN
123456789101112131415161718192021package
Consul::API::ACL;
$Consul::API::ACL::VERSION
=
'0.027'
;
use
namespace::autoclean;
use
Moo::Role;
requires
qw(_version_prefix _api_exec)
;
has
_acl_endpoint
=> (
is
=>
'lazy'
,
isa
=> Str );
sub
_build__acl_endpoint {
shift
->_version_prefix .
'/acl'
;
}
sub
acl {
my
$self
=
shift
;
$self
= Consul->new(
@_
)
unless
ref
$self
;
return
bless
\
$self
,
"Consul::API::ACL::Impl"
;
}
package
lib/Consul/API/ACL.pm view on Meta::CPAN
242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980use
Moo;
use
Consul::ACL;
sub
create {
my
(
$self
,
$acl
,
%args
) =
@_
;
$acl
||= {};
$acl
= Consul::ACL->new(
$acl
)
if
!blessed
$acl
;
$$self
->_api_exec(
$$self
->_acl_endpoint.
"/create"
,
'PUT'
,
%args
,
_content
=>
$acl
->to_json(),
sub
{
Consul::API::ACL::Success->new(
$_
[0])
});
}
sub
update {
my
(
$self
,
$acl
,
%args
) =
@_
;
croak
'usage: $acl->update($acl, [%args])'
if
grep
{ !
defined
} (
$acl
);
$acl
= Consul::ACL->new(
$acl
)
if
!blessed
$acl
;
$$self
->_api_exec(
$$self
->_acl_endpoint.
"/update"
,
'PUT'
,
%args
,
_content
=>
$acl
->to_json());
}
sub
destroy {
my
(
$self
,
$id
,
%args
) =
@_
;
croak
'usage: $acl->destroy($id, [%args])'
if
grep
{ !
defined
} (
$id
);
$$self
->_api_exec(
$$self
->_acl_endpoint.
"/destroy/$id"
,
'PUT'
,
%args
);
}
sub
info {
my
(
$self
,
$id
,
%args
) =
@_
;
croak
'usage: $acl->info($id, [%args])'
if
grep
{ !
defined
} (
$id
);
$$self
->_api_exec(
$$self
->_acl_endpoint.
"/info/$id"
,
'GET'
,
%args
,
sub
{
Consul::API::ACL::Info->new(
$_
[0]->[0])
});
}
sub
clone {
my
(
$self
,
$id
,
%args
) =
@_
;
croak
'usage: $acl->clone($id, [%args])'
if
grep
{ !
defined
} (
$id
);
$$self
->_api_exec(
$$self
->_acl_endpoint.
"/clone/$id"
,
'PUT'
,
%args
,
sub
{
Consul::API::ACL::Success->new(
$_
[0])
});
}
sub
list {
my
(
$self
,
%args
) =
@_
;
$$self
->_api_exec(
$$self
->_acl_endpoint.
"/list"
,
'GET'
,
%args
,
sub
{
[
map
{ Consul::API::ACL::Info->new(
$_
) } @{
$_
[0]} ]
});
}
package
Consul::API::ACL::Info;
$Consul::API::ACL::Info::VERSION
=
'0.027'
;
use
Moo;
has
create_index
=> (
is
=>
'ro'
,
isa
=> Str,
init_arg
=>
'CreateIndex'
,
required
=> 1 );
lib/Consul/API/Agent.pm view on Meta::CPAN
123456789101112131415161718192021package
Consul::API::Agent;
$Consul::API::Agent::VERSION
=
'0.027'
;
use
namespace::autoclean;
use
Moo::Role;
requires
qw(_version_prefix _api_exec)
;
has
_agent_endpoint
=> (
is
=>
'lazy'
,
isa
=> Str );
sub
_build__agent_endpoint {
shift
->_version_prefix .
'/agent'
;
}
sub
agent {
my
$self
=
shift
;
$self
= Consul->new(
@_
)
unless
ref
$self
;
return
bless
\
$self
,
"Consul::API::Agent::Impl"
;
}
package
lib/Consul/API/Agent.pm view on Meta::CPAN
24252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148use
Moo;
use
Consul::Check;
use
Consul::Service;
sub
checks {
my
(
$self
,
%args
) =
@_
;
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/checks"
,
'GET'
,
%args
,
sub
{
[
map
{ Consul::API::Agent::Check->new(
%$_
) }
values
%{
$_
[0]} ]
});
}
sub
services {
my
(
$self
,
%args
) =
@_
;
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/services"
,
'GET'
,
%args
,
sub
{
[
map
{ Consul::API::Agent::Service->new(
%$_
) }
values
%{
$_
[0]} ]
});
}
sub
members {
my
(
$self
,
%args
) =
@_
;
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/members"
,
'GET'
,
%args
,
sub
{
[
map
{ Consul::API::Agent::Member->new(
%$_
) } @{
$_
[0]} ]
});
}
sub
self {
my
(
$self
,
%args
) =
@_
;
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/self"
,
'GET'
,
%args
,
sub
{
Consul::API::Agent::Self->new(%{
$_
[0]})
});
}
sub
maintenance {
my
(
$self
,
$enable
,
%args
) =
@_
;
croak
'usage: $agent->maintenance($enable, [%args])'
if
grep
{ !
defined
} (
$enable
);
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/maintenance"
,
'PUT'
,
enable
=> (
$enable
?
"true"
:
"false"
),
%args
);
return
;
}
sub
join
{
my
(
$self
,
$address
,
%args
) =
@_
;
croak
'usage: $agent->join($address, [%args])'
if
grep
{ !
defined
} (
$address
);
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/join/"
.
$address
,
'PUT'
,
%args
);
return
;
}
sub
force_leave {
my
(
$self
,
$node
,
%args
) =
@_
;
croak
'usage: $agent->force_leave($node, [%args])'
if
grep
{ !
defined
} (
$node
);
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/force-leave/"
.
$node
,
'PUT'
,
%args
);
return
;
}
sub
check_register {
my
(
$self
,
$check
,
%args
) =
@_
;
croak
'usage: $agent->check_register($check, [%args])'
if
grep
{ !
defined
} (
$check
);
{
local
$Carp::CarpInternal
{ (__PACKAGE__) } = 1;
$check
= Consul::Check->smart_new(
$check
)
if
!blessed
$check
;
}
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/check/register"
,
'PUT'
,
%args
,
_content
=>
$check
->to_json);
return
;
}
sub
check_deregister {
my
(
$self
,
$check_id
,
%args
) =
@_
;
croak
'usage: $agent->check_deregister($check_id, [%args])'
if
grep
{ !
defined
} (
$check_id
);
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/check/deregister/"
.
$check_id
,
'PUT'
,
%args
);
return
;
}
sub
check_pass {
my
(
$self
,
$check_id
,
%args
) =
@_
;
croak
'usage: $agent->check_pass($check_id, [%args])'
if
grep
{ !
defined
} (
$check_id
);
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/check/pass/"
.
$check_id
,
'PUT'
,
%args
);
return
;
}
sub
check_warn {
my
(
$self
,
$check_id
,
%args
) =
@_
;
croak
'usage: $agent->check_warn($check_id, [%args])'
if
grep
{ !
defined
} (
$check_id
);
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/check/warn/"
.
$check_id
,
'PUT'
,
%args
);
return
;
}
sub
check_fail {
my
(
$self
,
$check_id
,
%args
) =
@_
;
croak
'usage: $agent->check_fail($check_id, [%args])'
if
grep
{ !
defined
} (
$check_id
);
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/check/fail/"
.
$check_id
,
'PUT'
,
%args
);
return
;
}
sub
service_register {
my
(
$self
,
$service
,
%args
) =
@_
;
croak
'usage: $agent->service_register($service, [%args])'
if
grep
{ !
defined
} (
$service
);
$service
= Consul::Service->new(
$service
)
if
!blessed
$service
;
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/service/register"
,
'PUT'
,
%args
,
_content
=>
$service
->to_json);
return
;
}
sub
service_deregister {
my
(
$self
,
$service_id
,
%args
) =
@_
;
croak
'usage: $agent->service_deregister($check_id, [%args])'
if
grep
{ !
defined
} (
$service_id
);
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/service/deregister/"
.
$service_id
,
'PUT'
,
%args
);
return
;
}
sub
service_maintenance {
my
(
$self
,
$service_id
,
$enable
,
%args
) =
@_
;
croak
'usage: $agent->service_maintenance($service_id, $enable, [%args])'
if
grep
{ !
defined
} (
$service_id
,
$enable
);
$$self
->_api_exec(
$$self
->_agent_endpoint.
"/service/maintenance/"
.
$service_id
,
'PUT'
,
enable
=> (
$enable
?
"true"
:
"false"
),
%args
);
return
;
}
package
Consul::API::Agent::Check;
$Consul::API::Agent::Check::VERSION
=
'0.027'
;
use
Moo;
has
node
=> (
is
=>
'ro'
,
isa
=> Str,
init_arg
=>
'Node'
,
required
=> 1 );
has
id
=> (
is
=>
'ro'
,
isa
=> Str,
init_arg
=>
'CheckID'
,
required
=> 1 );
lib/Consul/API/Catalog.pm view on Meta::CPAN
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576package
Consul::API::Catalog;
$Consul::API::Catalog::VERSION
=
'0.027'
;
use
namespace::autoclean;
use
Moo::Role;
requires
qw(_version_prefix _api_exec)
;
has
_catalog_endpoint
=> (
is
=>
'lazy'
,
isa
=> Str );
sub
_build__catalog_endpoint {
shift
->_version_prefix .
'/catalog'
;
}
sub
catalog {
my
$self
=
shift
;
$self
= Consul->new(
@_
)
unless
ref
$self
;
return
bless
\
$self
,
"Consul::API::Catalog::Impl"
;
}
package
Consul::API::Catalog::Impl;
# hide from PAUSE
use
Moo;
sub
datacenters {
my
(
$self
,
%args
) =
@_
;
$$self
->_api_exec(
$$self
->_catalog_endpoint.
"/datacenters"
,
'GET'
,
%args
);
}
sub
nodes {
my
(
$self
,
%args
) =
@_
;
$$self
->_api_exec(
$$self
->_catalog_endpoint.
"/nodes"
,
'GET'
,
%args
,
sub
{
[
map
{ Consul::API::Catalog::ShortNode->new(
%$_
) } @{
$_
[0]} ]
});
}
sub
services {
my
(
$self
,
%args
) =
@_
;
$$self
->_api_exec(
$$self
->_catalog_endpoint.
"/services"
,
'GET'
,
%args
);
}
sub
service {
my
(
$self
,
$service
,
%args
) =
@_
;
croak
'usage: $catalog->service($service, [%args])'
if
grep
{ !
defined
} (
$service
);
$$self
->_api_exec(
$$self
->_catalog_endpoint.
"/service/"
.
$service
,
'GET'
,
%args
,
sub
{
[
map
{ Consul::API::Catalog::Service->new(
%$_
) } @{
$_
[0]} ]
});
}
sub
register {
# register
croak
"not yet implemented"
;
}
sub
deregister {
# deregister
croak
"not yet implemented"
;
}
sub
node {
my
(
$self
,
$node
,
%args
) =
@_
;
croak
'usage: $catalog->node($node, [%args])'
if
grep
{ !
defined
} (
$node
);
$$self
->_api_exec(
$$self
->_catalog_endpoint.
"/node/"
.
$node
,
'GET'
,
%args
,
sub
{
Consul::API::Catalog::Node->new(
$_
[0])
});
}
package
Consul::API::Catalog::ShortNode;
$Consul::API::Catalog::ShortNode::VERSION
=
'0.027'
;
use
Moo;
has
name
=> (
is
=>
'ro'
,
isa
=> Str,
init_arg
=>
'Node'
,
required
=> 1 );
lib/Consul/API/Catalog.pm view on Meta::CPAN
110111112113114115116117118119120121122123124125126127128129130=head1 SYNOPSIS
use Consul;
my $catalog = Consul->catalog;
say for map { $_->name} @{$catalog->nodes};
=head1 DESCRIPTION
The catalog API is used to register and deregister nodes, services and checks.
It also provides query endpoints.
This API is fully documented at L<https://www.consul.io/docs/agent/http/catalog.html>.
=head1 METHODS
=head2 datacenters
=head2 nodes
=head2 services
lib/Consul/API/Event.pm view on Meta::CPAN
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849package
Consul::API::Event;
$Consul::API::Event::VERSION
=
'0.027'
;
use
namespace::autoclean;
use
Moo::Role;
requires
qw(_version_prefix _api_exec)
;
has
_event_endpoint
=> (
is
=>
'lazy'
,
isa
=> Str );
sub
_build__event_endpoint {
shift
->_version_prefix .
'/event'
;
}
sub
event {
my
$self
=
shift
;
$self
= Consul->new(
@_
)
unless
ref
$self
;
return
bless
\
$self
,
"Consul::API::Event::Impl"
;
}
package
Consul::API::Event::Impl;
# hide from PAUSE
use
Moo;
sub
fire {
my
(
$self
,
$name
,
%args
) =
@_
;
croak
'usage: $event->fire($name, [%args])'
if
grep
{ !
defined
} (
$name
);
my
$payload
=
delete
$args
{payload};
$$self
->_api_exec(
$$self
->_event_endpoint.
"/fire/"
.
$name
,
'PUT'
,
%args
, (
$payload
? (
_content
=>
$payload
) : ()),
sub
{
Consul::API::Event::Event->new(
$_
[0])
});
}
sub
list {
my
(
$self
,
%args
) =
@_
;
$$self
->_api_exec(
$$self
->_event_endpoint.
"/list"
,
'GET'
,
%args
,
sub
{
[
map
{ Consul::API::Event::Event->new(
%$_
) } @{
$_
[0]} ]
});
}
package
Consul::API::Event::Event;
$Consul::API::Event::Event::VERSION
=
'0.027'
;
use
Moo;
lib/Consul/API/Health.pm view on Meta::CPAN
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465package
Consul::API::Health;
$Consul::API::Health::VERSION
=
'0.027'
;
use
namespace::autoclean;
use
Moo::Role;
requires
qw(_version_prefix _api_exec)
;
has
_health_endpoint
=> (
is
=>
'lazy'
,
isa
=> Str );
sub
_build__health_endpoint {
shift
->_version_prefix .
'/health'
;
}
sub
health {
my
$self
=
shift
;
$self
= Consul->new(
@_
)
unless
ref
$self
;
return
bless
\
$self
,
"Consul::API::Health::Impl"
;
}
package
Consul::API::Health::Impl;
# hide from PAUSE
use
Moo;
sub
node {
my
(
$self
,
$node
,
%args
) =
@_
;
croak
'usage: $health->node($node, [%args])'
if
grep
{ !
defined
} (
$node
);
$$self
->_api_exec(
$$self
->_health_endpoint.
"/node/"
.
$node
,
'GET'
,
%args
,
sub
{
[
map
{ Consul::API::Health::Check->new(
%$_
) } @{
$_
[0]} ]
});
}
sub
checks {
my
(
$self
,
$service
,
%args
) =
@_
;
croak
'usage: $health->checks($service, [%args])'
if
grep
{ !
defined
} (
$service
);
$$self
->_api_exec(
$$self
->_health_endpoint.
"/checks/"
.
$service
,
'GET'
,
%args
,
sub
{
[
map
{ Consul::API::Health::Check->new(
%$_
) } @{
$_
[0]} ]
});
}
sub
service {
my
(
$self
,
$service
,
%args
) =
@_
;
croak
'usage: $health->service($service, [%args])'
if
grep
{ !
defined
} (
$service
);
$$self
->_api_exec(
$$self
->_health_endpoint.
"/service/"
.
$service
,
'GET'
,
%args
,
sub
{
[
map
{ Consul::API::Health::Service->new(
%$_
) } @{
$_
[0]} ]
});
}
sub
state {
my
(
$self
,
$state
,
%args
) =
@_
;
croak
'usage: $health->state($state, [%args])'
if
grep
{ !
defined
} (
$state
);
$$self
->_api_exec(
$$self
->_health_endpoint.
"/state/"
.
$state
,
'GET'
,
%args
,
sub
{
[
map
{ Consul::API::Health::Check->new(
%$_
) } @{
$_
[0]} ]
});
}
package
Consul::API::Health::Check;
$Consul::API::Health::Check::VERSION
=
'0.027'
;
use
Moo;
has
node
=> (
is
=>
'ro'
,
isa
=> Str,
init_arg
=>
'Node'
,
required
=> 1 );
lib/Consul/API/KV.pm view on Meta::CPAN
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283package
Consul::API::KV;
$Consul::API::KV::VERSION
=
'0.027'
;
use
namespace::autoclean;
use
Moo::Role;
requires
qw(_version_prefix _api_exec)
;
has
_kv_endpoint
=> (
is
=>
'lazy'
,
isa
=> Str );
sub
_build__kv_endpoint {
shift
->_version_prefix .
'/kv'
;
}
sub
kv {
my
$self
=
shift
;
$self
= Consul->new(
@_
)
unless
ref
$self
;
return
bless
\
$self
,
"Consul::API::KV::Impl"
;
}
package
Consul::API::KV::Impl;
# hide from PAUSE
use
Moo;
sub
get {
my
(
$self
,
$key
,
%args
) =
@_
;
croak
'usage: $kv->get($key, [%args])'
if
grep
{ !
defined
} (
$key
);
$$self
->_api_exec(
$$self
->_kv_endpoint.
"/"
.
$key
,
'GET'
,
%args
,
_valid_cb
=>
sub
{
int
(
$_
[0]/100) == 2 ||
int
(
$_
[0]) == 404
},
sub
{
return
undef
unless
defined
$_
[0];
Consul::API::KV::Response->new(
$_
[0]->[0]);
}
);
}
sub
get_all {
my
(
$self
,
$key
,
%args
) =
@_
;
croak
'usage: $kv->get_all($key, [%args])'
if
grep
{ !
defined
} (
$key
);
$$self
->_api_exec(
$$self
->_kv_endpoint.
"/"
.
$key
,
'GET'
,
%args
,
recurse
=> 1,
_valid_cb
=>
sub
{
int
(
$_
[0]/100) == 2 ||
int
(
$_
[0]) == 404
},
sub
{
return
[]
unless
defined
$_
[0];
[
map
{ Consul::API::KV::Response->new(
$_
) } @{
$_
[0]} ]
}
);
}
sub
put {
my
(
$self
,
$key
,
$value
,
%args
) =
@_
;
croak
'usage: $kv->put($key, $value, [%args])'
unless
defined
(
$key
) &&
@_
>= 3;
$$self
->_api_exec(
$$self
->_kv_endpoint.
"/"
.
$key
,
'PUT'
,
%args
,
_content
=>
$value
);
}
sub
delete
{
my
(
$self
,
$key
,
%args
) =
@_
;
croak
'usage: $kv->delete($key, [%args])'
if
grep
{ !
defined
} (
$key
);
$$self
->_api_exec(
$$self
->_kv_endpoint.
"/"
.
$key
,
'DELETE'
,
%args
);
return
;
}
sub
keys
{
my
(
$self
,
$key
,
%args
) =
@_
;
croak
'usage: $kv->keys($key, [%args])'
if
grep
{ !
defined
} (
$key
);
$$self
->_api_exec(
$$self
->_kv_endpoint.
"/"
.
$key
,
'GET'
,
%args
,
keys
=> 1);
}
package
Consul::API::KV::Response;
$Consul::API::KV::Response::VERSION
=
'0.027'
;
use
Moo;
has
key
=> (
is
=>
'ro'
,
isa
=> Str,
init_arg
=>
'Key'
,
required
=> 1 );
lib/Consul/API/Session.pm view on Meta::CPAN
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980package
Consul::API::Session;
$Consul::API::Session::VERSION
=
'0.027'
;
use
namespace::autoclean;
use
Moo::Role;
requires
qw(_version_prefix _api_exec)
;
has
_session_endpoint
=> (
is
=>
'lazy'
,
isa
=> Str );
sub
_build__session_endpoint {
shift
->_version_prefix .
'/session'
;
}
sub
session {
my
$self
=
shift
;
$self
= Consul->new(
@_
)
unless
ref
$self
;
return
bless
\
$self
,
"Consul::API::Session::Impl"
;
}
package
Consul::API::Session::Impl;
# hide from PAUSE
use
Moo;
sub
create {
my
(
$self
,
$session
,
%args
) =
@_
;
$$self
->_api_exec(
$$self
->_session_endpoint.
"/create"
,
'PUT'
,
%args
, (
$session
? (
_content
=>
$session
->to_json) : ()),
sub
{
$_
[0]->{ID}
});
}
sub
destroy {
my
(
$self
,
$id
,
%args
) =
@_
;
croak
'usage: $session->destroy($id, [%args])'
if
grep
{ !
defined
} (
$id
);
$$self
->_api_exec(
$$self
->_session_endpoint.
"/destroy/"
.
$id
,
'PUT'
,
%args
)
}
sub
info {
my
(
$self
,
$id
,
%args
) =
@_
;
croak
'usage: $session->info($id, [%args])'
if
grep
{ !
defined
} (
$id
);
$$self
->_api_exec(
$$self
->_session_endpoint.
"/info/"
.
$id
,
'GET'
,
%args
,
sub
{
return
undef
unless
$_
[0] &&
$_
[0]->[0];
Consul::API::Session::Session->new(
$_
[0]->[0])
}
);
}
sub
node {
my
(
$self
,
$node
,
%args
) =
@_
;
croak
'usage: $session->node($id, [%args])'
if
grep
{ !
defined
} (
$node
);
$$self
->_api_exec(
$$self
->_session_endpoint.
"/node/"
.
$node
,
'GET'
,
%args
,
sub
{
[
map
{ Consul::API::Session::Session->new(
$_
) } @{
$_
[0]} ]
});
}
sub
list {
my
(
$self
,
%args
) =
@_
;
$$self
->_api_exec(
$$self
->_session_endpoint.
"/list"
,
'GET'
,
%args
,
sub
{
[
map
{ Consul::API::Session::Session->new(
$_
) } @{
$_
[0]} ]
});
}
sub
renew {
my
(
$self
,
$id
,
%args
) =
@_
;
croak
'usage: $session->renew($id, [%args])'
if
grep
{ !
defined
} (
$id
);
$$self
->_api_exec(
$$self
->_session_endpoint.
"/renew/"
.
$id
,
'PUT'
,
%args
,
sub
{
Consul::API::Session::Session->new(
$_
[0]->[0])
});
}
package
Consul::API::Session::Session;
$Consul::API::Session::Session::VERSION
=
'0.027'
;
use
Moo;
has
id
=> (
is
=>
'ro'
,
isa
=> Str,
init_arg
=>
'ID'
,
required
=> 1 );
lib/Consul/API/Status.pm view on Meta::CPAN
1234567891011121314151617181920212223242526272829303132333435363738394041424344package
Consul::API::Status;
$Consul::API::Status::VERSION
=
'0.027'
;
use
namespace::autoclean;
use
Moo::Role;
requires
qw(_version_prefix _api_exec)
;
has
_status_endpoint
=> (
is
=>
'lazy'
,
isa
=> Str );
sub
_build__status_endpoint {
shift
->_version_prefix .
'/status'
;
}
sub
status {
my
$self
=
shift
;
$self
= Consul->new(
@_
)
unless
ref
$self
;
return
bless
\
$self
,
"Consul::API::Status::Impl"
;
}
package
Consul::API::Status::Impl;
# hide from PAUSE
use
Moo;
sub
leader {
my
(
$self
,
%args
) =
@_
;
$$self
->_api_exec(
$$self
->_status_endpoint.
"/leader"
,
"GET"
,
%args
);
}
sub
peers {
my
(
$self
,
%args
) =
@_
;
$$self
->_api_exec(
$$self
->_status_endpoint.
"/peers"
,
"GET"
,
%args
);
}
1;
=pod
=encoding UTF-8
=head1 NAME