Skip to content

Seems metadata needs to be prefixed with x-ms-meta- because of strip_prefix() #2289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
benjaminch opened this issue Mar 6, 2025 · 2 comments
Closed
3 tasks done
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Previous Versions Work related to older, unsupported SDKs question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Storage Storage Service (Queues, Blobs, Files)

Comments

@benjaminch
Copy link

Bug Title

impl From<&Headers> for Metadata seems to require header keys to be prefixed with x-ms-meta-

Crate Name

azure_storage

Crate Version

0.21.0

Description

While trying to add metadata to a storage container using Headers, it seems that any header keys not starting with x-ms-meta- are not add populated into Metadata in impl From<&Headers> for Metadata.

Crate code:

impl From<&Headers> for Metadata {
    fn from(header_map: &Headers) -> Self {
        let mut metadata = Metadata::new();
        header_map.iter().for_each(|(name, value)| {
            let name = name.as_str();
            let value = value.as_str();
            if let Some(name) = name.strip_prefix("x-ms-meta-") {
                metadata.insert(name.to_owned(), value.to_owned());
            }
        });

        metadata
    }
}

reference:

if let Some(name) = name.strip_prefix("x-ms-meta-") {

I am not sure whether it's bug or expected behavior? But strip_prefix("x-ms-meta-") returns None if input doesn't contain the prefix.
I would assume this code is just meant to strip this prefix if exists otherwise uses the key as is as it's done / possible via UI:

Image

If this behavior is not expected, I would suggest to change impl From<&Headers> for Metadata implementation to this one:

impl From<&Headers> for Metadata {
    fn from(header_map: &Headers) -> Self {
        let mut metadata = Metadata::new();
        header_map.iter().for_each(|(name, value)| {
            let name = name.as_str();
            let value = value.as_str();
-            if let Some(name) = name.strip_prefix("x-ms-meta-") {
+            if let Some(name) = name.strip_prefix("x-ms-meta-").or_else(|| name) {
                metadata.insert(name.to_owned(), value.to_owned());
            }
        });

        metadata
    }
}

Happy to send a PR to fix this one if you consider it to be a bug.

Steps to Reproduce

Here's the code to reproduce the issue:

  1. Execute the following code, creating a bucket with metadata not prefixed with "x-ms-meta-":
let client_builder = ClientBuilder::new("your-account", StorageCredentials::access_key("account".to_string(), "access-key".to_string()));

let client = client_builder.client();
let container_client = client
        .cloud_location(CloudLocation::Public {account: "your-account"})
        .container_client("a-test-bucket");

let mut metadata = HashMap::new();
metadata.insert(
    HeaderName::from("label-1"),
    HeaderValue::from("label-1-value"),
);
metadata.insert(
    HeaderName::from("label-2"),
    HeaderValue::from("label-2-value"),
);

container_client
    .create()
    .metadata(&Headers::from(metadata))
    .into_future().await?
  1. Check the bucket metadata in UI, there will be nothing.
  2. Execute the following code creating another bucket with metadata prefixed with "x-ms-meta-":
let client_builder = ClientBuilder::new("your-account", StorageCredentials::access_key("account".to_string(), "access-key".to_string()));

let client = client_builder.client();
let container_client = client
        .cloud_location(CloudLocation::Public {account: "your-account"})
        .container_client("a-test-bucket");

let mut metadata = HashMap::new();
metadata.insert(
    HeaderName::from("x-ms-meta-label-1"),
    HeaderValue::from("label-1-value"),
);
metadata.insert(
    HeaderName::from("x-ms-meta-label-2"),
    HeaderValue::from("label-2-value"),
);

container_client
    .create()
    .metadata(&Headers::from(metadata))
    .into_future().await?
  1. Check the bucket metadata in UI, there will be metadata populated properly as label-1 and label-2.

Checklist

@github-project-automation github-project-automation bot moved this to Untriaged in Azure SDK Rust Mar 6, 2025
@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 6, 2025
@RickWinter RickWinter added the Storage Storage Service (Queues, Blobs, Files) label Mar 6, 2025
@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Mar 6, 2025
@RickWinter RickWinter changed the title [Storage] seems metadata needs to be prefixed with x-ms-meta- because of strip_prefix() Seems metadata needs to be prefixed with x-ms-meta- because of strip_prefix() Mar 6, 2025
@vincenttran-msft
Copy link
Member

Hi @benjaminch BenjaminCh, thanks for bringing this issue to our attention. We are currently underway with active development of the replacement Storage SDK crate, and this issue has since been resolved. With that being said, we dropped support for the legacy branch, and so no further updates will be released. Sorry for the inconvenience, but please be on the lookout for the updated Storage crate! Thanks!

@vincenttran-msft vincenttran-msft added the Previous Versions Work related to older, unsupported SDKs label Mar 21, 2025
@github-actions github-actions bot added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Mar 21, 2025
@vincenttran-msft vincenttran-msft closed this as not planned Won't fix, can't repro, duplicate, stale Mar 21, 2025
@benjaminch
Copy link
Author

Thanks @vincenttran-msft !
Just to be sure, how should I use the new crate instead of the legacy one? Can you point me toward the new crate?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Previous Versions Work related to older, unsupported SDKs question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

No branches or pull requests

3 participants