pub struct Consul { /* private fields */ }
Expand description
This struct defines the consul client and allows access to the consul api via method syntax.
Implementations§
Source§impl Consul
impl Consul
Sourcepub async fn get_lock(
&self,
request: LockRequest<'_>,
value: &[u8],
) -> Result<Lock<'_>, ConsulError>
pub async fn get_lock( &self, request: LockRequest<'_>, value: &[u8], ) -> Result<Lock<'_>, ConsulError>
Obtains a lock against a specific key in consul. See the consul docs for more information.
§Arguments:
- request - the LockRequest
§Errors:
ConsulError describes all possible errors returned by this api.
Sourcepub async fn watch_lock(
&self,
request: LockWatchRequest<'_>,
) -> Result<ResponseMeta<Vec<ReadKeyResponse>>, ConsulError>
pub async fn watch_lock( &self, request: LockWatchRequest<'_>, ) -> Result<ResponseMeta<Vec<ReadKeyResponse>>, ConsulError>
Watches lock against a specific key in consul. See the consul docs for more information.
§Arguments:
- request - the LockWatchRequest
§Errors:
ConsulError describes all possible errors returned by this api.
Source§impl Consul
impl Consul
Sourcepub async fn get_acl_tokens(&self) -> Result<Vec<ACLToken>, ConsulError>
pub async fn get_acl_tokens(&self) -> Result<Vec<ACLToken>, ConsulError>
Returns all ACL tokens.
Fetches the list of ACL tokens from Consul’s /v1/acl/tokens
endpoint.
Users can use these tokens to manage access control for Consul resources.
See the Consul API docs for more information.
§Arguments:
&self
– theConsul
client instance.
§Errors:
ConsulError::ResponseDeserializationFailed
if the response JSON can’t be parsed.
Sourcepub async fn get_acl_policies(&self) -> Result<Vec<ACLPolicy>, ConsulError>
pub async fn get_acl_policies(&self) -> Result<Vec<ACLPolicy>, ConsulError>
Returns all ACL policies.
Retrieves the list of ACL policies defined in Consul via the /v1/acl/policies
endpoint.
ACL policies define sets of rules for tokens to grant or restrict permissions.
See the Consul API docs for more information.
§Arguments:
&self
– theConsul
client instance.
§Errors:
ConsulError::ResponseDeserializationFailed
if the response JSON can’t be parsed.
Sourcepub async fn delete_acl_policy(&self, id: String) -> Result<(), ConsulError>
pub async fn delete_acl_policy(&self, id: String) -> Result<(), ConsulError>
Delete an acl policy.
Sends a DELETE
to /v1/acl/policy/:id
to delete an ACL policy in Consul.
§Arguments:
&self
– theConsul
client instance.id
– the policy ID.
§Errors:
ConsulError::InvalidRequest
if the payload fails to serialize.ConsulError::ResponseDeserializationFailed
if the Consul response can’t be parsed.
Sourcepub async fn create_acl_policy(
&self,
payload: &CreateACLPolicyRequest,
) -> Result<ACLPolicy, ConsulError>
pub async fn create_acl_policy( &self, payload: &CreateACLPolicyRequest, ) -> Result<ACLPolicy, ConsulError>
Creates a new ACL policy.
Sends a PUT
to /v1/acl/policy
to define a new ACL policy in Consul.
ACL policies consist of rules that can be attached to tokens to control access.
See the Consul API docs for more information.
§Arguments:
&self
– theConsul
client instance.payload
– theCreateACLPolicyRequest
payload.
§Errors:
ConsulError::InvalidRequest
if the payload fails to serialize.ConsulError::ResponseDeserializationFailed
if the Consul response can’t be parsed.
Sourcepub async fn create_acl_token(
&self,
payload: &CreateACLTokenPayload,
) -> Result<ACLToken, ConsulError>
pub async fn create_acl_token( &self, payload: &CreateACLTokenPayload, ) -> Result<ACLToken, ConsulError>
Creates a new ACL token.
Sends a PUT
to /v1/acl/token
to generate a new token which can be attached to ACL policies.
Tokens grant the permissions defined by their associated policies.
See the Consul API docs for more information.
§Arguments:
&self
– theConsul
client instance.payload
– theCreateACLTokenPayload
payload.
§Errors:
ConsulError::InvalidRequest
if the payload fails to serialize.ConsulError::ResponseDeserializationFailed
if the response JSON can’t be parsed.
Sourcepub async fn read_acl_token(
&self,
accessor_id: String,
) -> Result<ACLToken, ConsulError>
pub async fn read_acl_token( &self, accessor_id: String, ) -> Result<ACLToken, ConsulError>
Reads an ACL token.
Fetches a single ACL token by its ID using the /v1/acl/token/{token}
endpoint.
Useful for inspecting the token’s properties and associated policies.
See the Consul API docs for more information.
§Arguments:
&self
– theConsul
client instance.accessor_id
– the accessor_id to read.
§Errors:
ConsulError::ResponseDeserializationFailed
if the response JSON can’t be parsed.
Sourcepub async fn delete_acl_token(&self, token: String) -> Result<(), ConsulError>
pub async fn delete_acl_token(&self, token: String) -> Result<(), ConsulError>
Deletes an ACL token.
Sends a DELETE
to /v1/acl/token/{token}
to remove the specified ACL token.
Returns false
if deletion failed, in which case this method returns an error.
See the Consul API docs for more information.
§Arguments:
&self
– theConsul
client instance.token
– the token ID to delete.
§Errors:
ConsulError::ResponseDeserializationFailed
if the response JSON can’t be parsed.ConsulError::TokenDeleteFailed
if Consul indicates deletion did not succeed.
Source§impl Consul
impl Consul
Sourcepub fn new_with_client(config: Config, https_client: HttpsClient) -> Self
pub fn new_with_client(config: Config, https_client: HttpsClient) -> Self
Creates a new instance of Consul
using the supplied HTTPS client.
This is the entry point for this crate.
#Arguments:
Sourcepub async fn read_key(
&self,
request: ReadKeyRequest<'_>,
) -> Result<ResponseMeta<Vec<ReadKeyResponse>>, ConsulError>
pub async fn read_key( &self, request: ReadKeyRequest<'_>, ) -> Result<ResponseMeta<Vec<ReadKeyResponse>>, ConsulError>
Reads a key from Consul’s KV store. See the consul docs for more information.
§Arguments:
- request - the ReadKeyRequest
§Errors:
ConsulError describes all possible errors returned by this api.
Sourcepub async fn create_or_update_key(
&self,
request: CreateOrUpdateKeyRequest<'_>,
value: Vec<u8>,
) -> Result<(bool, u64), ConsulError>
pub async fn create_or_update_key( &self, request: CreateOrUpdateKeyRequest<'_>, value: Vec<u8>, ) -> Result<(bool, u64), ConsulError>
Creates or updates a key in Consul’s KV store. See the consul docs for more information.
§Arguments:
- request - the CreateOrUpdateKeyRequest
- value - the data to store as Bytes
§Returns:
A tuple of a boolean and a 64 bit unsigned integer representing whether the operation was successful and the index for a subsequent blocking query.
§Errors:
ConsulError describes all possible errors returned by this api.
Sourcepub fn create_or_update_key_sync(
&self,
request: CreateOrUpdateKeyRequest<'_>,
value: Vec<u8>,
) -> Result<bool, ConsulError>
pub fn create_or_update_key_sync( &self, request: CreateOrUpdateKeyRequest<'_>, value: Vec<u8>, ) -> Result<bool, ConsulError>
Creates or updates a key in Consul’s KV store. See the consul docs for more information. This is the synchronous version of create_or_update_key
§Arguments:
- request - the CreateOrUpdateKeyRequest
- value - the data to store as Bytes
§Returns:
A tuple of a boolean and a 64 bit unsigned integer representing whether the operation was successful and the index for a subsequent blocking query.
§Errors:
ConsulError describes all possible errors returned by this api.
Sourcepub async fn delete_key(
&self,
request: DeleteKeyRequest<'_>,
) -> Result<bool, ConsulError>
pub async fn delete_key( &self, request: DeleteKeyRequest<'_>, ) -> Result<bool, ConsulError>
Deletes a key from Consul’s KV store. See the consul docs for more information.
§Arguments:
- request - the DeleteKeyRequest
§Errors:
ConsulError describes all possible errors returned by this api.
Sourcepub async fn register_entity(
&self,
payload: &RegisterEntityPayload,
) -> Result<(), ConsulError>
pub async fn register_entity( &self, payload: &RegisterEntityPayload, ) -> Result<(), ConsulError>
Registers or updates entries in consul’s global catalog. See https://www.consul.io/api-docs/catalog#register-entity for more information.
§Arguments:
- payload: The
RegisterEntityPayload
to provide the register entity API.
§Errors:
ConsulError describes all possible errors returned by this api.
Sourcepub async fn deregister_entity(
&self,
payload: &DeregisterEntityPayload,
) -> Result<(), ConsulError>
pub async fn deregister_entity( &self, payload: &DeregisterEntityPayload, ) -> Result<(), ConsulError>
Removes entries from consul’s global catalog. See https://www.consul.io/api-docs/catalog#deregister-entity for more information.
§Arguments:
- payload: The
DeregisterEntityPayload
to provide the register entity API.
§Errors:
ConsulError describes all possible errors returned by this api.
Sourcepub async fn get_all_registered_service_names(
&self,
query_opts: Option<QueryOptions>,
) -> Result<ResponseMeta<Vec<String>>, ConsulError>
pub async fn get_all_registered_service_names( &self, query_opts: Option<QueryOptions>, ) -> Result<ResponseMeta<Vec<String>>, ConsulError>
Returns all services currently registered with consul. See https://www.consul.io/api-docs/catalog#list-services for more information.
§Arguments:
- query_opts: The
QueryOptions
to apply for this endpoint.
§Errors:
ConsulError describes all possible errors returned by this api.
Sourcepub async fn get_service_nodes(
&self,
request: GetServiceNodesRequest<'_>,
query_opts: Option<QueryOptions>,
) -> Result<ResponseMeta<Vec<ServiceNode>>, ConsulError>
pub async fn get_service_nodes( &self, request: GetServiceNodesRequest<'_>, query_opts: Option<QueryOptions>, ) -> Result<ResponseMeta<Vec<ServiceNode>>, ConsulError>
returns the nodes providing the service indicated on the path. Users can also build in support for dynamic load balancing and other features by incorporating the use of health checks. See the consul docs for more information.
§Arguments:
- request - the GetServiceNodesRequest
§Errors:
ConsulError describes all possible errors returned by this api.
Sourcepub async fn get_service_addresses_and_ports(
&self,
service_name: &str,
query_opts: Option<QueryOptions>,
) -> Result<Vec<(String, u16)>, ConsulError>
pub async fn get_service_addresses_and_ports( &self, service_name: &str, query_opts: Option<QueryOptions>, ) -> Result<Vec<(String, u16)>, ConsulError>
Queries consul for a service and returns the Address:Port of all instances registered for that service.
Sourcepub async fn get_nodes(
&self,
request: GetNodesRequest<'_>,
query_opts: Option<QueryOptions>,
) -> Result<ResponseMeta<Vec<CatalogNode>>, ConsulError>
pub async fn get_nodes( &self, request: GetNodesRequest<'_>, query_opts: Option<QueryOptions>, ) -> Result<ResponseMeta<Vec<CatalogNode>>, ConsulError>
Returns the nodes registered in the Consul catalog.
§Arguments:
- request - the GetNodesRequest
§Errors:
ConsulError describes all possible errors returned by this api.