From 60643023ad18c6687f7c12e57678df7d592650d7 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 10 May 2021 14:39:05 +0200 Subject: [PATCH] api: move AcmeChallengeSchema to acme types module It will be reused in a later patch in another module which should not depend on the actual API implementation (ugly and cyclic) Signed-off-by: Thomas Lamprecht --- src/api2/config/acme.rs | 37 ++++--------------------------------- src/api2/types/acme.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/api2/config/acme.rs b/src/api2/config/acme.rs index e0ad0a16..22a29293 100644 --- a/src/api2/config/acme.rs +++ b/src/api2/config/acme.rs @@ -14,7 +14,7 @@ use proxmox_acme_rs::account::AccountData as AcmeAccountData; use proxmox_acme_rs::Account; use crate::acme::AcmeClient; -use crate::api2::types::{AcmeAccountName, Authid, KnownAcmeDirectory}; +use crate::api2::types::{AcmeAccountName, AcmeChallengeSchema, Authid, KnownAcmeDirectory}; use crate::config::acl::PRIV_SYS_MODIFY; use crate::config::acme::plugin::{ DnsPlugin, DnsPluginCore, DnsPluginCoreUpdater, PLUGIN_ID_SCHEMA, @@ -386,35 +386,6 @@ fn get_directories() -> Result<&'static [KnownAcmeDirectory], Error> { Ok(crate::config::acme::KNOWN_ACME_DIRECTORIES) } -#[api( - properties: { - schema: { - type: Object, - additional_properties: true, - properties: {}, - }, - type: { - type: String, - }, - }, -)] -#[derive(Serialize)] -/// Schema for an ACME challenge plugin. -pub struct ChallengeSchema { - /// Plugin ID. - id: String, - - /// Human readable name, falls back to id. - name: String, - - /// Plugin Type. - #[serde(rename = "type")] - ty: &'static str, - - /// The plugin's parameter schema. - schema: Value, -} - #[api( access: { permission: &Permission::Anybody, @@ -422,14 +393,14 @@ pub struct ChallengeSchema { returns: { description: "ACME Challenge Plugin Shema.", type: Array, - items: { type: ChallengeSchema }, + items: { type: AcmeChallengeSchema }, }, )] /// Get named known ACME directory endpoints. -fn get_challenge_schema() -> Result, Error> { +fn get_challenge_schema() -> Result, Error> { let mut out = Vec::new(); crate::config::acme::foreach_dns_plugin(|id| { - out.push(ChallengeSchema { + out.push(AcmeChallengeSchema { id: id.to_owned(), name: id.to_owned(), ty: "dns", diff --git a/src/api2/types/acme.rs b/src/api2/types/acme.rs index 59470d1e..87b86537 100644 --- a/src/api2/types/acme.rs +++ b/src/api2/types/acme.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use serde_json::Value; use proxmox::api::{api, schema::{Schema, StringSchema, ApiStringFormat}}; @@ -68,3 +69,32 @@ proxmox::api_string_type! { #[serde(transparent)] pub struct AcmeAccountName(String); } + +#[api( + properties: { + schema: { + type: Object, + additional_properties: true, + properties: {}, + }, + type: { + type: String, + }, + }, +)] +#[derive(Serialize)] +/// Schema for an ACME challenge plugin. +pub struct AcmeChallengeSchema { + /// Plugin ID. + pub id: String, + + /// Human readable name, falls back to id. + pub name: String, + + /// Plugin Type. + #[serde(rename = "type")] + pub ty: &'static str, + + /// The plugin's parameter schema. + pub schema: Value, +}