-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove credentials.toml support, using environment instead
- Loading branch information
Showing
16 changed files
with
107 additions
and
146 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use crate::credentials::{Credential, CredentialSelector, CredentialStorage}; | ||
use crate::error::EngineError; | ||
use async_trait::async_trait; | ||
use regex::Regex; | ||
use std::collections::HashMap; | ||
use tracing::info; | ||
use uuid::Uuid; | ||
|
||
#[derive(Eq, PartialEq, Hash, Debug)] | ||
struct CredentialKey { | ||
project: Uuid, | ||
name: String, | ||
} | ||
|
||
#[derive(Default, Debug)] | ||
pub struct EnvCredentialStorage(HashMap<CredentialKey, Credential>); | ||
|
||
impl EnvCredentialStorage { | ||
pub fn new() -> Self { | ||
let mut storage = HashMap::new(); | ||
|
||
let re = Regex::new("^NOTIFICO_CRED_(?:([[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12})_)?(.+)$").unwrap(); | ||
for (name, value) in std::env::vars() { | ||
let Some(captures) = re.captures(&name) else { | ||
continue; | ||
}; | ||
|
||
let project = captures | ||
.get(1) | ||
.map_or_else(Uuid::nil, |m| Uuid::parse_str(m.as_str()).unwrap()); | ||
let name = captures.get(2).unwrap().as_str(); | ||
let credential = Credential::Short(value); | ||
|
||
storage.insert( | ||
CredentialKey { | ||
project, | ||
name: name.to_lowercase(), | ||
}, | ||
credential, | ||
); | ||
} | ||
|
||
info!( | ||
"Imported {} credentials from environment variables", | ||
storage.len() | ||
); | ||
Self(storage) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl CredentialStorage for EnvCredentialStorage { | ||
async fn get_credential( | ||
&self, | ||
project: Uuid, | ||
selector: &CredentialSelector, | ||
) -> Result<Credential, EngineError> { | ||
match selector { | ||
CredentialSelector::ByName(name) => { | ||
let key = CredentialKey { | ||
project, | ||
name: name.to_lowercase(), | ||
}; | ||
|
||
self.0 | ||
.get(&key) | ||
.cloned() | ||
.ok_or(EngineError::CredentialNotFound) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
notifico-core/src/credentials.rs → notifico-core/src/credentials/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
pub mod config; | ||
pub mod contact; | ||
pub mod credentials; | ||
pub mod db; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.