2021-09-02 15:36:13 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
use super::*;
|
2021-10-08 09:19:37 +00:00
|
|
|
use proxmox_schema::*;
|
2021-09-02 15:36:13 +00:00
|
|
|
|
2022-04-10 15:53:42 +00:00
|
|
|
pub const REMOTE_PASSWORD_SCHEMA: Schema =
|
|
|
|
StringSchema::new("Password or auth token for remote host.")
|
|
|
|
.format(&PASSWORD_FORMAT)
|
|
|
|
.min_length(1)
|
|
|
|
.max_length(1024)
|
|
|
|
.schema();
|
2021-09-02 15:36:13 +00:00
|
|
|
|
2022-04-10 15:53:42 +00:00
|
|
|
pub const REMOTE_PASSWORD_BASE64_SCHEMA: Schema =
|
|
|
|
StringSchema::new("Password or auth token for remote host (stored as base64 string).")
|
|
|
|
.format(&PASSWORD_FORMAT)
|
|
|
|
.min_length(1)
|
|
|
|
.max_length(1024)
|
|
|
|
.schema();
|
2021-09-02 15:36:13 +00:00
|
|
|
|
|
|
|
pub const REMOTE_ID_SCHEMA: Schema = StringSchema::new("Remote ID.")
|
|
|
|
.format(&PROXMOX_SAFE_ID_FORMAT)
|
|
|
|
.min_length(3)
|
|
|
|
.max_length(32)
|
|
|
|
.schema();
|
|
|
|
|
|
|
|
#[api(
|
|
|
|
properties: {
|
|
|
|
comment: {
|
|
|
|
optional: true,
|
|
|
|
schema: SINGLE_LINE_COMMENT_SCHEMA,
|
|
|
|
},
|
|
|
|
host: {
|
|
|
|
schema: DNS_NAME_OR_IP_SCHEMA,
|
|
|
|
},
|
|
|
|
port: {
|
|
|
|
optional: true,
|
|
|
|
description: "The (optional) port",
|
|
|
|
type: u16,
|
|
|
|
},
|
|
|
|
"auth-id": {
|
|
|
|
type: Authid,
|
|
|
|
},
|
|
|
|
fingerprint: {
|
|
|
|
optional: true,
|
|
|
|
schema: CERT_FINGERPRINT_SHA256_SCHEMA,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
2022-04-10 15:53:42 +00:00
|
|
|
#[derive(Serialize, Deserialize, Updater)]
|
2021-09-02 15:36:13 +00:00
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
/// Remote configuration properties.
|
|
|
|
pub struct RemoteConfig {
|
2022-04-10 15:53:42 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2021-09-02 15:36:13 +00:00
|
|
|
pub comment: Option<String>,
|
|
|
|
pub host: String,
|
2022-04-10 15:53:42 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2021-09-02 15:36:13 +00:00
|
|
|
pub port: Option<u16>,
|
|
|
|
pub auth_id: Authid,
|
2022-04-10 15:53:42 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2021-09-02 15:36:13 +00:00
|
|
|
pub fingerprint: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[api(
|
|
|
|
properties: {
|
|
|
|
name: {
|
|
|
|
schema: REMOTE_ID_SCHEMA,
|
|
|
|
},
|
|
|
|
config: {
|
|
|
|
type: RemoteConfig,
|
|
|
|
},
|
|
|
|
password: {
|
|
|
|
schema: REMOTE_PASSWORD_BASE64_SCHEMA,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
2022-04-10 15:53:42 +00:00
|
|
|
#[derive(Serialize, Deserialize)]
|
2021-09-02 15:36:13 +00:00
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
/// Remote properties.
|
|
|
|
pub struct Remote {
|
|
|
|
pub name: String,
|
|
|
|
// Note: The stored password is base64 encoded
|
2022-04-10 15:53:42 +00:00
|
|
|
#[serde(skip_serializing_if = "String::is_empty")]
|
2021-11-23 16:57:00 +00:00
|
|
|
#[serde(with = "proxmox_serde::string_as_base64")]
|
2021-09-02 15:36:13 +00:00
|
|
|
pub password: String,
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub config: RemoteConfig,
|
|
|
|
}
|
2022-04-20 07:40:05 +00:00
|
|
|
|
|
|
|
#[api(
|
|
|
|
properties: {
|
|
|
|
name: {
|
|
|
|
schema: REMOTE_ID_SCHEMA,
|
|
|
|
},
|
|
|
|
config: {
|
|
|
|
type: RemoteConfig,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
/// Remote properties.
|
|
|
|
pub struct RemoteWithoutPassword {
|
|
|
|
pub name: String,
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub config: RemoteConfig,
|
|
|
|
}
|