Skip to content

Commit 1e013e5

Browse files
Storage/STG91 Move audience out of models namespace and add help function for audience (#5026)
* move audience out of models namespace * Update sdk/storage/azure-storage-queues/inc/azure/storage/queues/queue_options.hpp Co-authored-by: JinmingHu <jinmhu@microsoft.com> * Update sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/share_options.hpp Co-authored-by: JinmingHu <jinmhu@microsoft.com> * Update sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/datalake_options.hpp Co-authored-by: JinmingHu <jinmhu@microsoft.com> * add help func --------- Co-authored-by: JinmingHu <jinmhu@microsoft.com>
1 parent f0a379b commit 1e013e5

File tree

22 files changed

+219
-155
lines changed

22 files changed

+219
-155
lines changed

sdk/storage/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "cpp",
44
"TagPrefix": "cpp/storage",
5-
"Tag": "cpp/storage_1d2fb95162"
5+
"Tag": "cpp/storage_f9007be11f"
66
}

sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_options.hpp

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,42 @@
2121

2222
namespace Azure { namespace Storage { namespace Blobs {
2323

24-
namespace Models {
24+
/**
25+
* @brief Audiences available for blob service
26+
*
27+
*/
28+
class BlobAudience final : public Azure::Core::_internal::ExtendableEnumeration<BlobAudience> {
29+
public:
30+
/**
31+
* @brief Construct a new BlobAudience object
32+
*
33+
* @param blobAudience The Azure Active Directory audience to use when forming authorization
34+
* scopes. For the Language service, this value corresponds to a URL that identifies the Azure
35+
* cloud where the resource is located. For more information: See
36+
* https://learn.microsoft.com/en-us/azure/storage/blobs/authorize-access-azure-active-directory
37+
*/
38+
explicit BlobAudience(std::string blobAudience) : ExtendableEnumeration(std::move(blobAudience))
39+
{
40+
}
2541

2642
/**
27-
* @brief Audiences available for Blobs
43+
* @brief The service endpoint for a given storage account. Use this method to acquire a token
44+
* for authorizing requests to that specific Azure Storage account and service only.
2845
*
46+
* @param storageAccountName he storage account name used to populate the service endpoint.
47+
* @return The service endpoint for a given storage account.
2948
*/
30-
class BlobAudience final : public Azure::Core::_internal::ExtendableEnumeration<BlobAudience> {
31-
public:
32-
/**
33-
* @brief Construct a new BlobAudience object
34-
*
35-
* @param blobAudience The Azure Active Directory audience to use when forming authorization
36-
* scopes. For the Language service, this value corresponds to a URL that identifies the Azure
37-
* cloud where the resource is located. For more information: See
38-
* https://learn.microsoft.com/en-us/azure/storage/blobs/authorize-access-azure-active-directory
39-
*/
40-
explicit BlobAudience(std::string blobAudience)
41-
: ExtendableEnumeration(std::move(blobAudience))
42-
{
43-
}
49+
static BlobAudience CreateBlobServiceAccountAudience(const std::string& storageAccountName)
50+
{
51+
return BlobAudience("https://" + storageAccountName + ".blob.core.windows.net/");
52+
}
4453

45-
/**
46-
* @brief Default Audience. Use to acquire a token for authorizing requests to any Azure
47-
* Storage account.
48-
*/
49-
AZ_STORAGE_BLOBS_DLLEXPORT const static BlobAudience DefaultAudience;
50-
};
51-
} // namespace Models
54+
/**
55+
* @brief Default Audience. Use to acquire a token for authorizing requests to any Azure
56+
* Storage account.
57+
*/
58+
AZ_STORAGE_BLOBS_DLLEXPORT const static BlobAudience DefaultAudience;
59+
};
5260

5361
/**
5462
* @brief Specifies access conditions for a container.
@@ -198,10 +206,10 @@ namespace Azure { namespace Storage { namespace Blobs {
198206

199207
/**
200208
* The Audience to use for authentication with Azure Active Directory (AAD).
201-
* #Azure::Storage::Blobs::Models::BlobAudience::DefaultAudience will be assumed if Audience is
209+
* #Azure::Storage::Blobs::BlobAudience::DefaultAudience will be assumed if Audience is
202210
* not set.
203211
*/
204-
Azure::Nullable<Models::BlobAudience> Audience;
212+
Azure::Nullable<BlobAudience> Audience;
205213
};
206214

207215
/**

sdk/storage/azure-storage-blobs/src/blob_options.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
namespace Azure { namespace Storage { namespace Blobs {
77

8-
namespace Models {
9-
const BlobAudience BlobAudience::DefaultAudience(_internal::StorageDefaultAudience);
10-
} // namespace Models
8+
const BlobAudience BlobAudience::DefaultAudience(_internal::StorageDefaultAudience);
119

1210
BlobQueryInputTextOptions BlobQueryInputTextOptions::CreateCsvTextOptions(
1311
const std::string& recordSeparator,

sdk/storage/azure-storage-blobs/test/ut/bearer_token_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ namespace Azure { namespace Storage { namespace Test {
5151

5252
// With custom audience
5353
auto blobUrl = Azure::Core::Url(m_blockBlobClient->GetUrl());
54-
clientOptions.Audience
55-
= Blobs::Models::BlobAudience(blobUrl.GetScheme() + "://" + blobUrl.GetHost());
54+
clientOptions.Audience = Blobs::BlobAudience(blobUrl.GetScheme() + "://" + blobUrl.GetHost());
5655
blobClient = Blobs::BlobClient(
5756
m_blockBlobClient->GetUrl(),
5857
std::make_shared<Azure::Identity::ClientSecretCredential>(

sdk/storage/azure-storage-blobs/test/ut/blob_container_client_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,13 +1457,13 @@ namespace Azure { namespace Storage { namespace Test {
14571457
// custom audience
14581458
auto containerUrl = Azure::Core::Url(containerClient.GetUrl());
14591459
clientOptions.Audience
1460-
= Blobs::Models::BlobAudience(containerUrl.GetScheme() + "://" + containerUrl.GetHost());
1460+
= Blobs::BlobAudience(containerUrl.GetScheme() + "://" + containerUrl.GetHost());
14611461
containerClient
14621462
= Blobs::BlobContainerClient(m_blobContainerClient->GetUrl(), credential, clientOptions);
14631463
EXPECT_NO_THROW(containerClient.GetProperties());
14641464

14651465
// error audience
1466-
clientOptions.Audience = Blobs::Models::BlobAudience("https://disk.compute.azure.com");
1466+
clientOptions.Audience = Blobs::BlobAudience("https://disk.compute.azure.com");
14671467
containerClient
14681468
= Blobs::BlobContainerClient(m_blobContainerClient->GetUrl(), credential, clientOptions);
14691469
EXPECT_THROW(containerClient.GetProperties(), StorageException);

sdk/storage/azure-storage-blobs/test/ut/blob_service_client_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,13 @@ namespace Azure { namespace Storage { namespace Test {
515515
// custom audience
516516
auto serviceUrl = Azure::Core::Url(serviceClient.GetUrl());
517517
clientOptions.Audience
518-
= Blobs::Models::BlobAudience(serviceUrl.GetScheme() + "://" + serviceUrl.GetHost());
518+
= Blobs::BlobAudience(serviceUrl.GetScheme() + "://" + serviceUrl.GetHost());
519519
serviceClient
520520
= Blobs::BlobServiceClient(m_blobServiceClient->GetUrl(), credential, clientOptions);
521521
EXPECT_NO_THROW(serviceClient.GetProperties());
522522

523523
// error audience
524-
clientOptions.Audience = Blobs::Models::BlobAudience("https://disk.compute.azure.com");
524+
clientOptions.Audience = Blobs::BlobAudience("https://disk.compute.azure.com");
525525
serviceClient
526526
= Blobs::BlobServiceClient(m_blobServiceClient->GetUrl(), credential, clientOptions);
527527
EXPECT_THROW(serviceClient.GetProperties(), StorageException);

sdk/storage/azure-storage-blobs/test/ut/block_blob_client_test.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,26 +2041,35 @@ namespace Azure { namespace Storage { namespace Test {
20412041
EXPECT_NO_THROW(blockBlobClient.GetProperties());
20422042

20432043
// default audience
2044-
clientOptions.Audience = Blobs::Models::BlobAudience::DefaultAudience;
2044+
clientOptions.Audience = Blobs::BlobAudience::DefaultAudience;
2045+
blockBlobClient
2046+
= Blobs::BlockBlobClient(m_blockBlobClient->GetUrl(), credential, clientOptions);
2047+
EXPECT_NO_THROW(blockBlobClient.GetProperties());
2048+
2049+
// service audience
2050+
2051+
auto keyCredential
2052+
= _internal::ParseConnectionString(StandardStorageConnectionString()).KeyCredential;
2053+
auto accountName = keyCredential->AccountName;
2054+
clientOptions.Audience = Blobs::BlobAudience::CreateBlobServiceAccountAudience(accountName);
20452055
blockBlobClient
20462056
= Blobs::BlockBlobClient(m_blockBlobClient->GetUrl(), credential, clientOptions);
20472057
EXPECT_NO_THROW(blockBlobClient.GetProperties());
20482058

20492059
// custom audience
20502060
auto blobUrl = Azure::Core::Url(blockBlobClient.GetUrl());
2051-
clientOptions.Audience
2052-
= Blobs::Models::BlobAudience(blobUrl.GetScheme() + "://" + blobUrl.GetHost());
2061+
clientOptions.Audience = Blobs::BlobAudience(blobUrl.GetScheme() + "://" + blobUrl.GetHost());
20532062
blockBlobClient
20542063
= Blobs::BlockBlobClient(m_blockBlobClient->GetUrl(), credential, clientOptions);
20552064
EXPECT_NO_THROW(blockBlobClient.GetProperties());
20562065
clientOptions.Audience
2057-
= Blobs::Models::BlobAudience(blobUrl.GetScheme() + "://" + blobUrl.GetHost() + "/");
2066+
= Blobs::BlobAudience(blobUrl.GetScheme() + "://" + blobUrl.GetHost() + "/");
20582067
blockBlobClient
20592068
= Blobs::BlockBlobClient(m_blockBlobClient->GetUrl(), credential, clientOptions);
20602069
EXPECT_NO_THROW(blockBlobClient.GetProperties());
20612070

20622071
// error audience
2063-
clientOptions.Audience = Blobs::Models::BlobAudience("https://disk.compute.azure.com");
2072+
clientOptions.Audience = Blobs::BlobAudience("https://disk.compute.azure.com");
20642073
blockBlobClient
20652074
= Blobs::BlockBlobClient(m_blockBlobClient->GetUrl(), credential, clientOptions);
20662075
EXPECT_THROW(blockBlobClient.GetProperties(), StorageException);

sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/datalake_options.hpp

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -78,33 +78,6 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
7878
*/
7979
static std::string SerializeAcls(const std::vector<Acl>& aclsArray);
8080
};
81-
82-
/**
83-
* @brief Audiences available for Blobs
84-
*
85-
*/
86-
class DataLakeAudience final
87-
: public Azure::Core::_internal::ExtendableEnumeration<DataLakeAudience> {
88-
public:
89-
/**
90-
* @brief Construct a new DataLakeAudience object
91-
*
92-
* @param dataLakeAudience The Azure Active Directory audience to use when forming
93-
* authorization scopes. For the Language service, this value corresponds to a URL that
94-
* identifies the Azure cloud where the resource is located. For more information: See
95-
* https://learn.microsoft.com/en-us/azure/storage/blobs/authorize-access-azure-active-directory
96-
*/
97-
explicit DataLakeAudience(std::string dataLakeAudience)
98-
: ExtendableEnumeration(std::move(dataLakeAudience))
99-
{
100-
}
101-
102-
/**
103-
* @brief Default Audience. Use to acquire a token for authorizing requests to any Azure
104-
* Storage account.
105-
*/
106-
AZ_STORAGE_FILES_DATALAKE_DLLEXPORT const static DataLakeAudience DefaultAudience;
107-
};
10881
} // namespace Models
10982

11083
using DownloadFileToOptions = Blobs::DownloadBlobToOptions;
@@ -140,6 +113,46 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
140113
};
141114
} // namespace _detail
142115

116+
/**
117+
* @brief Audiences available for data lake service
118+
*
119+
*/
120+
class DataLakeAudience final
121+
: public Azure::Core::_internal::ExtendableEnumeration<DataLakeAudience> {
122+
public:
123+
/**
124+
* @brief Construct a new DataLakeAudience object
125+
*
126+
* @param dataLakeAudience The Azure Active Directory audience to use when forming
127+
* authorization scopes. For the Language service, this value corresponds to a URL that
128+
* identifies the Azure cloud where the resource is located. For more information: See
129+
* https://learn.microsoft.com/en-us/azure/storage/blobs/authorize-access-azure-active-directory
130+
*/
131+
explicit DataLakeAudience(std::string dataLakeAudience)
132+
: ExtendableEnumeration(std::move(dataLakeAudience))
133+
{
134+
}
135+
136+
/**
137+
* @brief The service endpoint for a given storage account. Use this method to acquire a token
138+
* for authorizing requests to that specific Azure Storage account and service only.
139+
*
140+
* @param storageAccountName he storage account name used to populate the service endpoint.
141+
* @return The service endpoint for a given storage account.
142+
*/
143+
static DataLakeAudience CreateDataLakeServiceAccountAudience(
144+
const std::string& storageAccountName)
145+
{
146+
return DataLakeAudience("https://" + storageAccountName + ".blob.core.windows.net/");
147+
}
148+
149+
/**
150+
* @brief Default Audience. Use to acquire a token for authorizing requests to any Azure
151+
* Storage account.
152+
*/
153+
AZ_STORAGE_FILES_DATALAKE_DLLEXPORT const static DataLakeAudience DefaultAudience;
154+
};
155+
143156
/**
144157
* @brief Client options used to initialize all DataLake clients.
145158
*/
@@ -173,10 +186,10 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
173186

174187
/**
175188
* The Audience to use for authentication with Azure Active Directory (AAD).
176-
* #Azure::Storage::Files::DataLake::Models::DataLakeAudience::DefaultAudience will be assumed
189+
* #Azure::Storage::Files::DataLake::DataLakeAudience::DefaultAudience will be assumed
177190
* if Audience is not set.
178191
*/
179-
Azure::Nullable<Models::DataLakeAudience> Audience;
192+
Azure::Nullable<DataLakeAudience> Audience;
180193
};
181194

182195
/**

sdk/storage/azure-storage-files-datalake/src/datalake_options.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
#include "azure/storage/files/datalake/datalake_options.hpp"
55

6-
namespace Azure { namespace Storage { namespace Files { namespace DataLake { namespace Models {
6+
namespace Azure { namespace Storage { namespace Files { namespace DataLake {
77

88
const DataLakeAudience DataLakeAudience::DefaultAudience(_internal::StorageDefaultAudience);
99

10-
}}}}} // namespace Azure::Storage::Files::DataLake::Models
10+
}}}} // namespace Azure::Storage::Files::DataLake

sdk/storage/azure-storage-files-datalake/src/datalake_utilities.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake { nam
100100
blobOptions.EnableTenantDiscovery = options.EnableTenantDiscovery;
101101
if (options.Audience.HasValue())
102102
{
103-
blobOptions.Audience = Blobs::Models::BlobAudience(options.Audience.Value().ToString());
103+
blobOptions.Audience = Blobs::BlobAudience(options.Audience.Value().ToString());
104104
}
105105
return blobOptions;
106106
}

0 commit comments

Comments
 (0)