start new pbs-config workspace
moved src/config/domains.rs
This commit is contained in:
@ -911,7 +911,7 @@ pub fn save_config(acl: &AclTree) -> Result<(), Error> {
|
||||
|
||||
acl.write_config(&mut raw)?;
|
||||
|
||||
crate::backup::replace_backup_config(ACL_CFG_FILENAME, &raw)
|
||||
pbs_config::replace_backup_config(ACL_CFG_FILENAME, &raw)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -9,8 +9,8 @@ use proxmox::api::{
|
||||
section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin},
|
||||
};
|
||||
|
||||
use crate::api2::types::PROXMOX_SAFE_ID_FORMAT;
|
||||
use crate::backup::{open_backup_lockfile, BackupLockGuard};
|
||||
use pbs_config::{open_backup_lockfile, BackupLockGuard};
|
||||
use pbs_api_types::PROXMOX_SAFE_ID_FORMAT;
|
||||
|
||||
pub const PLUGIN_ID_SCHEMA: Schema = StringSchema::new("ACME Challenge Plugin ID.")
|
||||
.format(&PROXMOX_SAFE_ID_FORMAT)
|
||||
@ -162,7 +162,7 @@ pub fn config() -> Result<(PluginData, [u8; 32]), Error> {
|
||||
pub fn save_config(config: &PluginData) -> Result<(), Error> {
|
||||
super::make_acme_dir()?;
|
||||
let raw = CONFIG.write(ACME_PLUGIN_CFG_FILENAME, &config.data)?;
|
||||
crate::backup::replace_backup_config(ACME_PLUGIN_CFG_FILENAME, raw.as_bytes())
|
||||
pbs_config::replace_backup_config(ACME_PLUGIN_CFG_FILENAME, raw.as_bytes())
|
||||
}
|
||||
|
||||
pub struct PluginData {
|
||||
|
@ -13,8 +13,9 @@ use proxmox::api::{
|
||||
}
|
||||
};
|
||||
|
||||
use pbs_config::{open_backup_lockfile, BackupLockGuard};
|
||||
|
||||
use crate::api2::types::*;
|
||||
use crate::backup::{open_backup_lockfile, BackupLockGuard};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref CONFIG: SectionConfig = init();
|
||||
@ -152,7 +153,7 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
|
||||
pub fn save_config(config: &SectionConfigData) -> Result<(), Error> {
|
||||
let raw = CONFIG.write(DATASTORE_CFG_FILENAME, &config)?;
|
||||
crate::backup::replace_backup_config(DATASTORE_CFG_FILENAME, raw.as_bytes())
|
||||
pbs_config::replace_backup_config(DATASTORE_CFG_FILENAME, raw.as_bytes())
|
||||
}
|
||||
|
||||
// shell completion helper
|
||||
|
@ -1,136 +0,0 @@
|
||||
use anyhow::{Error};
|
||||
use lazy_static::lazy_static;
|
||||
use std::collections::HashMap;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use proxmox::api::{
|
||||
api,
|
||||
schema::*,
|
||||
section_config::{
|
||||
SectionConfig,
|
||||
SectionConfigData,
|
||||
SectionConfigPlugin,
|
||||
}
|
||||
};
|
||||
|
||||
use crate::api2::types::*;
|
||||
use crate::backup::{open_backup_lockfile, BackupLockGuard};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref CONFIG: SectionConfig = init();
|
||||
}
|
||||
|
||||
#[api()]
|
||||
#[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
/// Use the value of this attribute/claim as unique user name. It is
|
||||
/// up to the identity provider to guarantee the uniqueness. The
|
||||
/// OpenID specification only guarantees that Subject ('sub') is unique. Also
|
||||
/// make sure that the user is not allowed to change that attribute by
|
||||
/// himself!
|
||||
pub enum OpenIdUserAttribute {
|
||||
/// Subject (OpenId 'sub' claim)
|
||||
Subject,
|
||||
/// Username (OpenId 'preferred_username' claim)
|
||||
Username,
|
||||
/// Email (OpenId 'email' claim)
|
||||
Email,
|
||||
}
|
||||
|
||||
#[api(
|
||||
properties: {
|
||||
realm: {
|
||||
schema: REALM_ID_SCHEMA,
|
||||
},
|
||||
"client-key": {
|
||||
optional: true,
|
||||
},
|
||||
comment: {
|
||||
optional: true,
|
||||
schema: SINGLE_LINE_COMMENT_SCHEMA,
|
||||
},
|
||||
autocreate: {
|
||||
optional: true,
|
||||
default: false,
|
||||
},
|
||||
"username-claim": {
|
||||
type: OpenIdUserAttribute,
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
)]
|
||||
#[derive(Serialize,Deserialize,Updater)]
|
||||
#[serde(rename_all="kebab-case")]
|
||||
/// OpenID configuration properties.
|
||||
pub struct OpenIdRealmConfig {
|
||||
#[updater(skip)]
|
||||
pub realm: String,
|
||||
/// OpenID Issuer Url
|
||||
pub issuer_url: String,
|
||||
/// OpenID Client ID
|
||||
pub client_id: String,
|
||||
/// OpenID Client Key
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub client_key: Option<String>,
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub comment: Option<String>,
|
||||
/// Automatically create users if they do not exist.
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub autocreate: Option<bool>,
|
||||
#[updater(skip)]
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub username_claim: Option<OpenIdUserAttribute>,
|
||||
}
|
||||
|
||||
fn init() -> SectionConfig {
|
||||
let obj_schema = match OpenIdRealmConfig::API_SCHEMA {
|
||||
Schema::Object(ref obj_schema) => obj_schema,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let plugin = SectionConfigPlugin::new("openid".to_string(), Some(String::from("realm")), obj_schema);
|
||||
let mut config = SectionConfig::new(&REALM_ID_SCHEMA);
|
||||
config.register_plugin(plugin);
|
||||
|
||||
config
|
||||
}
|
||||
|
||||
pub const DOMAINS_CFG_FILENAME: &str = "/etc/proxmox-backup/domains.cfg";
|
||||
pub const DOMAINS_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.domains.lck";
|
||||
|
||||
/// Get exclusive lock
|
||||
pub fn lock_config() -> Result<BackupLockGuard, Error> {
|
||||
open_backup_lockfile(DOMAINS_CFG_LOCKFILE, None, true)
|
||||
}
|
||||
|
||||
pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
|
||||
let content = proxmox::tools::fs::file_read_optional_string(DOMAINS_CFG_FILENAME)?
|
||||
.unwrap_or_else(|| "".to_string());
|
||||
|
||||
let digest = openssl::sha::sha256(content.as_bytes());
|
||||
let data = CONFIG.parse(DOMAINS_CFG_FILENAME, &content)?;
|
||||
Ok((data, digest))
|
||||
}
|
||||
|
||||
pub fn save_config(config: &SectionConfigData) -> Result<(), Error> {
|
||||
let raw = CONFIG.write(DOMAINS_CFG_FILENAME, &config)?;
|
||||
crate::backup::replace_backup_config(DOMAINS_CFG_FILENAME, raw.as_bytes())
|
||||
}
|
||||
|
||||
// shell completion helper
|
||||
pub fn complete_realm_name(_arg: &str, _param: &HashMap<String, String>) -> Vec<String> {
|
||||
match config() {
|
||||
Ok((data, _digest)) => data.sections.iter().map(|(id, _)| id.to_string()).collect(),
|
||||
Err(_) => return vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn complete_openid_realm_name(_arg: &str, _param: &HashMap<String, String>) -> Vec<String> {
|
||||
match config() {
|
||||
Ok((data, _digest)) => data.sections.iter()
|
||||
.filter_map(|(id, (t, _))| if t == "openid" { Some(id.to_string()) } else { None })
|
||||
.collect(),
|
||||
Err(_) => return vec![],
|
||||
}
|
||||
}
|
@ -27,8 +27,9 @@ use proxmox::{
|
||||
},
|
||||
};
|
||||
|
||||
use pbs_config::{open_backup_lockfile, BackupLockGuard};
|
||||
|
||||
use crate::{
|
||||
backup::{open_backup_lockfile, BackupLockGuard},
|
||||
api2::types::{
|
||||
DRIVE_NAME_SCHEMA,
|
||||
VirtualTapeDrive,
|
||||
@ -93,7 +94,7 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
/// Save the configuration file
|
||||
pub fn save_config(config: &SectionConfigData) -> Result<(), Error> {
|
||||
let raw = CONFIG.write(DRIVE_CFG_FILENAME, &config)?;
|
||||
crate::backup::replace_backup_config(DRIVE_CFG_FILENAME, raw.as_bytes())
|
||||
pbs_config::replace_backup_config(DRIVE_CFG_FILENAME, raw.as_bytes())
|
||||
}
|
||||
|
||||
/// Check if the specified drive name exists in the config.
|
||||
|
@ -22,8 +22,9 @@ use proxmox::{
|
||||
},
|
||||
};
|
||||
|
||||
use pbs_config::{open_backup_lockfile, BackupLockGuard};
|
||||
|
||||
use crate::{
|
||||
backup::{open_backup_lockfile, BackupLockGuard},
|
||||
api2::types::{
|
||||
MEDIA_POOL_NAME_SCHEMA,
|
||||
MediaPoolConfig,
|
||||
@ -72,7 +73,7 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
/// Save the configuration file
|
||||
pub fn save_config(config: &SectionConfigData) -> Result<(), Error> {
|
||||
let raw = CONFIG.write(MEDIA_POOL_CFG_FILENAME, &config)?;
|
||||
crate::backup::replace_backup_config(MEDIA_POOL_CFG_FILENAME, raw.as_bytes())
|
||||
pbs_config::replace_backup_config(MEDIA_POOL_CFG_FILENAME, raw.as_bytes())
|
||||
}
|
||||
|
||||
// shell completion helper
|
||||
|
@ -30,7 +30,6 @@ pub mod drive;
|
||||
pub mod media_pool;
|
||||
pub mod tape_encryption_keys;
|
||||
pub mod tape_job;
|
||||
pub mod domains;
|
||||
|
||||
/// Check configuration directory permissions
|
||||
///
|
||||
@ -40,7 +39,7 @@ pub mod domains;
|
||||
pub fn check_configdir_permissions() -> Result<(), Error> {
|
||||
let cfgdir = pbs_buildcfg::CONFIGDIR;
|
||||
|
||||
let backup_user = crate::backup::backup_user()?;
|
||||
let backup_user = pbs_config::backup_user()?;
|
||||
let backup_uid = backup_user.uid.as_raw();
|
||||
let backup_gid = backup_user.gid.as_raw();
|
||||
|
||||
@ -85,7 +84,7 @@ pub fn create_configdir() -> Result<(), Error> {
|
||||
),
|
||||
}
|
||||
|
||||
let backup_user = crate::backup::backup_user()?;
|
||||
let backup_user = pbs_config::backup_user()?;
|
||||
|
||||
nix::unistd::chown(cfgdir, Some(backup_user.uid), Some(backup_user.gid))
|
||||
.map_err(|err| {
|
||||
@ -197,9 +196,9 @@ pub(crate) fn set_proxy_certificate(cert_pem: &[u8], key_pem: &[u8]) -> Result<(
|
||||
let cert_path = PathBuf::from(configdir!("/proxy.pem"));
|
||||
|
||||
create_configdir()?;
|
||||
crate::backup::replace_backup_config(&key_path, key_pem)
|
||||
pbs_config::replace_backup_config(&key_path, key_pem)
|
||||
.map_err(|err| format_err!("error writing certificate private key - {}", err))?;
|
||||
crate::backup::replace_backup_config(&cert_path, &cert_pem)
|
||||
pbs_config::replace_backup_config(&cert_path, &cert_pem)
|
||||
.map_err(|err| format_err!("error writing certificate file - {}", err))?;
|
||||
|
||||
Ok(())
|
||||
|
@ -9,8 +9,8 @@ use proxmox::api::schema::{ApiStringFormat, ApiType, Updater};
|
||||
use proxmox_http::ProxyConfig;
|
||||
|
||||
use pbs_buildcfg::configdir;
|
||||
use pbs_config::{open_backup_lockfile, BackupLockGuard};
|
||||
|
||||
use crate::backup::{open_backup_lockfile, BackupLockGuard};
|
||||
use crate::acme::AcmeClient;
|
||||
use crate::api2::types::{
|
||||
AcmeAccountName, AcmeDomain, ACME_DOMAIN_PROPERTY_SCHEMA, HTTP_PROXY_SCHEMA,
|
||||
@ -39,7 +39,7 @@ pub fn save_config(config: &NodeConfig) -> Result<(), Error> {
|
||||
config.validate()?;
|
||||
|
||||
let raw = crate::tools::config::to_bytes(config, &NodeConfig::API_SCHEMA)?;
|
||||
crate::backup::replace_backup_config(CONF_FILE, &raw)
|
||||
pbs_config::replace_backup_config(CONF_FILE, &raw)
|
||||
}
|
||||
|
||||
#[api(
|
||||
|
@ -122,7 +122,7 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
|
||||
pub fn save_config(config: &SectionConfigData) -> Result<(), Error> {
|
||||
let raw = CONFIG.write(REMOTE_CFG_FILENAME, &config)?;
|
||||
crate::backup::replace_backup_config(REMOTE_CFG_FILENAME, raw.as_bytes())
|
||||
pbs_config::replace_backup_config(REMOTE_CFG_FILENAME, raw.as_bytes())
|
||||
}
|
||||
|
||||
// shell completion helper
|
||||
|
@ -118,7 +118,7 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
|
||||
pub fn save_config(config: &SectionConfigData) -> Result<(), Error> {
|
||||
let raw = CONFIG.write(SYNC_CFG_FILENAME, &config)?;
|
||||
crate::backup::replace_backup_config(SYNC_CFG_FILENAME, raw.as_bytes())
|
||||
pbs_config::replace_backup_config(SYNC_CFG_FILENAME, raw.as_bytes())
|
||||
}
|
||||
|
||||
// shell completion helper
|
||||
|
@ -19,7 +19,7 @@ use proxmox::tools::fs::file_read_optional_string;
|
||||
use pbs_api_types::Fingerprint;
|
||||
use pbs_datastore::key_derivation::KeyConfig;
|
||||
|
||||
use crate::backup::open_backup_lockfile;
|
||||
use pbs_config::{open_backup_lockfile, replace_secret_config};
|
||||
|
||||
mod hex_key {
|
||||
use serde::{self, Deserialize, Serializer, Deserializer};
|
||||
@ -135,7 +135,7 @@ pub fn save_keys(map: HashMap<Fingerprint, EncryptionKeyInfo>) -> Result<(), Err
|
||||
}
|
||||
|
||||
let raw = serde_json::to_string_pretty(&list)?;
|
||||
crate::backup::replace_secret_config(TAPE_KEYS_FILENAME, raw.as_bytes())
|
||||
replace_secret_config(TAPE_KEYS_FILENAME, raw.as_bytes())
|
||||
}
|
||||
|
||||
/// Store tape encryption key configurations (password protected keys)
|
||||
@ -148,7 +148,7 @@ pub fn save_key_configs(map: HashMap<Fingerprint, KeyConfig>) -> Result<(), Erro
|
||||
}
|
||||
|
||||
let raw = serde_json::to_string_pretty(&list)?;
|
||||
crate::backup::replace_backup_config(TAPE_KEY_CONFIG_FILENAME, raw.as_bytes())
|
||||
pbs_config::replace_backup_config(TAPE_KEY_CONFIG_FILENAME, raw.as_bytes())
|
||||
}
|
||||
|
||||
/// Insert a new key
|
||||
|
@ -160,7 +160,7 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
|
||||
pub fn save_config(config: &SectionConfigData) -> Result<(), Error> {
|
||||
let raw = CONFIG.write(TAPE_JOB_CFG_FILENAME, &config)?;
|
||||
crate::backup::replace_backup_config(TAPE_JOB_CFG_FILENAME, raw.as_bytes())
|
||||
pbs_config::replace_backup_config(TAPE_JOB_CFG_FILENAME, raw.as_bytes())
|
||||
}
|
||||
|
||||
// shell completion helper
|
||||
|
@ -26,9 +26,9 @@ use proxmox::tools::uuid::Uuid;
|
||||
use proxmox::tools::AsHex;
|
||||
|
||||
use pbs_buildcfg::configdir;
|
||||
use pbs_config::{open_backup_lockfile, BackupLockGuard};
|
||||
|
||||
use crate::api2::types::Userid;
|
||||
use crate::backup::{open_backup_lockfile, BackupLockGuard};
|
||||
|
||||
/// Mapping of userid to TFA entry.
|
||||
pub type TfaUsers = HashMap<Userid, TfaUserData>;
|
||||
|
@ -8,7 +8,7 @@ use proxmox::tools::fs::CreateOptions;
|
||||
|
||||
use crate::api2::types::Authid;
|
||||
use crate::auth;
|
||||
use crate::backup::open_backup_lockfile;
|
||||
use pbs_config::open_backup_lockfile;
|
||||
|
||||
const LOCK_FILE: &str = pbs_buildcfg::configdir!("/token.shadow.lock");
|
||||
const CONF_FILE: &str = pbs_buildcfg::configdir!("/token.shadow");
|
||||
@ -33,7 +33,7 @@ fn read_file() -> Result<HashMap<Authid, String>, Error> {
|
||||
}
|
||||
|
||||
fn write_file(data: HashMap<Authid, String>) -> Result<(), Error> {
|
||||
let backup_user = crate::backup::backup_user()?;
|
||||
let backup_user = pbs_config::backup_user()?;
|
||||
let options = CreateOptions::new()
|
||||
.perm(nix::sys::stat::Mode::from_bits_truncate(0o0640))
|
||||
.owner(backup_user.uid)
|
||||
|
@ -119,7 +119,7 @@ pub fn cached_config() -> Result<Arc<SectionConfigData>, Error> {
|
||||
|
||||
pub fn save_config(config: &SectionConfigData) -> Result<(), Error> {
|
||||
let raw = CONFIG.write(USER_CFG_FILENAME, &config)?;
|
||||
crate::backup::replace_backup_config(USER_CFG_FILENAME, raw.as_bytes())?;
|
||||
pbs_config::replace_backup_config(USER_CFG_FILENAME, raw.as_bytes())?;
|
||||
|
||||
// increase user cache generation
|
||||
// We use this in CachedUserInfo
|
||||
|
@ -116,7 +116,7 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||
|
||||
pub fn save_config(config: &SectionConfigData) -> Result<(), Error> {
|
||||
let raw = CONFIG.write(VERIFICATION_CFG_FILENAME, &config)?;
|
||||
crate::backup::replace_backup_config(VERIFICATION_CFG_FILENAME, raw.as_bytes())
|
||||
pbs_config::replace_backup_config(VERIFICATION_CFG_FILENAME, raw.as_bytes())
|
||||
}
|
||||
|
||||
// shell completion helper
|
||||
|
Reference in New Issue
Block a user