Skip to content

Commit

Permalink
add getaccountinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
microzchang committed Apr 24, 2024
1 parent 791e5e3 commit 59d451f
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,17 @@ namespace Azure { namespace Storage { namespace Blobs {
const SetBlobLegalHoldOptions& options = SetBlobLegalHoldOptions(),
const Azure::Core::Context& context = Azure::Core::Context()) const;

/**
* @brief Returns the sku name and account kind for the specified account.
*
* @param options Optional parameters to execute this function.
* @param context Context for cancelling long running operations.
* @return AccountInfo describing the account.
*/
Azure::Response<Models::AccountInfo> GetAccountInfo(
const GetAccountInfoOptions& options = GetAccountInfoOptions(),
const Azure::Core::Context& context = Azure::Core::Context()) const;

protected:
/** @brief Blob Url */
Azure::Core::Url m_blobUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,17 @@ namespace Azure { namespace Storage { namespace Blobs {
const SubmitBlobBatchOptions& options = SubmitBlobBatchOptions(),
const Core::Context& context = Core::Context()) const;

/**
* @brief Returns the sku name and account kind for the specified account.
*
* @param options Optional parameters to execute this function.
* @param context Context for cancelling long running operations.
* @return AccountInfo describing the account.
*/
Azure::Response<Models::AccountInfo> GetAccountInfo(
const GetAccountInfoOptions& options = GetAccountInfoOptions(),
const Azure::Core::Context& context = Azure::Core::Context()) const;

private:
Azure::Core::Url m_blobContainerUrl;
std::shared_ptr<Azure::Core::Http::_internal::HttpPipeline> m_pipeline;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,25 +655,6 @@ namespace Azure { namespace Storage { namespace Blobs {
private:
std::string m_value;
};
/**
* @brief Response type for #Azure::Storage::Blobs::BlobServiceClient::GetAccountInfo.
*/
struct AccountInfo final
{
/**
* Identifies the sku name of the account.
*/
Models::SkuName SkuName;
/**
* Identifies the account kind.
*/
Models::AccountKind AccountKind;
/**
* Version 2019-07-07 and newer. Indicates if the account has a hierarchical namespace
* enabled.
*/
bool IsHierarchicalNamespaceEnabled = bool();
};
/**
* @brief Blob info from a Filter Blobs API call.
*/
Expand Down Expand Up @@ -2400,6 +2381,25 @@ namespace Azure { namespace Storage { namespace Blobs {
struct SetBlobAccessTierResult final
{
};
/**
* @brief Response type for #Azure::Storage::Blobs::BlobServiceClient::GetAccountInfo.
*/
struct AccountInfo final
{
/**
* Identifies the sku name of the account.
*/
Models::SkuName SkuName;
/**
* Identifies the account kind.
*/
Models::AccountKind AccountKind;
/**
* Version 2019-07-07 and newer. Indicates if the account has a hierarchical namespace
* enabled.
*/
bool IsHierarchicalNamespaceEnabled = bool();
};
namespace _detail {
/**
* @brief Required. The type of the provided query expression.
Expand Down Expand Up @@ -3664,6 +3664,14 @@ namespace Azure { namespace Storage { namespace Blobs {
const Core::Url& url,
const ListBlobContainerBlobsByHierarchyOptions& options,
const Core::Context& context);
struct GetBlobContainerAccountInfoOptions final
{
};
static Response<Models::AccountInfo> GetAccountInfo(
Core::Http::_internal::HttpPipeline& pipeline,
const Core::Url& url,
const GetBlobContainerAccountInfoOptions& options,
const Core::Context& context);
};
class BlobClient final {
public:
Expand Down Expand Up @@ -3986,6 +3994,14 @@ namespace Azure { namespace Storage { namespace Blobs {
const Core::Url& url,
const SetBlobTierOptions& options,
const Core::Context& context);
struct GetBlobAccountInfoOptions final
{
};
static Response<Models::AccountInfo> GetAccountInfo(
Core::Http::_internal::HttpPipeline& pipeline,
const Core::Url& url,
const GetBlobAccountInfoOptions& options,
const Core::Context& context);
struct QueryBlobOptions final
{
Models::_detail::QueryRequest QueryRequest;
Expand Down
10 changes: 10 additions & 0 deletions sdk/storage/azure-storage-blobs/src/blob_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,4 +896,14 @@ namespace Azure { namespace Storage { namespace Blobs {
return _detail::BlobClient::SetLegalHold(*m_pipeline, m_blobUrl, protocolLayerOptions, context);
}

Azure::Response<Models::AccountInfo> BlobClient::GetAccountInfo(
const GetAccountInfoOptions& options,
const Azure::Core::Context& context) const
{
(void)options;
_detail::BlobClient::GetBlobAccountInfoOptions protocolLayerOptions;
return _detail::BlobClient::GetAccountInfo(
*m_pipeline, m_blobUrl, protocolLayerOptions, _internal::WithReplicaStatus(context));
}

}}} // namespace Azure::Storage::Blobs
13 changes: 13 additions & 0 deletions sdk/storage/azure-storage-blobs/src/blob_container_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,17 @@ namespace Azure { namespace Storage { namespace Blobs {
return Azure::Response<Models::SubmitBlobBatchResult>(
Models::SubmitBlobBatchResult(), std::move(response.RawResponse));
}

Azure::Response<Models::AccountInfo> BlobContainerClient::GetAccountInfo(
const GetAccountInfoOptions& options,
const Azure::Core::Context& context) const
{
(void)options;
_detail::BlobContainerClient::GetBlobContainerAccountInfoOptions protocolLayerOptions;
return _detail::BlobContainerClient::GetAccountInfo(
*m_pipeline,
m_blobContainerUrl,
protocolLayerOptions,
_internal::WithReplicaStatus(context));
}
}}} // namespace Azure::Storage::Blobs
50 changes: 50 additions & 0 deletions sdk/storage/azure-storage-blobs/src/rest_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3597,6 +3597,31 @@ namespace Azure { namespace Storage { namespace Blobs {
return Response<Models::_detail::ListBlobsByHierarchyResult>(
std::move(response), std::move(pRawResponse));
}
Response<Models::AccountInfo> BlobContainerClient::GetAccountInfo(
Core::Http::_internal::HttpPipeline& pipeline,
const Core::Url& url,
const GetBlobContainerAccountInfoOptions& options,
const Core::Context& context)
{
auto request = Core::Http::Request(Core::Http::HttpMethod::Get, url);
request.GetUrl().AppendQueryParameter("restype", "account");
request.GetUrl().AppendQueryParameter("comp", "properties");
request.SetHeader("x-ms-version", "2023-11-03");
(void)options;
auto pRawResponse = pipeline.Send(request, context);
auto httpStatusCode = pRawResponse->GetStatusCode();
if (httpStatusCode != Core::Http::HttpStatusCode::Ok)
{
throw StorageException::CreateFromResponse(std::move(pRawResponse));
}
Models::AccountInfo response;
response.SkuName = Models::SkuName(pRawResponse->GetHeaders().at("x-ms-sku-name"));
response.AccountKind
= Models::AccountKind(pRawResponse->GetHeaders().at("x-ms-account-kind"));
response.IsHierarchicalNamespaceEnabled
= pRawResponse->GetHeaders().at("x-ms-is-hns-enabled") == std::string("true");
return Response<Models::AccountInfo>(std::move(response), std::move(pRawResponse));
}
Response<Models::DownloadBlobResult> BlobClient::Download(
Core::Http::_internal::HttpPipeline& pipeline,
const Core::Url& url,
Expand Down Expand Up @@ -5295,6 +5320,31 @@ namespace Azure { namespace Storage { namespace Blobs {
return Response<Models::SetBlobAccessTierResult>(
std::move(response), std::move(pRawResponse));
}
Response<Models::AccountInfo> BlobClient::GetAccountInfo(
Core::Http::_internal::HttpPipeline& pipeline,
const Core::Url& url,
const GetBlobAccountInfoOptions& options,
const Core::Context& context)
{
auto request = Core::Http::Request(Core::Http::HttpMethod::Get, url);
request.GetUrl().AppendQueryParameter("restype", "account");
request.GetUrl().AppendQueryParameter("comp", "properties");
request.SetHeader("x-ms-version", "2023-11-03");
(void)options;
auto pRawResponse = pipeline.Send(request, context);
auto httpStatusCode = pRawResponse->GetStatusCode();
if (httpStatusCode != Core::Http::HttpStatusCode::Ok)
{
throw StorageException::CreateFromResponse(std::move(pRawResponse));
}
Models::AccountInfo response;
response.SkuName = Models::SkuName(pRawResponse->GetHeaders().at("x-ms-sku-name"));
response.AccountKind
= Models::AccountKind(pRawResponse->GetHeaders().at("x-ms-account-kind"));
response.IsHierarchicalNamespaceEnabled
= pRawResponse->GetHeaders().at("x-ms-is-hns-enabled") == std::string("true");
return Response<Models::AccountInfo>(std::move(response), std::move(pRawResponse));
}
Response<Models::QueryBlobResult> BlobClient::Query(
Core::Http::_internal::HttpPipeline& pipeline,
const Core::Url& url,
Expand Down
38 changes: 22 additions & 16 deletions sdk/storage/azure-storage-blobs/swagger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ directive:
- from: swagger-document
where: $["x-ms-paths"]
transform: >
delete $["/{containerName}?restype=account&comp=properties"];
delete $["/{containerName}/{blob}?restype=account&comp=properties"];
delete $["/{filesystem}/{path}?action=setAccessControl&blob"];
delete $["/{filesystem}/{path}?action=getAccessControl&blob"];
delete $["/{filesystem}/{path}?FileRename"];
Expand Down Expand Up @@ -673,22 +671,30 @@ directive:
```yaml
directive:
- from: swagger-document
where: $["x-ms-paths"]["/?restype=account&comp=properties"].get.responses["200"]
transform: >
$.schema = {"$ref": "#/definitions/AccountInfo"};
- from: swagger-document
where: $["x-ms-paths"]["/?restype=account&comp=properties"].get.responses["200"].headers["x-ms-sku-name"]
where: $
transform: >
$["x-ms-enum"]["values"] = [
{"value": "Standard_LRS", "name":"Standard_Lrs"},
{"value": "Standard_GRS", "name":"StandardGrs"},
{"value": "Standard_RAGRS", "name":"StandardRagrs"},
{"value": "Standard_ZRS", "name":"StandardZrs"},
{"value": "Premium_LRS", "name":"PremiumLrs"},
{"value": "Premium_ZRS", "name":"PremiumZrs"},
{"value": "Standard_GZRS", "name":"StandardGzrs"},
{"value": "Standard_RAGZRS", "name":"StandardRagzrs"}
const operations = [
"Service_GetAccountInfo",
"BlobContainer_GetAccountInfo",
"Blob_GetAccountInfo",
];
for (const url in $["x-ms-paths"]) {
for (const verb in $["x-ms-paths"][url]) {
if (!operations.includes($["x-ms-paths"][url][verb].operationId)) continue;
const operation = $["x-ms-paths"][url][verb];
operation.responses["200"].schema = {"$ref": "#/definitions/AccountInfo"};
operation.responses["200"].headers["x-ms-sku-name"]["x-ms-enum"]["values"] = [
{"value": "Standard_LRS", "name":"Standard_Lrs"},
{"value": "Standard_GRS", "name":"StandardGrs"},
{"value": "Standard_RAGRS", "name":"StandardRagrs"},
{"value": "Standard_ZRS", "name":"StandardZrs"},
{"value": "Premium_LRS", "name":"PremiumLrs"},
{"value": "Premium_ZRS", "name":"PremiumZrs"},
{"value": "Standard_GZRS", "name":"StandardGzrs"},
{"value": "Standard_RAGZRS", "name":"StandardRagzrs"}
];
}
}
```
### FindBlobsByTags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1493,4 +1493,14 @@ namespace Azure { namespace Storage { namespace Test {
EXPECT_EQ(e.ErrorCode, "BlobNotFound");
}
}

TEST_F(BlobContainerClientTest, AccountInfo_LIVEONLY_)
{
auto containerClient = *m_blobContainerClient;

auto accountInfo = containerClient.GetAccountInfo().Value;
EXPECT_FALSE(accountInfo.SkuName.ToString().empty());
EXPECT_FALSE(accountInfo.AccountKind.ToString().empty());
EXPECT_FALSE(accountInfo.IsHierarchicalNamespaceEnabled);
}
}}} // namespace Azure::Storage::Test
10 changes: 10 additions & 0 deletions sdk/storage/azure-storage-blobs/test/ut/block_blob_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2074,4 +2074,14 @@ namespace Azure { namespace Storage { namespace Test {
= Blobs::BlockBlobClient(m_blockBlobClient->GetUrl(), credential, clientOptions);
EXPECT_THROW(blockBlobClient.GetProperties(), StorageException);
}

TEST_F(BlockBlobClientTest, AccountInfo_LIVEONLY_)
{
auto blobClient = *m_blockBlobClient;

auto accountInfo = blobClient.GetAccountInfo().Value;
EXPECT_FALSE(accountInfo.SkuName.ToString().empty());
EXPECT_FALSE(accountInfo.AccountKind.ToString().empty());
EXPECT_FALSE(accountInfo.IsHierarchicalNamespaceEnabled);
}
}}} // namespace Azure::Storage::Test

0 comments on commit 59d451f

Please sign in to comment.