Skip to content

Commit

Permalink
Merge pull request cnabio#24 from technosophos/feat/credentialset
Browse files Browse the repository at this point in the history
feat: implement credentialsets per spec section 802
  • Loading branch information
technosophos authored Nov 13, 2019
2 parents 603d0d7 + d47e505 commit 2c01696
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/credentialset.rs
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");
}
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ pub use ulid::Ulid;

#[cfg(test)]
mod tests;

mod credentialset;
pub use crate::credentialset::*;

0 comments on commit 2c01696

Please sign in to comment.