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 <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-05-10 14:39:05 +02:00
parent 875d53ef6c
commit 60643023ad
2 changed files with 34 additions and 33 deletions

View File

@ -14,7 +14,7 @@ use proxmox_acme_rs::account::AccountData as AcmeAccountData;
use proxmox_acme_rs::Account; use proxmox_acme_rs::Account;
use crate::acme::AcmeClient; 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::acl::PRIV_SYS_MODIFY;
use crate::config::acme::plugin::{ use crate::config::acme::plugin::{
DnsPlugin, DnsPluginCore, DnsPluginCoreUpdater, PLUGIN_ID_SCHEMA, DnsPlugin, DnsPluginCore, DnsPluginCoreUpdater, PLUGIN_ID_SCHEMA,
@ -386,35 +386,6 @@ fn get_directories() -> Result<&'static [KnownAcmeDirectory], Error> {
Ok(crate::config::acme::KNOWN_ACME_DIRECTORIES) 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( #[api(
access: { access: {
permission: &Permission::Anybody, permission: &Permission::Anybody,
@ -422,14 +393,14 @@ pub struct ChallengeSchema {
returns: { returns: {
description: "ACME Challenge Plugin Shema.", description: "ACME Challenge Plugin Shema.",
type: Array, type: Array,
items: { type: ChallengeSchema }, items: { type: AcmeChallengeSchema },
}, },
)] )]
/// Get named known ACME directory endpoints. /// Get named known ACME directory endpoints.
fn get_challenge_schema() -> Result<Vec<ChallengeSchema>, Error> { fn get_challenge_schema() -> Result<Vec<AcmeChallengeSchema>, Error> {
let mut out = Vec::new(); let mut out = Vec::new();
crate::config::acme::foreach_dns_plugin(|id| { crate::config::acme::foreach_dns_plugin(|id| {
out.push(ChallengeSchema { out.push(AcmeChallengeSchema {
id: id.to_owned(), id: id.to_owned(),
name: id.to_owned(), name: id.to_owned(),
ty: "dns", ty: "dns",

View File

@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value;
use proxmox::api::{api, schema::{Schema, StringSchema, ApiStringFormat}}; use proxmox::api::{api, schema::{Schema, StringSchema, ApiStringFormat}};
@ -68,3 +69,32 @@ proxmox::api_string_type! {
#[serde(transparent)] #[serde(transparent)]
pub struct AcmeAccountName(String); 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,
}