Generate Auth Keys
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.
This commit is contained in:
91
src/types.rs
91
src/types.rs
@@ -1,4 +1,95 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user