Added the ability to generate new auth keys. Can see in the tailscale logs that new keys are being generated with a 90 day expiration time. This should be enough to close out issue #7.
96 lines
2.1 KiB
Rust
96 lines
2.1 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
pub struct ClientAuth {
|
|
pub id: String,
|
|
pub secret: String,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
pub struct AuthKeyRequest {
|
|
capabilities: CapabilitiesCreate,
|
|
expiry_seconds: i32,
|
|
description: String,
|
|
}
|
|
|
|
impl AuthKeyRequest {
|
|
pub fn new() -> Self {
|
|
let create_options = CreateOptions {
|
|
reusable: false,
|
|
ephemeral: false,
|
|
preauthorized: false,
|
|
tags: Vec::new(),
|
|
};
|
|
|
|
let devices_create = DevicesCreate {
|
|
create: create_options,
|
|
};
|
|
|
|
let capabilities_create = CapabilitiesCreate {
|
|
devices: devices_create,
|
|
};
|
|
|
|
Self {
|
|
capabilities: capabilities_create,
|
|
expiry_seconds: 3600,
|
|
description: String::new(),
|
|
}
|
|
}
|
|
|
|
pub fn is_reusable(&mut self, reusable: bool) {
|
|
self.capabilities.devices.create.reusable = reusable;
|
|
}
|
|
|
|
pub fn is_ephemeral(&mut self, ephemeral: bool) {
|
|
self.capabilities.devices.create.ephemeral = ephemeral;
|
|
}
|
|
|
|
pub fn is_preauthorized(&mut self, preauthorized: bool) {
|
|
self.capabilities.devices.create.preauthorized = preauthorized;
|
|
}
|
|
|
|
pub fn expiry_seconds(&mut self, expiry_seconds: i32) {
|
|
self.expiry_seconds = expiry_seconds;
|
|
}
|
|
|
|
pub fn description(&mut self, description: String) {
|
|
self.description = description;
|
|
}
|
|
|
|
pub fn set_tags(&mut self, tags: Vec<String>) {
|
|
self.capabilities.devices.create.tags = tags;
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
pub struct CapabilitiesCreate {
|
|
devices: DevicesCreate,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
struct DevicesCreate {
|
|
create: CreateOptions,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
struct CreateOptions {
|
|
reusable: bool,
|
|
ephemeral: bool,
|
|
preauthorized: bool,
|
|
tags: Vec<String>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
pub struct AuthKeyResponse {
|
|
id: String,
|
|
key: String,
|
|
created: String,
|
|
expires: String,
|
|
capabilities: CapabilitiesCreate,
|
|
}
|
|
|
|
impl AuthKeyResponse {
|
|
pub fn get_auth_key(self) -> String {
|
|
self.key
|
|
}
|
|
}
|