mirror of
https://git.proxmox.com/git/proxmox-offline-mirror
synced 2025-08-05 19:56:48 +00:00
improve interfaces and descriptions
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
a9f22be14c
commit
b42cad3b8e
@ -15,7 +15,7 @@ use proxmox_offline_mirror::helpers::tty::{
|
||||
use proxmox_offline_mirror::{
|
||||
config::{save_config, MediaConfig, MirrorConfig},
|
||||
mirror,
|
||||
types::{ProductType, MIRROR_ID_SCHEMA},
|
||||
types::{ProductType, MEDIA_ID_SCHEMA, MIRROR_ID_SCHEMA},
|
||||
};
|
||||
|
||||
mod proxmox_offline_mirror_cmds;
|
||||
@ -463,7 +463,7 @@ fn action_add_medium(config: &SectionConfigData) -> Result<MediaConfig, Error> {
|
||||
|
||||
let id = loop {
|
||||
let mut id = read_string_from_tty("Enter medium ID", None)?;
|
||||
while let Err(err) = MIRROR_ID_SCHEMA.parse_simple_value(&id) {
|
||||
while let Err(err) = MEDIA_ID_SCHEMA.parse_simple_value(&id) {
|
||||
eprintln!("Not a valid medium ID: {err}");
|
||||
id = read_string_from_tty("Enter medium ID", None)?;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use proxmox_schema::{api, param_bail, ApiType, ArraySchema, ReturnType};
|
||||
use proxmox_offline_mirror::{
|
||||
config::{MediaConfig, MediaConfigUpdater, MirrorConfig, MirrorConfigUpdater},
|
||||
mirror,
|
||||
types::MIRROR_ID_SCHEMA,
|
||||
types::{MEDIA_ID_SCHEMA, MIRROR_ID_SCHEMA},
|
||||
};
|
||||
|
||||
pub const DEFAULT_CONFIG_PATH: &str = "/etc/proxmox-apt-mirror.cfg";
|
||||
@ -313,7 +313,7 @@ async fn list_media(config: Option<String>, param: Value) -> Result<Value, Error
|
||||
description: "Path to mirroring config file.",
|
||||
},
|
||||
id: {
|
||||
schema: MIRROR_ID_SCHEMA,
|
||||
schema: MEDIA_ID_SCHEMA,
|
||||
},
|
||||
"output-format": {
|
||||
schema: OUTPUT_FORMAT,
|
||||
@ -392,7 +392,7 @@ async fn add_medium(
|
||||
description: "Path to mirroring config file.",
|
||||
},
|
||||
id: {
|
||||
schema: MIRROR_ID_SCHEMA,
|
||||
schema: MEDIA_ID_SCHEMA,
|
||||
},
|
||||
"remove-data": {
|
||||
type: bool,
|
||||
@ -444,7 +444,7 @@ async fn remove_medium(
|
||||
description: "Path to mirroring config file.",
|
||||
},
|
||||
id: {
|
||||
schema: MIRROR_ID_SCHEMA,
|
||||
schema: MEDIA_ID_SCHEMA,
|
||||
},
|
||||
update: {
|
||||
type: MediaConfigUpdater,
|
||||
|
@ -14,7 +14,7 @@ use proxmox_offline_mirror::{
|
||||
generate_repo_file_line,
|
||||
medium::{self},
|
||||
mirror,
|
||||
types::{ProductType, Snapshot, MIRROR_ID_SCHEMA},
|
||||
types::{ProductType, Snapshot, MEDIA_ID_SCHEMA},
|
||||
};
|
||||
|
||||
use super::DEFAULT_CONFIG_PATH;
|
||||
@ -28,7 +28,7 @@ use super::DEFAULT_CONFIG_PATH;
|
||||
description: "Path to mirroring config file.",
|
||||
},
|
||||
id: {
|
||||
schema: MIRROR_ID_SCHEMA,
|
||||
schema: MEDIA_ID_SCHEMA,
|
||||
},
|
||||
"output-format": {
|
||||
schema: OUTPUT_FORMAT,
|
||||
@ -62,7 +62,7 @@ async fn garbage_collect(
|
||||
description: "Path to mirroring config file.",
|
||||
},
|
||||
id: {
|
||||
schema: MIRROR_ID_SCHEMA,
|
||||
schema: MEDIA_ID_SCHEMA,
|
||||
},
|
||||
"output-format": {
|
||||
schema: OUTPUT_FORMAT,
|
||||
@ -180,7 +180,7 @@ fn get_subscription_keys(
|
||||
description: "Path to mirroring config file.",
|
||||
},
|
||||
id: {
|
||||
schema: MIRROR_ID_SCHEMA,
|
||||
schema: MEDIA_ID_SCHEMA,
|
||||
},
|
||||
"keys-only": {
|
||||
type: bool,
|
||||
@ -222,9 +222,15 @@ async fn sync(
|
||||
|
||||
pub fn medium_commands() -> CommandLineInterface {
|
||||
let cmd_def = CliCommandMap::new()
|
||||
.insert("gc", CliCommand::new(&API_METHOD_GARBAGE_COLLECT))
|
||||
.insert("status", CliCommand::new(&API_METHOD_STATUS))
|
||||
.insert("sync", CliCommand::new(&API_METHOD_SYNC));
|
||||
.insert(
|
||||
"gc",
|
||||
CliCommand::new(&API_METHOD_GARBAGE_COLLECT).arg_param(&["id"]),
|
||||
)
|
||||
.insert(
|
||||
"status",
|
||||
CliCommand::new(&API_METHOD_STATUS).arg_param(&["id"]),
|
||||
)
|
||||
.insert("sync", CliCommand::new(&API_METHOD_SYNC).arg_param(&["id"]));
|
||||
|
||||
cmd_def.into()
|
||||
}
|
||||
|
@ -177,13 +177,25 @@ async fn garbage_collect(config: Option<String>, id: String, _param: Value) -> R
|
||||
}
|
||||
pub fn mirror_commands() -> CommandLineInterface {
|
||||
let snapshot_cmds = CliCommandMap::new()
|
||||
.insert("create", CliCommand::new(&API_METHOD_CREATE_SNAPSHOT))
|
||||
.insert("list", CliCommand::new(&API_METHOD_LIST_SNAPSHOTS))
|
||||
.insert("remove", CliCommand::new(&API_METHOD_REMOVE_SNAPSHOT));
|
||||
.insert(
|
||||
"create",
|
||||
CliCommand::new(&API_METHOD_CREATE_SNAPSHOT).arg_param(&["id"]),
|
||||
)
|
||||
.insert(
|
||||
"list",
|
||||
CliCommand::new(&API_METHOD_LIST_SNAPSHOTS).arg_param(&["id"]),
|
||||
)
|
||||
.insert(
|
||||
"remove",
|
||||
CliCommand::new(&API_METHOD_REMOVE_SNAPSHOT).arg_param(&["id", "snapshot"]),
|
||||
);
|
||||
|
||||
let cmd_def = CliCommandMap::new()
|
||||
.insert("snapshot", snapshot_cmds)
|
||||
.insert("gc", CliCommand::new(&API_METHOD_GARBAGE_COLLECT));
|
||||
.insert(
|
||||
"gc",
|
||||
CliCommand::new(&API_METHOD_GARBAGE_COLLECT).arg_param(&["id"]),
|
||||
);
|
||||
|
||||
cmd_def.into()
|
||||
}
|
||||
|
@ -348,14 +348,23 @@ async fn remove_key(config: Option<String>, key: String, _param: Value) -> Resul
|
||||
|
||||
pub fn key_commands() -> CommandLineInterface {
|
||||
CliCommandMap::new()
|
||||
.insert("add", CliCommand::new(&API_METHOD_ADD_KEY))
|
||||
.insert(
|
||||
"add",
|
||||
CliCommand::new(&API_METHOD_ADD_KEY).arg_param(&["key", "server-id"]),
|
||||
)
|
||||
.insert(
|
||||
"add-mirror-key",
|
||||
CliCommand::new(&API_METHOD_ADD_MIRROR_KEY),
|
||||
CliCommand::new(&API_METHOD_ADD_MIRROR_KEY).arg_param(&["key"]),
|
||||
)
|
||||
.insert(
|
||||
"update",
|
||||
CliCommand::new(&API_METHOD_UPDATE_KEY).arg_param(&["key"]),
|
||||
)
|
||||
.insert("update", CliCommand::new(&API_METHOD_UPDATE_KEY))
|
||||
.insert("refresh", CliCommand::new(&API_METHOD_REFRESH_KEYS))
|
||||
.insert("remove", CliCommand::new(&API_METHOD_REMOVE_KEY))
|
||||
.insert(
|
||||
"remove",
|
||||
CliCommand::new(&API_METHOD_REMOVE_KEY).arg_param(&["key"]),
|
||||
)
|
||||
.insert("list", CliCommand::new(&API_METHOD_LIST_KEYS))
|
||||
.into()
|
||||
}
|
||||
|
@ -10,7 +10,8 @@ use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlug
|
||||
use proxmox_sys::fs::{replace_file, CreateOptions};
|
||||
|
||||
use crate::types::{
|
||||
ProductType, MIRROR_ID_SCHEMA, PROXMOX_SERVER_ID_SCHEMA, PROXMOX_SUBSCRIPTION_KEY_SCHEMA,
|
||||
ProductType, MEDIA_ID_SCHEMA, MIRROR_ID_SCHEMA, PROXMOX_SERVER_ID_SCHEMA,
|
||||
PROXMOX_SUBSCRIPTION_KEY_SCHEMA,
|
||||
};
|
||||
|
||||
#[api(
|
||||
@ -69,7 +70,7 @@ pub struct MirrorConfig {
|
||||
#[api(
|
||||
properties: {
|
||||
id: {
|
||||
schema: MIRROR_ID_SCHEMA,
|
||||
schema: MEDIA_ID_SCHEMA,
|
||||
},
|
||||
mountpoint: {
|
||||
type: String,
|
||||
|
@ -26,6 +26,13 @@ pub const MIRROR_ID_SCHEMA: Schema = StringSchema::new("Mirror name.")
|
||||
.max_length(32)
|
||||
.schema();
|
||||
|
||||
/// Schema for config IDs
|
||||
pub const MEDIA_ID_SCHEMA: Schema = StringSchema::new("Medium name.")
|
||||
.format(&PROXMOX_SAFE_ID_FORMAT)
|
||||
.min_length(3)
|
||||
.max_length(32)
|
||||
.schema();
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[macro_export]
|
||||
macro_rules! PROXMOX_SUBSCRIPTION_KEY_REGEX_STR { () => { r"(?:pom-|pve\d+[a-z]-|pbs[a-z]-|pmg[a-z]-).*" }; }
|
||||
|
Loading…
Reference in New Issue
Block a user