-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mostly working, issue with generated get_block_list
- Loading branch information
1 parent
f1fe84f
commit 386879b
Showing
13 changed files
with
670 additions
and
75 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
sdk/storage/azure_storage_blob/src/clients/blob_service_client.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,66 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
use crate::{ | ||
clients::GeneratedBlobClient, | ||
models::{BlobServiceClientGetPropertiesOptions, StorageServiceProperties}, | ||
pipeline::StorageHeadersPolicy, | ||
BlobClientOptions, | ||
}; | ||
use azure_core::{ | ||
credentials::TokenCredential, BearerTokenCredentialPolicy, Policy, Response, Result, Url, | ||
}; | ||
use std::sync::Arc; | ||
|
||
pub struct BlobServiceClient { | ||
endpoint: Url, | ||
client: GeneratedBlobClient, | ||
} | ||
|
||
impl BlobServiceClient { | ||
pub fn new( | ||
endpoint: &str, | ||
credential: Arc<dyn TokenCredential>, | ||
options: Option<BlobClientOptions>, | ||
) -> Result<Self> { | ||
let mut options = options.unwrap_or_default(); | ||
|
||
let storage_headers_policy = Arc::new(StorageHeadersPolicy); | ||
options | ||
.client_options | ||
.per_call_policies | ||
.push(storage_headers_policy); | ||
|
||
let oauth_token_policy = BearerTokenCredentialPolicy::new( | ||
credential.clone(), | ||
["https://storage.azure.com/.default"], | ||
); | ||
options | ||
.client_options | ||
.per_try_policies | ||
.push(Arc::new(oauth_token_policy) as Arc<dyn Policy>); | ||
|
||
let client = GeneratedBlobClient::new(endpoint, credential, Some(options))?; | ||
|
||
Ok(Self { | ||
endpoint: endpoint.parse()?, | ||
client, | ||
}) | ||
} | ||
|
||
pub fn endpoint(&self) -> &Url { | ||
&self.endpoint | ||
} | ||
|
||
pub async fn get_service_properties( | ||
&self, | ||
options: Option<BlobServiceClientGetPropertiesOptions<'_>>, | ||
) -> Result<Response<StorageServiceProperties>> { | ||
let response = self | ||
.client | ||
.get_blob_service_client() | ||
.get_properties(options) | ||
.await?; | ||
Ok(response) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
sdk/storage/azure_storage_blob/src/models/container_properties.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
use azure_core::{ | ||
headers::{ | ||
FromHeaders, HeaderName, Headers, ETAG, HAS_IMMUTABILITY_POLICY, HAS_LEGAL_HOLD, | ||
LEASE_STATE, LEASE_STATUS, VERSION, | ||
}, | ||
Error, Etag, LeaseStatus, | ||
}; | ||
use typespec_client_core::fmt::SafeDebug; | ||
|
||
use crate::models::LeaseState; | ||
|
||
pub const LAST_MODIFIED: HeaderName = HeaderName::from_static("last-modified"); | ||
pub const IMMUTABLE_STORAGE_WITH_VERSIONING_ENABLED: HeaderName = | ||
HeaderName::from_static("x-ms-immutable-storage-with-versioning-enabled"); | ||
|
||
/// Properties of an Azure Storage container. | ||
/// | ||
#[derive(Clone, Default, SafeDebug)] | ||
pub struct ContainerProperties { | ||
pub last_modified: Option<String>, | ||
pub lease_state: Option<LeaseState>, | ||
pub lease_status: Option<LeaseStatus>, | ||
pub has_immutability_policy: Option<bool>, | ||
pub has_legal_hold: Option<bool>, | ||
pub immutable_storage_with_versioning_enabled: Option<String>, | ||
pub etag: Option<Etag>, | ||
pub version: Option<String>, | ||
} | ||
|
||
impl FromHeaders for ContainerProperties { | ||
type Error = Error; | ||
fn header_names() -> &'static [&'static str] { | ||
&[ | ||
"etag", | ||
"last-modified", | ||
"x-ms-lease-state", | ||
"x-ms-lease-status", | ||
"x-ms-immutable-storage-with-versioning-enabled", | ||
"x-ms-has-immutability-policy", | ||
"x-ms-version", | ||
"x-ms-has-legal-hold", | ||
] | ||
} | ||
|
||
fn from_headers(headers: &Headers) -> Result<Option<Self>, Error> { | ||
let mut properties = ContainerProperties { | ||
..Default::default() | ||
}; | ||
|
||
let last_modified = headers.get_optional_str(&LAST_MODIFIED); | ||
properties.last_modified = last_modified.map(|s| s.to_string()); | ||
|
||
let lease_state: Option<LeaseState> = headers.get_optional_as(&LEASE_STATE)?; | ||
properties.lease_state = lease_state; | ||
|
||
let lease_status: Option<LeaseStatus> = headers.get_optional_as(&LEASE_STATUS)?; | ||
properties.lease_status = lease_status; | ||
|
||
let has_immutability_policy: Option<bool> = | ||
headers.get_optional_as(&HAS_IMMUTABILITY_POLICY)?; | ||
properties.has_immutability_policy = has_immutability_policy; | ||
|
||
let has_legal_hold: Option<bool> = headers.get_optional_as(&HAS_LEGAL_HOLD)?; | ||
properties.has_legal_hold = has_legal_hold; | ||
|
||
let immutable_storage_with_versioning_enabled = | ||
headers.get_optional_str(&IMMUTABLE_STORAGE_WITH_VERSIONING_ENABLED); | ||
properties.immutable_storage_with_versioning_enabled = | ||
immutable_storage_with_versioning_enabled.map(|s| s.to_string()); | ||
|
||
let version = headers.get_optional_str(&VERSION); | ||
properties.version = version.map(|s| s.to_string()); | ||
|
||
let etag: Option<Etag> = headers.get_optional_as(&ETAG)?; | ||
properties.etag = etag; | ||
|
||
let last_modified = headers.get_optional_str(&LAST_MODIFIED); | ||
properties.last_modified = last_modified.map(|s| s.to_string()); | ||
|
||
let lease_state: Option<LeaseState> = headers.get_optional_as(&LEASE_STATE)?; | ||
properties.lease_state = lease_state; | ||
|
||
let lease_status: Option<LeaseStatus> = headers.get_optional_as(&LEASE_STATUS)?; | ||
properties.lease_status = lease_status; | ||
|
||
Ok(Some(properties)) | ||
} | ||
} |
Oops, something went wrong.