]> git.proxmox.com Git - proxmox-offline-mirror.git/commitdiff
improve interfaces and descriptions
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 8 Jul 2022 12:53:42 +0000 (14:53 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Tue, 6 Sep 2022 10:06:13 +0000 (12:06 +0200)
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
src/bin/proxmox-offline-mirror.rs
src/bin/proxmox_offline_mirror_cmds/config.rs
src/bin/proxmox_offline_mirror_cmds/medium.rs
src/bin/proxmox_offline_mirror_cmds/mirror.rs
src/bin/proxmox_offline_mirror_cmds/subscription.rs
src/config.rs
src/types.rs

index 11f22b3ee179d20e006cf8fa25fd6ca6810cf94d..fc24e57595f4d4aeb7998251d4c6a04a7073dd8f 100644 (file)
@@ -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)?;
         }
index 9cc29afb5b0338009169a5cdd14be266bb1b75a6..57aa5fe2325734abd324c165656388dffc684acc 100644 (file)
@@ -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,
index 4cd0e4df0f684cc1b2dd58e7d6bb3bdcf57f5c64..06b00f54447f70c8260c8bb6871d47859cd0bc49 100644 (file)
@@ -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()
 }
index 888db7550d53c07a31621eb80c783e13ff3c19ad..6b4da0d38c6d2ae68eb39fefbb5a95f75c56d2a6 100644 (file)
@@ -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()
 }
index fe14dd06b9e7066aa6f9e4761452e7b7331cad3a..9d638f47b24bc0665709b2425894fcc04f124d31 100644 (file)
@@ -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()
 }
index 3d3a6c83f174124a88942e7eabe853337cd14ab3..42705a802c213321a8949429ac656180820ff237 100644 (file)
@@ -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,
index cf15c0b34768561e5f9d822e57e3baa9dac0a0a4..7a1348ac6c4fa46420e313aafd23bfafbad102f2 100644 (file)
@@ -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]-).*" }; }