diff --git a/README.md b/README.md index 542d4ff..5651a89 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,11 @@ following to the macro to exclude it from `no-entrypoint` builds. #[cfg(not(feature = "no-entrypoint"))] ``` +#### Use as an indicator for the deployed code version + +In order to simplify access to the source code we recommend to include the commit hash as `source_revision` or the release tag as `source_release`. +You can use the `option_env!` macro to automatically configure values passed to the `security_txt!` macro from the build process envioronment. + ### Example ```rust @@ -74,6 +79,8 @@ security_txt! { // Optional Fields preferred_languages: "en,de", source_code: "https://github.com/example/example", + source_revision: option_env!("GITHUB_SHA").unwrap().into(), + source_release: option_env!("GITHUB_REF_NAME").unwrap().into(), encryption: " -----BEGIN PGP PUBLIC KEY BLOCK----- Comment: Alice's OpenPGP certificate diff --git a/security-txt/src/parser.rs b/security-txt/src/parser.rs index da35362..dcdcf88 100644 --- a/security-txt/src/parser.rs +++ b/security-txt/src/parser.rs @@ -181,12 +181,8 @@ pub fn parse(mut data: &[u8]) -> Result { .remove("project_url") .ok_or_else(|| SecurityTxtError::MissingField("project_url".to_string()))?; let source_code = attributes.remove("source_code"); - let source_release = attributes - .remove("source_release") - .or(option_env!("GITHUB_REF_NAME").map(|s| s.into())); - let source_revision = attributes - .remove("source_revision") - .or(option_env!("GITHUB_SHA").map(|s| s.into())); + let source_release = attributes.remove("source_release"); + let source_revision = attributes.remove("source_revision"); let expiry = attributes.remove("expiry"); let preferred_languages = attributes .remove("preferred_languages")