Skip to content

[Storage] start_copy_from_url for BlobClient, set_properties for BlobServiceClient #2662

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/storage/assets.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "rust",
"Tag": "rust/azure_storage_blob_231754d877",
"Tag": "rust/azure_storage_blob_5c826b7898",
"TagPrefix": "rust/azure_storage_blob"
}
25 changes: 22 additions & 3 deletions sdk/storage/azure_storage_blob/src/clients/blob_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
use crate::{
generated::clients::BlobClient as GeneratedBlobClient,
generated::models::{
BlobClientDownloadResult, BlobClientGetPropertiesResult,
BlobClientDownloadResult, BlobClientGetPropertiesResult, BlobClientStartCopyFromUrlResult,
BlockBlobClientCommitBlockListResult, BlockBlobClientStageBlockResult,
BlockBlobClientUploadResult,
},
models::{
AccessTier, BlobClientDeleteOptions, BlobClientDownloadOptions,
BlobClientGetPropertiesOptions, BlobClientSetMetadataOptions,
BlobClientSetPropertiesOptions, BlobClientSetTierOptions,
BlockBlobClientCommitBlockListOptions, BlockBlobClientUploadOptions, BlockList,
BlockListType, BlockLookupList,
BlobClientStartCopyFromUrlOptions, BlockBlobClientCommitBlockListOptions,
BlockBlobClientUploadOptions, BlockList, BlockListType, BlockLookupList,
},
pipeline::StorageHeadersPolicy,
BlobClientOptions, BlockBlobClient,
Expand Down Expand Up @@ -211,4 +211,23 @@ impl BlobClient {
) -> Result<Response<()>> {
self.client.set_tier(tier, options).await
}

/// Copies a blob or an internet resource to a new blob.
///
/// # Arguments
///
/// * `copy_source` - A URL of up to 2 KB in length that specifies a file or blob.
/// The value should be URL-encoded as it would appear in a request URI.
/// If the source is in another account, the source must either be public
/// or must be authenticated via a shared access signature. If the source
/// is public, no authentication is required.
/// Example: https://myaccount.blob.core.windows.net/mycontainer/myblob
/// * `options` - Optional configuration for the request.
pub async fn start_copy_from_url(
&self,
copy_source: String,
options: Option<BlobClientStartCopyFromUrlOptions<'_>>,
) -> Result<Response<BlobClientStartCopyFromUrlResult>> {
self.client.start_copy_from_url(copy_source, options).await
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

use crate::{
generated::clients::BlobServiceClient as GeneratedBlobServiceClient,
models::{BlobServiceClientGetPropertiesOptions, StorageServiceProperties},
models::{
BlobServiceClientGetPropertiesOptions, BlobServiceClientSetPropertiesOptions,
StorageServiceProperties,
},
pipeline::StorageHeadersPolicy,
BlobContainerClient, BlobServiceClientOptions,
};
use azure_core::{
credentials::TokenCredential,
http::{
policies::{BearerTokenCredentialPolicy, Policy},
Response, Url,
RequestContent, Response, Url,
},
Result,
};
Expand Down Expand Up @@ -89,4 +92,20 @@ impl BlobServiceClient {
) -> Result<Response<StorageServiceProperties>> {
self.client.get_properties(options).await
}

/// Sets properties for a storage account's Blob service endpoint, including properties for Storage Analytics and CORS rules.
///
/// # Arguments
///
/// * `storage_service_properties` - The Storage service properties to set.
/// * `options` - Optional configuration for the request.
pub async fn set_properties(
&self,
storage_service_properties: RequestContent<StorageServiceProperties>,
options: Option<BlobServiceClientSetPropertiesOptions<'_>>,
) -> Result<Response<()>> {
self.client
.set_properties(storage_service_properties, options)
.await
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions sdk/storage/azure_storage_blob/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ pub mod models {
BlobClientDownloadResult, BlobClientDownloadResultHeaders, BlobClientGetPropertiesOptions,
BlobClientGetPropertiesResult, BlobClientGetPropertiesResultHeaders,
BlobClientSetMetadataOptions, BlobClientSetPropertiesOptions, BlobClientSetTierOptions,
BlobClientStartCopyFromUrlOptions, BlobClientStartCopyFromUrlResultHeaders,
BlobContainerClientCreateOptions, BlobContainerClientDeleteOptions,
BlobContainerClientGetPropertiesOptions, BlobContainerClientGetPropertiesResult,
BlobContainerClientGetPropertiesResultHeaders,
BlobContainerClientListBlobFlatSegmentOptions, BlobContainerClientSetMetadataOptions,
BlobImmutabilityPolicyMode, BlobServiceClientGetPropertiesOptions, BlobType,
BlockBlobClientCommitBlockListOptions, BlockBlobClientCommitBlockListResult,
BlockBlobClientGetBlockListOptions, BlockBlobClientStageBlockOptions,
BlockBlobClientStageBlockResult, BlockBlobClientUploadOptions, BlockBlobClientUploadResult,
BlockList, BlockListType, BlockLookupList, CopyStatus, LeaseState, LeaseStatus,
ListBlobsFlatSegmentResponse, PublicAccessType, RehydratePriority,
StorageServiceProperties,
BlobImmutabilityPolicyMode, BlobServiceClientGetPropertiesOptions,
BlobServiceClientSetPropertiesOptions, BlobType, BlockBlobClientCommitBlockListOptions,
BlockBlobClientCommitBlockListResult, BlockBlobClientGetBlockListOptions,
BlockBlobClientStageBlockOptions, BlockBlobClientStageBlockResult,
BlockBlobClientUploadOptions, BlockBlobClientUploadResult, BlockList, BlockListType,
BlockLookupList, CopyStatus, LeaseState, LeaseStatus, ListBlobsFlatSegmentResponse,
PublicAccessType, RehydratePriority, StorageServiceProperties,
};
}
70 changes: 68 additions & 2 deletions sdk/storage/azure_storage_blob/tests/blob_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use azure_core::{
use azure_core_test::{recorded, TestContext};
use azure_storage_blob::models::{
AccessTier, BlobClientDownloadResultHeaders, BlobClientGetPropertiesResultHeaders,
BlobClientSetMetadataOptions, BlobClientSetPropertiesOptions, BlockBlobClientUploadOptions,
LeaseState,
BlobClientSetMetadataOptions, BlobClientSetPropertiesOptions,
BlobClientStartCopyFromUrlResultHeaders, BlockBlobClientUploadOptions, CopyStatus, LeaseState,
};
use azure_storage_blob_test::{create_test_blob, get_blob_name, get_container_client};
use std::{collections::HashMap, error::Error};
Expand Down Expand Up @@ -276,3 +276,69 @@ async fn test_set_access_tier(ctx: TestContext) -> Result<(), Box<dyn Error>> {
container_client.delete_container(None).await?;
Ok(())
}

#[recorded::test]
async fn test_start_copy_from_url(ctx: TestContext) -> Result<(), Box<dyn Error>> {
// Recording Setup
let recording = ctx.recording();
let container_client = get_container_client(recording, true).await?;
let source_blob_client = container_client.blob_client(get_blob_name(recording));
create_test_blob(&source_blob_client).await?;

let blob_client = container_client.blob_client("destination_blob".to_string());
let source_url = format!(
"{}{}/{}",
source_blob_client.endpoint().as_str(),
source_blob_client.container_name(),
source_blob_client.blob_name()
);
let response = blob_client.start_copy_from_url(source_url, None).await?;
let (_, _, source_content) = source_blob_client.download(None).await?.deconstruct();
let (_, _, copied_content) = blob_client.download(None).await?.deconstruct();

// Assert
let copy_status = response.copy_status()?;
let copy_id = response.copy_id()?;
assert_eq!(CopyStatus::Success, copy_status.unwrap());
assert!(copy_id.is_some());
assert_eq!(
source_content.collect().await?,
copied_content.collect().await?
);

container_client.delete_container(None).await?;
Ok(())
}

#[recorded::test]
async fn test_start_copy_from_url2(ctx: TestContext) -> Result<(), Box<dyn Error>> {
// Recording Setup
let recording = ctx.recording();
let container_client = get_container_client(recording, true).await?;
let source_blob_client = container_client.blob_client(get_blob_name(recording));
create_test_blob(&source_blob_client).await?;

let blob_client = container_client.blob_client("destination_blob".to_string());
let source_url = format!(
"{}{}/{}",
source_blob_client.endpoint().as_str(),
source_blob_client.container_name(),
source_blob_client.blob_name()
);
let response = blob_client.start_copy_from_url(source_url, None).await?;
let (_, _, source_content) = source_blob_client.download(None).await?.deconstruct();
let (_, _, copied_content) = blob_client.download(None).await?.deconstruct();

// Assert
let copy_status = response.copy_status()?;
let copy_id = response.copy_id()?;
assert_eq!(CopyStatus::Success, copy_status.unwrap());
assert!(copy_id.is_some());
assert_eq!(
source_content.collect().await?,
copied_content.collect().await?
);

container_client.delete_container(None).await?;
Ok(())
}
27 changes: 26 additions & 1 deletion sdk/storage/azure_storage_blob/tests/blob_service_client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

use azure_core::http::RequestContent;
use azure_core_test::{recorded, TestContext};
use azure_storage_blob::models::BlobServiceClientGetPropertiesOptions;
use azure_storage_blob::models::{BlobServiceClientGetPropertiesOptions, StorageServiceProperties};
use azure_storage_blob_test::get_blob_service_client;
use std::error::Error;

Expand All @@ -22,3 +23,27 @@ async fn test_get_service_properties(ctx: TestContext) -> Result<(), Box<dyn Err
assert!(hour_metrics.is_some());
Ok(())
}

#[recorded::test]
async fn test_set_service_properties(ctx: TestContext) -> Result<(), Box<dyn Error>> {
// Recording Setup
let recording = ctx.recording();
let service_client = get_blob_service_client(recording)?;

// Storage Service Properties
let storage_service_properties = StorageServiceProperties {
default_service_version: Some("2022-11-02".to_string()),
..Default::default()
};
let request_content: RequestContent<StorageServiceProperties> =
storage_service_properties.try_into()?;

service_client.set_properties(request_content, None).await?;

// Assert
let response = service_client.get_properties(None).await?;
let storage_service_properties = response.into_body().await?;
let default_service_version = storage_service_properties.default_service_version;
assert_eq!("2022-11-02".to_string(), default_service_version.unwrap());
Ok(())
}
2 changes: 1 addition & 1 deletion sdk/storage/azure_storage_blob/tsp-location.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
directory: specification/storage/Microsoft.BlobStorage
commit: a0463864e021c00771eb01510e2eecd800ad05e2
commit: f848853e5880d2b1e3375a6517aa59ada57d60d3
repo: Azure/azure-rest-api-specs
additionalDirectories:
Loading