commit 83cdfdaa6787b8bd6c900c13b48d53cd3efe088d
parent a680db2bd6d6a82398e361ee604ce639c24fdef6
Author: Gavin Peacock <gpeacock@adobe.com>
Date: Mon, 20 Jun 2022 12:14:56 -0700
(MINOR) Add asset attribute getters for manifest (#56)
* Add asset attribute getters for manifest
format, title, instance_id and thumbnail
make asset getter crate private
Co-authored-by: Dave Kozma <dkozma@adobe.com>
Co-authored-by: Dave Kozma <dkozma@adobe.com>
Diffstat:
4 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/sdk/examples/client/client.rs b/sdk/examples/client/client.rs
@@ -30,15 +30,13 @@ fn show_manifest(manifest_store: &ManifestStore, manifest_label: &str, level: us
println!("{}manifest_label: {}", indent, manifest_label);
if let Some(manifest) = manifest_store.get(manifest_label) {
- if let Some(asset) = manifest.asset().as_ref() {
- println!(
- "{}title: {} , format: {}, instance_id: {}",
- indent,
- asset.title(),
- asset.format(),
- asset.instance_id()
- );
- }
+ println!(
+ "{}title: {} , format: {}, instance_id: {}",
+ indent,
+ manifest.title().unwrap_or_default(),
+ manifest.format(),
+ manifest.instance_id()
+ );
for assertion in manifest.assertions().iter() {
println!("{}", assertion.label_with_instance());
diff --git a/sdk/src/ingredient.rs b/sdk/src/ingredient.rs
@@ -200,7 +200,7 @@ impl Ingredient {
self.manifest_data.as_deref()
}
- /// Sets a human-readable title for this manifest.
+ /// Sets a human-readable title for this ingredient.
pub fn set_title<S: Into<String>>(&mut self, title: S) -> &mut Self {
self.title = title.into();
self
diff --git a/sdk/src/manifest.rs b/sdk/src/manifest.rs
@@ -94,8 +94,30 @@ impl Manifest {
self.claim_generator.as_str()
}
+ /// Returns a MIME content_type for the asset associated with this manifest.
+ pub fn format(&self) -> &str {
+ self.asset().map(|asset| asset.format()).unwrap_or_default()
+ }
+
+ /// Returns the instance identifier.
+ pub fn instance_id(&self) -> &str {
+ self.asset()
+ .map(|asset| asset.instance_id())
+ .unwrap_or_default()
+ }
+
+ /// Returns a user-displayable title for this manifest
+ pub fn title(&self) -> Option<&str> {
+ self.asset().map(|asset| asset.title())
+ }
+
+ /// Returns a tuple with thumbnail format and image bytes or `None`.
+ pub fn thumbnail(&self) -> Option<(&str, &[u8])> {
+ self.asset().and_then(|asset| asset.thumbnail())
+ }
+
/// Returns an [Ingredient] reference to the asset associated with this manifest
- pub fn asset(&self) -> Option<&Ingredient> {
+ pub(crate) fn asset(&self) -> Option<&Ingredient> {
self.asset.as_ref()
}
@@ -727,6 +749,10 @@ pub(crate) mod tests {
.embed(&source_path, &test_output, &signer)
.expect("embed");
+ assert_eq!(manifest.format(), "image/jpeg");
+ assert_eq!(manifest.title(), Some("wc_embed_test.jpg"));
+ assert!(manifest.thumbnail().is_some());
+
let ingredient = Ingredient::from_file(&test_output).expect("load_from_asset");
assert!(ingredient.active_manifest().is_some());
}
diff --git a/sdk/tests/integration.rs b/sdk/tests/integration.rs
@@ -111,7 +111,7 @@ mod integration_1 {
assert!(manifest_store.get_active().is_some());
if let Some(manifest) = manifest_store.get_active() {
- assert!(manifest.asset().is_some());
+ assert!(manifest.title().is_some());
assert_eq!(manifest.ingredients().len(), 2);
} else {
panic!("no manifest in store");