feat(opnsense-config): dnsmasq dhcp static mappings (#130)
All checks were successful
Run Check Script / check (pull_request) Successful in 59s
All checks were successful
Run Check Script / check (pull_request) Successful in 59s
Co-authored-by: Jean-Gabriel Gill-Couture <jeangabriel.gc@gmail.com> Co-authored-by: Ian Letourneau <ian@noma.to> Reviewed-on: #130 Reviewed-by: Ian Letourneau <ian@noma.to> Co-authored-by: Jean-Gabriel Gill-Couture <jg@nationtech.io> Co-committed-by: Jean-Gabriel Gill-Couture <jg@nationtech.io>
This commit is contained in:
@@ -9,6 +9,7 @@ use config::INFISICAL_ENVIRONMENT;
|
||||
use config::INFISICAL_PROJECT_ID;
|
||||
use config::INFISICAL_URL;
|
||||
use config::SECRET_STORE;
|
||||
use log::debug;
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
use std::fmt;
|
||||
use store::InfisicalSecretStore;
|
||||
@@ -101,6 +102,7 @@ impl SecretManager {
|
||||
/// Retrieves and deserializes a secret.
|
||||
pub async fn get<T: Secret>() -> Result<T, SecretStoreError> {
|
||||
let manager = get_secret_manager().await;
|
||||
debug!("Getting secret ns {} key {}", &manager.namespace, T::KEY);
|
||||
let raw_value = manager.store.get_raw(&manager.namespace, T::KEY).await?;
|
||||
serde_json::from_slice(&raw_value).map_err(|e| SecretStoreError::Deserialization {
|
||||
key: T::KEY.to_string(),
|
||||
@@ -108,6 +110,42 @@ impl SecretManager {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn get_or_prompt<T: Secret>() -> Result<T, SecretStoreError> {
|
||||
let secret = Self::get::<T>().await;
|
||||
let manager = get_secret_manager().await;
|
||||
let prompted = secret.is_err();
|
||||
|
||||
let secret = secret.or_else(|e| -> Result<T, SecretStoreError> {
|
||||
debug!("Could not get secret : {e}");
|
||||
|
||||
let ns = &manager.namespace;
|
||||
let key = T::KEY;
|
||||
let secret_json = inquire::Text::new(&format!(
|
||||
"Secret not found for {} {}, paste the JSON here :",
|
||||
ns, key
|
||||
))
|
||||
.prompt()
|
||||
.map_err(|e| {
|
||||
SecretStoreError::Store(format!("Failed to prompt secret {ns} {key} : {e}").into())
|
||||
})?;
|
||||
|
||||
let secret: T = serde_json::from_str(&secret_json).map_err(|e| {
|
||||
SecretStoreError::Deserialization {
|
||||
key: T::KEY.to_string(),
|
||||
source: e,
|
||||
}
|
||||
})?;
|
||||
|
||||
Ok(secret)
|
||||
})?;
|
||||
|
||||
if prompted {
|
||||
Self::set(&secret).await?;
|
||||
}
|
||||
|
||||
Ok(secret)
|
||||
}
|
||||
|
||||
/// Serializes and stores a secret.
|
||||
pub async fn set<T: Secret>(secret: &T) -> Result<(), SecretStoreError> {
|
||||
let manager = get_secret_manager().await;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use async_trait::async_trait;
|
||||
use log::info;
|
||||
use log::{debug, info};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::{SecretStore, SecretStoreError};
|
||||
@@ -24,7 +24,7 @@ impl SecretStore for LocalFileSecretStore {
|
||||
.join("secrets");
|
||||
|
||||
let file_path = Self::get_file_path(&data_dir, ns, key);
|
||||
info!(
|
||||
debug!(
|
||||
"LOCAL_STORE: Getting key '{key}' from namespace '{ns}' at {}",
|
||||
file_path.display()
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user