macro_rules! include_service {
($name:ident) => {
#[allow(warnings)]
#[cfg(not(doctest))]
pub mod $name {
include!(concat!(
env!("OUT_DIR"),
"/codegen_",
stringify!($name),
".rs"
));
}
};
}
#[cfg(not(doctest))]
pub mod types {
use crate::rekor::types as rekor;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged, rename_all = "lowercase")]
pub enum ProposedEntry {
Rekord(rekor::Rekord),
Hashedrekord(rekor::Hashedrekord),
Rpm(rekor::Rpm),
Tuf(rekor::Tuf),
Helm(rekor::Helm),
Intoto(rekor::Intoto),
Cose(rekor::Cose),
Jar(rekor::Jar),
Rfc3161(rekor::Rfc3161),
Dsse(rekor::Dsse),
}
}
include_service!(fulcio);
include_service!(rekor);
#[cfg(test)]
mod tests {
use crate::{
fulcio,
rekor::{self, types::SearchLogQuery},
types::ProposedEntry,
};
const REKOR_URL: &str = "https://rekor.sigstore.dev";
const FULCIO_URL: &str = "https://fulcio.sigstore.dev";
#[tokio::test]
async fn rekor_get_log_info() {
let client = rekor::Client::new(REKOR_URL);
let response = client.get_log_info(None).await;
assert!(response.is_ok(), "{:?}", response.unwrap_err());
}
#[tokio::test]
async fn fulcio_get_configuration() {
let client = fulcio::Client::new(FULCIO_URL);
let response = client.ca_get_configuration().await;
assert!(response.is_ok(), "{:?}", response.unwrap_err());
}
#[tokio::test]
async fn rekor_get_log_entry() {
let client = rekor::Client::new(REKOR_URL);
let response = client.get_log_entry_by_index(Some(0)).await;
assert!(response.is_ok(), "{:?}", response.unwrap_err());
}
#[tokio::test]
async fn rekor_search_log_entries_by_index() {
let client = rekor::Client::new(REKOR_URL);
let query = SearchLogQuery {
entries: vec![],
entry_uui_ds: vec![],
log_indexes: vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
};
let response = client.search_log_query(&query).await;
assert!(response.is_ok(), "{:?}", response.unwrap_err());
assert_eq!(response.unwrap().len(), 10);
}
#[test]
fn test_proposed_entry_deserialize_hashedrekord() {
let raw = r#"{"apiVersion":"0.0.1","kind":"hashedrekord","spec":{"data":{"hash":{"algorithm":"sha256","value":"135c891df9b15e7f79cc5173b46d0d1ec66dc889ff95e3ffd5cfd0bf669bef9f"}},"signature":{"content":"MEYCIQDUXfS70qVCqBo2oQIE1Rtkupe68OTCDPyfsAOXjY23mAIhAOrqQ4xP8mZj9g2lwvmYCOEtZR2vq8rAeDqdKnmHmPOb","publicKey":{"content":"LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUcrRENDQm4rZ0F3SUJBZ0lVRnRPNDJHd3lRcW5TNU8valdtQTVxY01RTU1Fd0NnWUlLb1pJemowRUF3TXcKTnpFVk1CTUdBMVVFQ2hNTWMybG5jM1J2Y21VdVpHVjJNUjR3SEFZRFZRUURFeFZ6YVdkemRHOXlaUzFwYm5SbApjbTFsWkdsaGRHVXdIaGNOTWpRd05ERTVNREF5TlRReldoY05NalF3TkRFNU1EQXpOVFF6V2pBQU1Ga3dFd1lICktvWkl6ajBDQVFZSUtvWkl6ajBEQVFjRFFnQUV4elN2Zis4MXExamRraVBSelYvYTl0QW1ER2kyTi9sMkNiMVIKbHJsTW14U2ZwNjdzdGd5aWVFRFdTR0FpYy9RUEZpcWQvVkFOYzdwVCtqcG54cEZxV2FPQ0JaNHdnZ1dhTUE0RwpBMVVkRHdFQi93UUVBd0lIZ0RBVEJnTlZIU1VFRERBS0JnZ3JCZ0VGQlFjREF6QWRCZ05WSFE0RUZnUVV0UGZ4CmRCeUpTM3dGbXZ6cUgyaVpqdWNiRXdvd0h3WURWUjBqQkJnd0ZvQVUzOVBwejFZa0VaYjVxTmpwS0ZXaXhpNFkKWkQ4d2FBWURWUjBSQVFIL0JGNHdYSVphYUhSMGNITTZMeTluYVhSb2RXSXVZMjl0TDJOb1lXbHVaM1ZoY21RdAphVzFoWjJWekwybHRZV2RsY3k4dVoybDBhSFZpTDNkdmNtdG1iRzkzY3k5eVpXeGxZWE5sTG5saGJXeEFjbVZtCmN5O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