diff --git a/async-nats/src/jetstream/object_store/mod.rs b/async-nats/src/jetstream/object_store/mod.rs index 2658bfc11..eb70c3991 100644 --- a/async-nats/src/jetstream/object_store/mod.rs +++ b/async-nats/src/jetstream/object_store/mod.rs @@ -12,7 +12,7 @@ // limitations under the License. //! Object Store module -use std::collections::VecDeque; +use std::collections::{HashMap, VecDeque}; use std::fmt::Display; use std::{cmp, str::FromStr, task::Poll, time::Duration}; @@ -358,6 +358,8 @@ impl ObjectStore { digest: Some(format!("SHA-256={}", URL_SAFE.encode(digest))), modified: Some(OffsetDateTime::now_utc()), deleted: false, + metadata: object_meta.metadata, + headers: object_meta.headers, }; let mut headers = HeaderMap::new(); @@ -722,6 +724,8 @@ impl ObjectStore { modified: Some(OffsetDateTime::now_utc()), digest: None, deleted: false, + metadata: HashMap::default(), + headers: None, }; publish_meta(self, &info).await?; Ok(info) @@ -785,6 +789,8 @@ impl ObjectStore { modified: Some(OffsetDateTime::now_utc()), digest: None, deleted: false, + metadata: HashMap::default(), + headers: None, }; publish_meta(self, &info).await?; Ok(info) @@ -1072,6 +1078,12 @@ pub struct ObjectInfo { /// A short human readable description of the object. #[serde(default)] pub description: Option, + /// Metadata for given object. + #[serde(default)] + pub metadata: HashMap, + /// Headers for given object. + #[serde(default)] + pub headers: Option, /// Link this object points to, if any. #[serde(default)] pub options: Option, @@ -1127,6 +1139,10 @@ pub struct ObjectMetadata { pub description: Option, /// Max chunk size. Default is 128k. pub chunk_size: Option, + /// Metadata for given object. + pub metadata: HashMap, + /// Headers for given object. + pub headers: Option, } impl From<&str> for ObjectMetadata { @@ -1158,6 +1174,8 @@ impl From for ObjectMetadata { ObjectMetadata { name: info.name, description: info.description, + metadata: info.metadata, + headers: info.headers, chunk_size: None, } } diff --git a/async-nats/tests/object_store.rs b/async-nats/tests/object_store.rs index c80964ece..4d319a07a 100644 --- a/async-nats/tests/object_store.rs +++ b/async-nats/tests/object_store.rs @@ -12,11 +12,14 @@ // limitations under the License. mod object_store { - use std::{io, time::Duration}; - - use async_nats::jetstream::{ - object_store::{AddLinkErrorKind, ObjectMetadata, UpdateMetadata}, - stream::DirectGetErrorKind, + use std::{collections::HashMap, io, time::Duration}; + + use async_nats::{ + jetstream::{ + object_store::{AddLinkErrorKind, ObjectMetadata, UpdateMetadata}, + stream::DirectGetErrorKind, + }, + HeaderMap, }; use base64::Engine; use futures::StreamExt; @@ -88,6 +91,7 @@ mod object_store { name: "BAR".to_string(), description: Some("custom object".to_string()), chunk_size: Some(64 * 1024), + ..Default::default() }, &mut bytes.as_slice(), ) @@ -217,8 +221,21 @@ mod object_store { .await .unwrap(); + let metadata = HashMap::from([("foo".to_string(), "bar".to_string())]); + let mut headers = HeaderMap::new(); + headers.append("foo", "bar"); + bucket - .put("FOO", &mut io::Cursor::new(vec![2, 3, 4, 5])) + .put( + ObjectMetadata { + name: "FOO".to_string(), + description: Some("description".to_string()), + chunk_size: None, + metadata: metadata.clone(), + headers: Some(headers.clone()), + }, + &mut io::Cursor::new(vec![2, 3, 4, 5]), + ) .await .unwrap(); @@ -228,6 +245,8 @@ mod object_store { assert_eq!(info.name, "FOO"); assert_eq!(info.bucket, "bucket"); assert_eq!(info.size, 4); + assert_eq!(info.metadata, metadata); + assert_eq!(info.headers, Some(headers)); assert!(!info.deleted); let modified = info.modified; @@ -375,6 +394,7 @@ mod object_store { name: "Foo".to_string(), description: Some("foo desc".to_string()), chunk_size: None, + ..Default::default() }, &mut "dadada".as_bytes(), )