EV-Etcd
view release on metacpan or search on metacpan
lib/EV/Etcd.pm view on Meta::CPAN
die $err->{message} if $err;
my $lease_id = $lease_resp->{id};
# Now acquire the lock
$client->lock("my-resource", $lease_id, sub {
my ($lock_resp, $err) = @_;
die $err->{message} if $err;
my $lock_key = $lock_resp->{key};
print "Lock acquired with key: $lock_key\n";
# ... do protected work ...
# Release the lock when done
$client->unlock($lock_key, sub {
my ($unlock_resp, $err) = @_;
warn "Unlock failed: $err->{message}" if $err;
});
});
});
=head2 unlock
$client->unlock($key, $callback);
Release a distributed lock.
Arguments:
=over 4
=item key
The lock key returned from a successful C<lock> call. This is the unique
key that was created to hold the lock ownership.
=item callback
Called with C<($response, $error)> when the unlock completes.
=back
The response contains:
=over 4
=item header
Standard response header with cluster_id, member_id, revision, and raft_term.
=back
B<Note>: You can also release a lock by revoking its associated lease with
C<lease_revoke>. This is useful if you want to release all resources
associated with a lease at once.
=head1 AUTHENTICATION SERVICE
EV::Etcd provides full support for etcd's authentication and authorization
system. Authentication uses username/password credentials, and authorization
is based on roles with key-range permissions.
=head2 authenticate
$client->authenticate($username, $password, $callback);
Authenticate with etcd using username and password. On success, the client
automatically stores the auth token and uses it for subsequent requests.
Arguments:
=over 4
=item username
The username to authenticate as.
=item password
The password for the user.
=item callback
Called with C<($response, $error)> when authentication completes.
=back
The response contains:
=over 4
=item token
The authentication token (also automatically stored in the client).
=item header
Standard response header.
=back
Example:
$client->authenticate('admin', 'secret', sub {
my ($resp, $err) = @_;
if ($err) {
die "Authentication failed: $err->{message}";
}
say "Authenticated successfully";
# Client now automatically uses the token for all requests
});
=head2 auth_enable
$client->auth_enable($callback);
Enable authentication on the etcd cluster.
B<Warning>: Before enabling auth, you must create at least one user with
the root role, otherwise you will be locked out of the cluster.
( run in 0.569 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )