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
impl TailscaleClient
Sourcepub fn new(token: String) -> Self
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
Sourcepub async fn whoami(&self) -> Result<WhoAmIResponse>
pub async fn whoami(&self) -> Result<WhoAmIResponse>
Example method to call the /whoami
endpoint which returns information
about the current user and their Tailnets.
Sourcepub async fn create_auth_key(
&self,
tailnet: &str,
all: bool,
req_body: &CreateAuthKeyRequest,
) -> Result<CreateAuthKeyResponse>
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
).
Sourcepub async fn list_devices(
&self,
tailnet: &str,
fields: Option<&str>,
) -> Result<ListDevicesResponse>
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.
Sourcepub async fn find_device_by_name(
&self,
tailnet: &str,
name: &str,
fields: Option<&str>,
) -> Result<Option<TailnetDevice>>
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.
Sourcepub async fn delete_device(
&self,
device_id: &str,
fields: Option<&str>,
) -> Result<Option<TailnetDevice>>
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 thenodeId
or the numericid
.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.
Sourcepub async fn remove_device_by_name(
&self,
tailnet: &str,
name: &str,
fields: Option<&str>,
) -> Result<Option<TailnetDevice>>
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 ifNone
.
§Returns
Ok(Some(TailnetDevice))
if the device was found and successfully deleted.Ok(None)
if the device was not found.- An error otherwise.
Sourcepub 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>>
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§
impl Freeze for TailscaleClient
impl !RefUnwindSafe for TailscaleClient
impl Send for TailscaleClient
impl Sync for TailscaleClient
impl Unpin for TailscaleClient
impl !UnwindSafe for TailscaleClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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