Add encrypted config
This commit is contained in:
parent
2559ef4452
commit
548e98838b
20
conf.toml.sops
Normal file
20
conf.toml.sops
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"data": "ENC[AES256_GCM,data:jVTiiuy0//yVa0QwCvx34IzKFJao3Dd/a9vympEUvqrGXoW2Tx847R1cRQ1UvSJ1/aK+Nzui7MiTCntNORAsIgAr5EkqX54AS/aW5uc0Dk54LM/Sp++wlNeAvNTFFQ7PjVZVEEwcAAGijZpA6QPYu9nMfb3W05OULAqiYj4im+yY/eruYl/lnAQ8Kfn6HERVfNegsPM63wAdyNFgKA==,iv:hhbCMrsoIMSvEMxJXGX8H7SHWKsAtFC7G+JBWBgL2TA=,tag:b+EOgaz9shJWhfcPT05aiQ==,type:str]",
|
||||||
|
"sops": {
|
||||||
|
"kms": null,
|
||||||
|
"gcp_kms": null,
|
||||||
|
"azure_kv": null,
|
||||||
|
"hc_vault": null,
|
||||||
|
"age": [
|
||||||
|
{
|
||||||
|
"recipient": "age1stdue5q5teskee057ced6rh9pzzr93xsy66w4sc3zu49rgxl7cjshztt45",
|
||||||
|
"enc": "-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBuOGgwVFlUeGRTTUVFVjN6\nYVlXRnAzUWo5Y01FaSsrdklGSWtKL0tjY0cwCm9tY3FuZGtLcUUyalpTNUNQeDJa\nVHp5azU2T1FIc0RaYkxCenkwYkRBdGMKLS0tIGQwV0RGQlVnbFRodVkvL0FKZmFX\nTGFsazZNVWxXTUFiL2MxN3JNL0RBU2MKKtK+szuRYu/csPo232Ge/jzlHBqQHNIK\nr8NEFL+Px2pBVXdJh/tibV7b5iUx4s7x9ghmEklhl1ZqwsCkjsmsKQ==\n-----END AGE ENCRYPTED FILE-----\n"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"lastmodified": "2024-04-13T15:48:26Z",
|
||||||
|
"mac": "ENC[AES256_GCM,data:BEgO8PoSNO3dIkmiNZ2yXmOWVyrohTT1UT6fpvhGXapUujhZIBNMqTvrTZGJldoeeBOz9FQRdPZGNN+GZAWHZfdMryvym9D0Tj3Rjqbvn6ukJ1uaXblGaB9C4SLfeQ50vK5gEq0Nn2KPtKnPeCFXYFT8ikt2bgo9dROmqkLtmXc=,iv:6O2HP3zwDPhucNruSZ/rrUTy3BeGwXokFblwTStQZf0=,tag:r7DOkdbG2dIWoBmZGbaJPg==,type:str]",
|
||||||
|
"pgp": null,
|
||||||
|
"unencrypted_suffix": "_unencrypted",
|
||||||
|
"version": "3.8.1"
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{collections::HashMap, fmt::Debug};
|
use std::{collections::HashMap, fmt::Debug, fs::File};
|
||||||
|
|
||||||
use config::{builder::DefaultState, Config as CConfig, ConfigBuilder};
|
use config::{builder::DefaultState, Config as CConfig, ConfigBuilder};
|
||||||
use redact::serde::redact_secret;
|
use redact::serde::redact_secret;
|
||||||
|
@ -27,6 +27,8 @@ pub struct Config {
|
||||||
pub open_ai: Option<OpenAI>,
|
pub open_ai: Option<OpenAI>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CONFIG_FILE_PATH: &str = "./conf.toml";
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn load() -> Result<Self> {
|
pub fn load() -> Result<Self> {
|
||||||
let c = Self::builder()?.build()?;
|
let c = Self::builder()?.build()?;
|
||||||
|
@ -34,10 +36,17 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn builder() -> Result<ConfigBuilder<DefaultState>> {
|
pub fn builder() -> Result<ConfigBuilder<DefaultState>> {
|
||||||
|
let p = std::path::PathBuf::from(CONFIG_FILE_PATH);
|
||||||
|
if !p.exists() {
|
||||||
|
warn!(
|
||||||
|
"Config file '{}' doesn't exist, so defaults will likely be loaded!",
|
||||||
|
p.display(),
|
||||||
|
);
|
||||||
|
}
|
||||||
// TODO: log whether or not we were able to load conf.toml?
|
// TODO: log whether or not we were able to load conf.toml?
|
||||||
Ok(Self::default_builder()
|
Ok(Self::default_builder()
|
||||||
.map_err(Error::from)?
|
.map_err(Error::from)?
|
||||||
.add_source(config::File::from(std::path::PathBuf::from("./conf.toml")).required(false))
|
.add_source(config::File::from(p).required(false))
|
||||||
.add_source(config::Environment::with_prefix("chatbot").separator("__")))
|
.add_source(config::Environment::with_prefix("chatbot").separator("__")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue