Consul

Struct Consul 

Source
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

Source

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:
§Errors:

ConsulError describes all possible errors returned by this api.

Source

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:
§Errors:

ConsulError describes all possible errors returned by this api.

Source§

impl Consul

Source

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 – the Consul client instance.
§Errors:
Source

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 – the Consul client instance.
§Errors:
Source

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 – the Consul client instance.
  • id – the policy ID.
§Errors:
Source

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:
§Errors:
Source

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:
§Errors:
Source

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 – the Consul client instance.
  • accessor_id – the accessor_id to read.
§Errors:
Source

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 – the Consul client instance.
  • token – the token ID to delete.
§Errors:
Source§

impl Consul

Source

pub fn new(config: Config) -> Self

Creates a new instance of Consul. This is the entry point for this crate. #Arguments:

Source

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:

Source

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:
§Errors:

ConsulError describes all possible errors returned by this api.

Source

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:
§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.

Source

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:
§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.

Source

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:
§Errors:

ConsulError describes all possible errors returned by this api.

Source

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:
§Errors:

ConsulError describes all possible errors returned by this api.

Source

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:
§Errors:

ConsulError describes all possible errors returned by this api.

Source

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:
§Errors:

ConsulError describes all possible errors returned by this api.

Source

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:
§Errors:

ConsulError describes all possible errors returned by this api.

Source

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.

Source

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:
§Errors:

ConsulError describes all possible errors returned by this api.

Trait Implementations§

Source§

impl Debug for Consul

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Consul

§

impl !RefUnwindSafe for Consul

§

impl Send for Consul

§

impl Sync for Consul

§

impl Unpin for Consul

§

impl !UnwindSafe for Consul

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more