-
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.
Initial
yaml
file format for age
sops file metadata.
- Loading branch information
Showing
7 changed files
with
146 additions
and
7 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
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
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,110 @@ | ||
mod file_format {} | ||
|
||
#[cfg(feature = "test-utils")] | ||
pub use test_utils::*; | ||
#[cfg(feature = "test-utils")] | ||
mod test_utils { | ||
#[cfg(feature = "yaml")] | ||
pub use yaml::YamlTestUtils; | ||
#[cfg(feature = "yaml")] | ||
mod yaml { | ||
use std::fmt::Debug; | ||
|
||
use serde::{de::DeserializeOwned, Serialize}; | ||
|
||
use crate::*; | ||
|
||
pub struct YamlTestUtils; | ||
|
||
impl YamlTestUtils { | ||
pub fn assert_serialization<T: MockTestUtil + MockYamlTestUtil + Serialize>() { | ||
assert_eq!(T::mock_yaml(), serde_yaml::to_string(&T::mock()).unwrap()) | ||
} | ||
|
||
pub fn assert_deserialization<T: MockTestUtil + MockYamlTestUtil + DeserializeOwned + Debug + PartialEq>() { | ||
assert_eq!(T::mock(), serde_yaml::from_str(&T::mock_yaml()).unwrap()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub use metadata::*; | ||
mod metadata { | ||
pub use core::SopsFileMetadata; | ||
mod core { | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::*; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct SopsFileMetadata { | ||
#[cfg(feature = "age")] | ||
pub age: Vec<SopsFileAgeMetadata>, | ||
} | ||
} | ||
|
||
#[cfg(feature = "age")] | ||
pub use age::SopsFileAgeMetadata; | ||
#[cfg(feature = "age")] | ||
mod age { | ||
use serde::{Deserialize, Serialize}; | ||
use serde_with::{serde_as, DisplayFromStr}; | ||
|
||
use crate::*; | ||
|
||
#[serde_as] | ||
#[derive(Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct SopsFileAgeMetadata { | ||
#[serde_as(as = "DisplayFromStr")] | ||
#[serde(rename = "recipient")] | ||
pub public_key: <AgeIntegration as Integration>::PublicKey, | ||
#[serde(rename = "enc")] | ||
pub encrypted_data_key: String, | ||
} | ||
|
||
#[cfg(feature = "test-utils")] | ||
mod test_utils { | ||
use super::*; | ||
|
||
impl MockTestUtil for SopsFileAgeMetadata { | ||
fn mock() -> Self { | ||
Self { | ||
public_key: AgeIntegration::mock_public_key(), | ||
encrypted_data_key: AgeIntegration::mock_encrypted_data_key_str().to_string(), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(feature = "yaml")] | ||
impl MockYamlTestUtil for SopsFileAgeMetadata { | ||
fn mock_yaml() -> String { | ||
indoc::formatdoc! {" | ||
recipient: {} | ||
enc: | | ||
{}", | ||
AgeIntegration::mock_public_key_str(), | ||
textwrap::indent(AgeIntegration::mock_encrypted_data_key_str()," ") | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[cfg(feature = "yaml")] | ||
mod yaml { | ||
use crate::*; | ||
|
||
#[test] | ||
fn serializes_yaml_age_sops_file_metadata() { | ||
YamlTestUtils::assert_serialization::<SopsFileAgeMetadata>() | ||
} | ||
|
||
#[test] | ||
fn deserializes_yaml_age_sops_file_metadata() { | ||
YamlTestUtils::assert_deserialization::<SopsFileAgeMetadata>() | ||
} | ||
} | ||
} | ||
} | ||
} |