forked from Proxmox/proxmox
acme-api: add init method to setup directories
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
parent
e913330e09
commit
d152e47d78
@ -18,6 +18,7 @@ use proxmox_acme::types::AccountData as AcmeAccountData;
|
||||
use proxmox_acme::Account;
|
||||
|
||||
use crate::types::AcmeAccountName;
|
||||
use crate::acme_account_dir;
|
||||
|
||||
#[inline]
|
||||
fn is_false(b: &bool) -> bool {
|
||||
@ -78,10 +79,6 @@ impl AccountData {
|
||||
}
|
||||
}
|
||||
|
||||
fn acme_account_dir() -> PathBuf {
|
||||
super::config::acme_config_dir().join("accounts")
|
||||
}
|
||||
|
||||
/// Returns the path to the account configuration file (`$config_dir/accounts/$name`).
|
||||
pub fn account_cfg_filename(name: &str) -> PathBuf {
|
||||
acme_account_dir().join(name)
|
||||
@ -96,7 +93,7 @@ pub(crate) fn foreach_acme_account<F>(mut func: F) -> Result<(), Error>
|
||||
where
|
||||
F: FnMut(AcmeAccountName) -> ControlFlow<Result<(), Error>>,
|
||||
{
|
||||
match proxmox_sys::fs::scan_subdir(-1, acme_account_dir().as_path(), &SAFE_ID_REGEX) {
|
||||
match proxmox_sys::fs::scan_subdir(-1, acme_account_dir(), &SAFE_ID_REGEX) {
|
||||
Ok(files) => {
|
||||
for file in files {
|
||||
let file = file?;
|
||||
|
@ -1,14 +1,13 @@
|
||||
//! ACME API Configuration.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::Path;
|
||||
|
||||
use proxmox_sys::error::SysError;
|
||||
use proxmox_sys::fs::CreateOptions;
|
||||
|
||||
use proxmox_product_config::product_config;
|
||||
|
||||
use crate::types::KnownAcmeDirectory;
|
||||
use crate::acme_config_dir;
|
||||
|
||||
/// List of known ACME directorties.
|
||||
pub const KNOWN_ACME_DIRECTORIES: &[KnownAcmeDirectory] = &[
|
||||
@ -25,17 +24,6 @@ pub const KNOWN_ACME_DIRECTORIES: &[KnownAcmeDirectory] = &[
|
||||
/// Default ACME directorties.
|
||||
pub const DEFAULT_ACME_DIRECTORY_ENTRY: &KnownAcmeDirectory = &KNOWN_ACME_DIRECTORIES[0];
|
||||
|
||||
pub(crate) fn acme_config_dir() -> PathBuf {
|
||||
product_config().absolute_path("acme")
|
||||
}
|
||||
|
||||
pub(crate) fn plugin_cfg_filename() -> PathBuf {
|
||||
acme_config_dir().join("plugins.cfg")
|
||||
}
|
||||
|
||||
pub(crate) fn plugin_cfg_lockfile() -> PathBuf {
|
||||
acme_config_dir().join("plugins.lck")
|
||||
}
|
||||
|
||||
pub(crate) fn create_secret_subdir<P: AsRef<Path>>(dir: P) -> nix::Result<()> {
|
||||
let root_only = CreateOptions::new()
|
||||
|
@ -3,6 +3,11 @@
|
||||
#[cfg(feature = "api-types")]
|
||||
pub mod types;
|
||||
|
||||
#[cfg(feature = "impl")]
|
||||
mod init;
|
||||
#[cfg(feature = "impl")]
|
||||
pub use init::*;
|
||||
|
||||
#[cfg(feature = "impl")]
|
||||
mod config;
|
||||
|
||||
|
@ -56,19 +56,19 @@ fn init() -> SectionConfig {
|
||||
pub(crate) fn lock_plugin_config() -> Result<ApiLockGuard, Error> {
|
||||
super::config::make_acme_dir()?;
|
||||
|
||||
let plugin_cfg_lockfile = super::config::plugin_cfg_lockfile();
|
||||
let plugin_cfg_lockfile = crate::plugin_cfg_lockfile();
|
||||
|
||||
open_api_lockfile(plugin_cfg_lockfile, None, true)
|
||||
}
|
||||
|
||||
pub(crate) fn plugin_config() -> Result<(PluginData, ConfigDigest), Error> {
|
||||
let plugin_cfg_filename = super::config::plugin_cfg_filename();
|
||||
let plugin_cfg_filename = crate::plugin_cfg_filename();
|
||||
|
||||
let content =
|
||||
proxmox_sys::fs::file_read_optional_string(&plugin_cfg_filename)?.unwrap_or_default();
|
||||
|
||||
let digest = ConfigDigest::from_slice(content.as_bytes());
|
||||
let mut data = CONFIG.parse(&plugin_cfg_filename, &content)?;
|
||||
let mut data = CONFIG.parse(plugin_cfg_filename, &content)?;
|
||||
|
||||
if data.sections.get("standalone").is_none() {
|
||||
let standalone = StandalonePlugin::default();
|
||||
@ -81,7 +81,7 @@ pub(crate) fn plugin_config() -> Result<(PluginData, ConfigDigest), Error> {
|
||||
|
||||
pub(crate) fn save_plugin_config(config: &PluginData) -> Result<(), Error> {
|
||||
super::config::make_acme_dir()?;
|
||||
let plugin_cfg_filename = super::config::plugin_cfg_filename();
|
||||
let plugin_cfg_filename = crate::plugin_cfg_filename();
|
||||
let raw = CONFIG.write(&plugin_cfg_filename, &config.data)?;
|
||||
|
||||
replace_config(plugin_cfg_filename, raw.as_bytes())
|
||||
|
Loading…
Reference in New Issue
Block a user