product-config: simplify by removing the configuration directory
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
parent
40f812f324
commit
e913330e09
@ -2,11 +2,11 @@ use anyhow::Error;
|
||||
|
||||
use proxmox_sys::fs::CreateOptions;
|
||||
|
||||
use super::product_config;
|
||||
use super::get_api_user;
|
||||
|
||||
/// Return [CreateOptions] for files owned by `api_user.uid/api_user.gid` with mode `0640`.
|
||||
pub fn default_create_options() -> CreateOptions {
|
||||
let api_user = &product_config().api_user;
|
||||
let api_user = get_api_user();
|
||||
let mode = nix::sys::stat::Mode::from_bits_truncate(0o0640);
|
||||
proxmox_sys::fs::CreateOptions::new()
|
||||
.perm(mode)
|
||||
@ -18,7 +18,7 @@ pub fn default_create_options() -> CreateOptions {
|
||||
///
|
||||
/// Only the superuser can write those files, but group `api-user.gid` can read them.
|
||||
pub fn privileged_create_options() -> CreateOptions {
|
||||
let api_user = &product_config().api_user;
|
||||
let api_user = get_api_user();
|
||||
let mode = nix::sys::stat::Mode::from_bits_truncate(0o0640);
|
||||
proxmox_sys::fs::CreateOptions::new()
|
||||
.perm(mode)
|
||||
@ -51,7 +51,7 @@ pub fn system_config_create_options() -> CreateOptions {
|
||||
|
||||
/// Return [CreateOptions] for lock files, owner `api_user.uid/api_user.gid` and mode `0660`.
|
||||
pub fn lockfile_create_options() -> CreateOptions {
|
||||
let api_user = &product_config().api_user;
|
||||
let api_user = get_api_user();
|
||||
proxmox_sys::fs::CreateOptions::new()
|
||||
.perm(nix::sys::stat::Mode::from_bits_truncate(0o660))
|
||||
.owner(api_user.uid)
|
||||
|
26
proxmox-product-config/src/init.rs
Normal file
26
proxmox-product-config/src/init.rs
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
struct ProxmoxProductConfig {
|
||||
// Configuration file owner.
|
||||
api_user: nix::unistd::User,
|
||||
}
|
||||
|
||||
static mut PRODUCT_CONFIG: Option<ProxmoxProductConfig> = None;
|
||||
|
||||
/// Initialize the global product configuration.
|
||||
pub fn init(api_user: nix::unistd::User) {
|
||||
unsafe {
|
||||
PRODUCT_CONFIG = Some(ProxmoxProductConfig {
|
||||
api_user,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the global product configuration (see [init_product_config])
|
||||
pub(crate) fn get_api_user() -> &'static nix::unistd::User {
|
||||
unsafe {
|
||||
&PRODUCT_CONFIG
|
||||
.as_ref()
|
||||
.expect("ProxmoxProductConfig is not initialized!")
|
||||
.api_user
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
mod filesystem_helpers;
|
||||
pub use filesystem_helpers::*;
|
||||
|
||||
mod product_config;
|
||||
pub use product_config::*;
|
||||
mod init;
|
||||
pub use init::*;
|
||||
|
@ -1,38 +0,0 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
static mut PRODUCT_CONFIG: Option<ProxmoxProductConfig> = None;
|
||||
|
||||
/// Initialize the global product configuration.
|
||||
pub fn init_product_config(config_dir: &'static str, api_user: nix::unistd::User) {
|
||||
unsafe {
|
||||
PRODUCT_CONFIG = Some(ProxmoxProductConfig {
|
||||
config_dir,
|
||||
api_user,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the global product configuration (see [init_product_config])
|
||||
pub fn product_config() -> &'static ProxmoxProductConfig {
|
||||
unsafe {
|
||||
PRODUCT_CONFIG
|
||||
.as_ref()
|
||||
.expect("ProxmoxProductConfig is not initialized!")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ProxmoxProductConfig {
|
||||
/// Path to the main product configuration directory.
|
||||
pub(crate) config_dir: &'static str,
|
||||
|
||||
/// Configuration file owner.
|
||||
pub(crate) api_user: nix::unistd::User,
|
||||
}
|
||||
|
||||
impl ProxmoxProductConfig {
|
||||
/// Returns the absolute path (prefix with 'config_dir')
|
||||
pub fn absolute_path(&self, rel_path: &str) -> PathBuf {
|
||||
let path = Path::new(self.config_dir);
|
||||
path.join(rel_path)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user