Struct TailscaleClient

Source
pub struct TailscaleClient {
    pub base_url: String,
    pub token: String,
    /* private fields */
}
Expand description

A client for interacting with Tailscale’s v2 API.

Fields§

§base_url: String§token: String

Implementations§

Source§

impl TailscaleClient

Source

pub fn new(token: String) -> Self

Creates a new TailscaleClient with the given token, automatically setting the base URL to https://api.tailscale.com/api/v2

Source

pub async fn whoami(&self) -> Result<WhoAmIResponse>

Example method to call the /whoami endpoint which returns information about the current user and their Tailnets.

Source

pub async fn create_auth_key( &self, tailnet: &str, all: bool, req_body: &CreateAuthKeyRequest, ) -> Result<CreateAuthKeyResponse>

Creates a new auth key in the specified tailnet, returning the newly generated key. The all parameter is optional in the API, but here we surface it directly to match the Tailscale docs example (e.g., ?all=true).

Source

pub async fn list_devices( &self, tailnet: &str, fields: Option<&str>, ) -> Result<ListDevicesResponse>

Lists the devices in a tailnet.

The fields parameter can be “all” to return all device fields, or “default” to only get limited fields (addresses, id, nodeId, user, name, hostname, etc). If fields is None, then no query parameter is applied, and the default fields set is returned.

For details, see https://tailscale.com/kb/api#list-tailnet-devices.

Source

pub async fn find_device_by_name( &self, tailnet: &str, name: &str, fields: Option<&str>, ) -> Result<Option<TailnetDevice>>

Finds a single device by name in the specified tailnet using the list_devices() call. Returns Ok(Some(device)) if found, Ok(None) if not found, or an error otherwise.

You may pass fields as Some("all") to request all fields, or None (the default) to request the limited set. See list_devices() for more details.

Source

pub async fn delete_device( &self, device_id: &str, fields: Option<&str>, ) -> Result<Option<TailnetDevice>>

Deletes the specified device from the tailnet. The device must belong to the requesting user’s tailnet. Deleting devices shared with the tailnet is not supported.

§Arguments
  • device_id - The ID of the device to delete. This can be either the nodeId or the numeric id.
  • fields - If provided, appends ?fields=default or ?fields=all to the request. Defaults to the limited fields if omitted.
§Returns
  • Ok(TailnetDevice) if the deletion is successful (Tailscale returns the deleted device object in the response).
  • An error otherwise.
Source

pub async fn remove_device_by_name( &self, tailnet: &str, name: &str, fields: Option<&str>, ) -> Result<Option<TailnetDevice>>

Removes a device by its first name component if it exists on the specified tailnet. Returns an Ok(Some(TailnetDevice)) containing the deleted device if it was found and removed, or Ok(None) if the device was not found. If Tailscale returns an error, an Err(…) is returned.

§Arguments
  • tailnet - The name of the tailnet.
  • name - The device’s first name component. For example, passing “my-dev” will match device names like “my-dev.example.com”.
  • fields - If provided, e.g. “all”, returns more fields in the device object from the Tailscale API. Defaults to limited fields if None.
§Returns
  • Ok(Some(TailnetDevice)) if the device was found and successfully deleted.
  • Ok(None) if the device was not found.
  • An error otherwise.
Source

pub async fn wait_for_device_by_name( &self, tailnet: &str, device_name: &str, fields: Option<&str>, max_retries: u32, delay_secs: u64, ) -> Result<Option<TailnetDevice>>

Waits for a device to appear in the specified tailnet, matching by its first name component. Polls find_device_by_name up to max_retries times, sleeping delay_secs each time before giving up. Returns Ok(Some(TailnetDevice)) if found, or Ok(None) if not found.

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoResult<T> for T

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

impl<T> ErasedDestructor for T
where T: 'static,