forked from cnabio/cnab-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cnabio#24 from technosophos/feat/credentialset
feat: implement credentialsets per spec section 802
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
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,55 @@ | ||
use serde::{Serialize, Deserialize}; | ||
/// CredentialSet implements section 802 of the CNAB specification at the time CNAB Core 1.0 was finalized. | ||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct CredentialSet { | ||
pub name: String, | ||
pub credentials: Vec<Credential>, | ||
} | ||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Credential { | ||
name: String, | ||
source: CredentialSource, | ||
} | ||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct CredentialSource { | ||
value: Option<String>, | ||
env: Option<String>, | ||
path: Option<std::path::PathBuf>, | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
#[test] | ||
fn test_credentialset() { | ||
let _: CredentialSet = serde_json::from_str( | ||
r#"{ | ||
"name": "test_credentials", | ||
"credentials": [ | ||
{ | ||
"name": "kubeconfig", | ||
"source": { | ||
"path": "$HOME/.kube/config" | ||
} | ||
}, | ||
{ | ||
"name": "image_token", | ||
"source": { | ||
"value": "1234aaaaaaaaaaaa" | ||
} | ||
}, | ||
{ | ||
"name": "hostkey", | ||
"source": { | ||
"env": "HOSTKEY", | ||
"path": "$HOME/.thing/hostkey" | ||
} | ||
} | ||
] | ||
}"# | ||
).expect("credential set parsed"); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -11,3 +11,6 @@ pub use ulid::Ulid; | |
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
mod credentialset; | ||
pub use crate::credentialset::*; |