tailscale.rs
A modern, minimal Rust client for the Tailscale v2 API. This library provides simple methods to authenticate with Tailscale, retrieve user and Tailnet info, and create auth keys.
Installation
Add this crate to your Cargo.toml:
[dependencies]
tailscale-client = "0.1.2"
Usage
Below is a quick example that calls the whoami endpoint:
use tailscale_client::TailscaleClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = TailscaleClient::new("tskey-api-XXXXXX".to_string());
let whoami_response = client.whoami().await?;
println!("WhoAmI Response: {:?}", whoami_response);
Ok(())
}
Create an auth key:
use std::error::Error;
use tailscale_client::{TailscaleClient, KeyCapabilities};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let api_key = "tskey-api-XXXXXX".to_string();
let tailnet = "example.com".to_string();
let client = TailscaleClient::new(api_key);
let capabilities = KeyCapabilities {
ephemeral: Some(true), reusable: Some(false), preauthorized: Some(false), };
let new_key = client.create_auth_key(&tailnet, capabilities).await?;
println!("Successfully created auth key: {:?}", new_key);
Ok(())
}
Features
- Easy construction of a Tailscale API client.
- Simple helpers for common operations (e.g. /whoami).
- Create auth keys with flexible capabilities.
Contributing
Contributions are welcome! Please open an issue or pull request.
Developing
make build_test_image
make test
License
Licensed under the terms of the Apache License 2.0.