Skip to content

Storage/feature/stg87-File OAuth #4413

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

Merged
Merged
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
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "cpp",
"TagPrefix": "cpp/storage",
"Tag": "cpp/storage_fafb185a5f"
"Tag": "cpp/storage_b3174d14d3"
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
std::shared_ptr<StorageSharedKeyCredential> credential,
const ShareClientOptions& options = ShareClientOptions());

/**
* @brief Initialize a new instance of ShareClient using shared key authentication.
* @param shareUrl The URL of the file share this client's request targets.
* @param credential The token credential used to sign requests.
* @param options Optional parameters used to initialize the client.
*/
explicit ShareClient(
const std::string& shareUrl,
std::shared_ptr<Core::Credentials::TokenCredential> credential,
const ShareClientOptions& options = ShareClientOptions());

/**
* @brief Initialize a new instance of ShareClient using anonymous access or shared access
* signature.
Expand Down Expand Up @@ -232,6 +243,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
std::shared_ptr<Azure::Core::Http::_internal::HttpPipeline> m_pipeline;
Nullable<bool> m_allowTrailingDot;
Nullable<bool> m_allowSourceTrailingDot;
Nullable<Models::ShareTokenIntent> m_shareTokenIntent;

explicit ShareClient(
Azure::Core::Url shareUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
std::shared_ptr<StorageSharedKeyCredential> credential,
const ShareClientOptions& options = ShareClientOptions());

/**
* @brief Initialize a new instance of ShareDirectoryClient using shared key authentication.
* @param shareDirectoryUrl The URL of the directory this client's request targets.
* @param credential The token credential used to sign requests.
* @param options Optional parameters used to initialize the client.
*/
explicit ShareDirectoryClient(
const std::string& shareDirectoryUrl,
std::shared_ptr<Core::Credentials::TokenCredential> credential,
const ShareClientOptions& options = ShareClientOptions());

/**
* @brief Initialize a new instance of ShareDirectoryClient using anonymous access or shared
* access signature.
Expand Down Expand Up @@ -262,6 +273,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
std::shared_ptr<Azure::Core::Http::_internal::HttpPipeline> m_pipeline;
Nullable<bool> m_allowTrailingDot;
Nullable<bool> m_allowSourceTrailingDot;
Nullable<Models::ShareTokenIntent> m_shareTokenIntent;

explicit ShareDirectoryClient(
Azure::Core::Url shareDirectoryUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
std::shared_ptr<StorageSharedKeyCredential> credential,
const ShareClientOptions& options = ShareClientOptions());

/**
* @brief Initialize a new instance of ShareFileClient using shared key authentication.
* @param shareFileUrl The URL of the file this client's request targets.
* @param credential The token credential used to sign requests.
* @param options Optional parameters used to initialize the client.
*/
explicit ShareFileClient(
const std::string& shareFileUrl,
std::shared_ptr<Core::Credentials::TokenCredential> credential,
const ShareClientOptions& options = ShareClientOptions());

/**
* @brief Initialize a new instance of ShareFileClient using anonymous access or shared access
* signature.
Expand Down Expand Up @@ -365,6 +376,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
std::shared_ptr<Azure::Core::Http::_internal::HttpPipeline> m_pipeline;
Nullable<bool> m_allowTrailingDot;
Nullable<bool> m_allowSourceTrailingDot;
Nullable<Models::ShareTokenIntent> m_shareTokenIntent;

explicit ShareFileClient(
Azure::Core::Url shareFileUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
* Supported by x-ms-version 2022-11-02 and above.
*/
Nullable<bool> AllowSourceTrailingDot;

/**
* Share Token Intent. For use with token authentication. Used to indicate the intent of the
* request. This is currently required when using token authentication.
*/
Nullable<Models::ShareTokenIntent> ShareTokenIntent;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
std::shared_ptr<StorageSharedKeyCredential> credential,
const ShareClientOptions& options = ShareClientOptions());

/**
* @brief Initialize a new instance of ShareServiceClient using shared key authentication.
* @param serviceUrl The service URL this client's request targets.
* @param credential The token credential used to sign requests.
* @param options Optional parameters used to initialize the client.
*/
explicit ShareServiceClient(
const std::string& serviceUrl,
std::shared_ptr<Core::Credentials::TokenCredential> credential,
const ShareClientOptions& options = ShareClientOptions());

/**
* @brief Initialize a new instance of ShareServiceClient using anonymous access or shared
* access signature.
Expand Down Expand Up @@ -104,5 +115,6 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
std::shared_ptr<Azure::Core::Http::_internal::HttpPipeline> m_pipeline;
Nullable<bool> m_allowTrailingDot;
Nullable<bool> m_allowSourceTrailingDot;
Nullable<Models::ShareTokenIntent> m_shareTokenIntent;
};
}}}} // namespace Azure::Storage::Files::Shares
39 changes: 37 additions & 2 deletions sdk/storage/azure-storage-files-shares/src/share_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
std::shared_ptr<StorageSharedKeyCredential> credential,
const ShareClientOptions& options)
: m_shareUrl(shareUrl), m_allowTrailingDot(options.AllowTrailingDot),
m_allowSourceTrailingDot(options.AllowSourceTrailingDot)
m_allowSourceTrailingDot(options.AllowSourceTrailingDot),
m_shareTokenIntent(options.ShareTokenIntent)
{
ShareClientOptions newOptions = options;
newOptions.PerRetryPolicies.emplace_back(
Expand All @@ -63,9 +64,40 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
std::move(perOperationPolicies));
}

ShareClient::ShareClient(
const std::string& shareUrl,
std::shared_ptr<Core::Credentials::TokenCredential> credential,
const ShareClientOptions& options)
: m_shareUrl(shareUrl), m_allowTrailingDot(options.AllowTrailingDot),
m_allowSourceTrailingDot(options.AllowSourceTrailingDot),
m_shareTokenIntent(options.ShareTokenIntent)
{
ShareClientOptions newOptions = options;

std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perRetryPolicies;
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perOperationPolicies;
perRetryPolicies.emplace_back(std::make_unique<_internal::StoragePerRetryPolicy>());
{
Azure::Core::Credentials::TokenRequestContext tokenContext;
tokenContext.Scopes.emplace_back(_internal::StorageScope);
perRetryPolicies.emplace_back(
std::make_unique<Azure::Core::Http::Policies::_internal::BearerTokenAuthenticationPolicy>(
credential, tokenContext));
}
perOperationPolicies.emplace_back(
std::make_unique<_internal::StorageServiceVersionPolicy>(newOptions.ApiVersion));
m_pipeline = std::make_shared<Azure::Core::Http::_internal::HttpPipeline>(
newOptions,
_internal::FileServicePackageName,
_detail::PackageVersion::ToString(),
std::move(perRetryPolicies),
std::move(perOperationPolicies));
}

ShareClient::ShareClient(const std::string& shareUrl, const ShareClientOptions& options)
: m_shareUrl(shareUrl), m_allowTrailingDot(options.AllowTrailingDot),
m_allowSourceTrailingDot(options.AllowSourceTrailingDot)
m_allowSourceTrailingDot(options.AllowSourceTrailingDot),
m_shareTokenIntent(options.ShareTokenIntent)
{
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perRetryPolicies;
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perOperationPolicies;
Expand All @@ -85,6 +117,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
ShareDirectoryClient directoryClient(m_shareUrl, m_pipeline);
directoryClient.m_allowTrailingDot = m_allowTrailingDot;
directoryClient.m_allowSourceTrailingDot = m_allowSourceTrailingDot;
directoryClient.m_shareTokenIntent = m_shareTokenIntent;
return directoryClient;
}

Expand Down Expand Up @@ -267,6 +300,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
(void)options;
auto protocolLayerOptions = _detail::ShareClient::CreateSharePermissionOptions();
protocolLayerOptions.SharePermission.Permission = permission;
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;
return _detail::ShareClient::CreatePermission(
*m_pipeline, m_shareUrl, protocolLayerOptions, context);
}
Expand All @@ -279,6 +313,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
(void)options;
auto protocolLayerOptions = _detail::ShareClient::GetSharePermissionOptions();
protocolLayerOptions.FilePermissionKey = permissionKey;
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;
auto result = _detail::ShareClient::GetPermission(
*m_pipeline, m_shareUrl, protocolLayerOptions, context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
std::shared_ptr<StorageSharedKeyCredential> credential,
const ShareClientOptions& options)
: m_shareDirectoryUrl(shareDirectoryUrl), m_allowTrailingDot(options.AllowTrailingDot),
m_allowSourceTrailingDot(options.AllowSourceTrailingDot)
m_allowSourceTrailingDot(options.AllowSourceTrailingDot),
m_shareTokenIntent(options.ShareTokenIntent)
{
ShareClientOptions newOptions = options;
newOptions.PerRetryPolicies.emplace_back(
Expand All @@ -67,9 +68,40 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {

ShareDirectoryClient::ShareDirectoryClient(
const std::string& shareDirectoryUrl,
std::shared_ptr<Core::Credentials::TokenCredential> credential,
const ShareClientOptions& options)
: m_shareDirectoryUrl(shareDirectoryUrl), m_allowTrailingDot(options.AllowTrailingDot),
m_allowSourceTrailingDot(options.AllowSourceTrailingDot)
m_allowSourceTrailingDot(options.AllowSourceTrailingDot),
m_shareTokenIntent(options.ShareTokenIntent)
{
ShareClientOptions newOptions = options;

std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perRetryPolicies;
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perOperationPolicies;
perRetryPolicies.emplace_back(std::make_unique<_internal::StoragePerRetryPolicy>());
{
Azure::Core::Credentials::TokenRequestContext tokenContext;
tokenContext.Scopes.emplace_back(_internal::StorageScope);
perRetryPolicies.emplace_back(
std::make_unique<Azure::Core::Http::Policies::_internal::BearerTokenAuthenticationPolicy>(
credential, tokenContext));
}
perOperationPolicies.emplace_back(
std::make_unique<_internal::StorageServiceVersionPolicy>(newOptions.ApiVersion));
m_pipeline = std::make_shared<Azure::Core::Http::_internal::HttpPipeline>(
newOptions,
_internal::FileServicePackageName,
_detail::PackageVersion::ToString(),
std::move(perRetryPolicies),
std::move(perOperationPolicies));
}

ShareDirectoryClient::ShareDirectoryClient(
const std::string& shareDirectoryUrl,
const ShareClientOptions& options)
: m_shareDirectoryUrl(shareDirectoryUrl), m_allowTrailingDot(options.AllowTrailingDot),
m_allowSourceTrailingDot(options.AllowSourceTrailingDot),
m_shareTokenIntent(options.ShareTokenIntent)
{
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perRetryPolicies;
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perOperationPolicies;
Expand All @@ -92,6 +124,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
ShareDirectoryClient subdirectoryClient(builder, m_pipeline);
subdirectoryClient.m_allowTrailingDot = m_allowTrailingDot;
subdirectoryClient.m_allowSourceTrailingDot = m_allowSourceTrailingDot;
subdirectoryClient.m_shareTokenIntent = m_shareTokenIntent;
return subdirectoryClient;
}

Expand All @@ -102,6 +135,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
ShareFileClient fileClient(builder, m_pipeline);
fileClient.m_allowTrailingDot = m_allowTrailingDot;
fileClient.m_allowSourceTrailingDot = m_allowSourceTrailingDot;
fileClient.m_shareTokenIntent = m_shareTokenIntent;
return fileClient;
}

Expand Down Expand Up @@ -172,6 +206,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
protocolLayerOptions.FilePermission = std::string(FileInheritPermission);
}
protocolLayerOptions.AllowTrailingDot = m_allowTrailingDot;
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;
auto result = _detail::DirectoryClient::Create(
*m_pipeline, m_shareDirectoryUrl, protocolLayerOptions, context);
Models::CreateDirectoryResult ret;
Expand Down Expand Up @@ -255,13 +290,15 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
protocolLayerOptions.AllowTrailingDot = m_allowTrailingDot;
protocolLayerOptions.AllowSourceTrailingDot = m_allowSourceTrailingDot;
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;

auto response = _detail::FileClient::Rename(
*m_pipeline, destinationFileUrl, protocolLayerOptions, context);

auto renamedFileClient = ShareFileClient(destinationFileUrl, m_pipeline);
renamedFileClient.m_allowTrailingDot = m_allowTrailingDot;
renamedFileClient.m_allowSourceTrailingDot = m_allowSourceTrailingDot;
renamedFileClient.m_shareTokenIntent = m_shareTokenIntent;
return Azure::Response<ShareFileClient>(
std::move(renamedFileClient), std::move(response.RawResponse));
}
Expand Down Expand Up @@ -315,13 +352,15 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
protocolLayerOptions.AllowTrailingDot = m_allowTrailingDot;
protocolLayerOptions.AllowSourceTrailingDot = m_allowSourceTrailingDot;
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;

auto response = _detail::DirectoryClient::Rename(
*m_pipeline, destinationDirectoryUrl, protocolLayerOptions, context);

auto renamedSubdirectoryClient = ShareDirectoryClient(destinationDirectoryUrl, m_pipeline);
renamedSubdirectoryClient.m_allowTrailingDot = m_allowTrailingDot;
renamedSubdirectoryClient.m_allowSourceTrailingDot = m_allowSourceTrailingDot;
renamedSubdirectoryClient.m_shareTokenIntent = m_shareTokenIntent;
return Azure::Response<ShareDirectoryClient>(
std::move(renamedSubdirectoryClient), std::move(response.RawResponse));
}
Expand All @@ -333,6 +372,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
(void)options;
auto protocolLayerOptions = _detail::DirectoryClient::DeleteDirectoryOptions();
protocolLayerOptions.AllowTrailingDot = m_allowTrailingDot;
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;
auto result = _detail::DirectoryClient::Delete(
*m_pipeline, m_shareDirectoryUrl, protocolLayerOptions, context);
Models::DeleteDirectoryResult ret;
Expand Down Expand Up @@ -370,6 +410,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
(void)options;
auto protocolLayerOptions = _detail::DirectoryClient::GetDirectoryPropertiesOptions();
protocolLayerOptions.AllowTrailingDot = m_allowTrailingDot;
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;
return _detail::DirectoryClient::GetProperties(
*m_pipeline, m_shareDirectoryUrl, protocolLayerOptions, context);
}
Expand Down Expand Up @@ -421,6 +462,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
protocolLayerOptions.FilePermission = FilePreserveSmbProperties;
}
protocolLayerOptions.AllowTrailingDot = m_allowTrailingDot;
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;
return _detail::DirectoryClient::SetProperties(
*m_pipeline, m_shareDirectoryUrl, protocolLayerOptions, context);
}
Expand All @@ -435,6 +477,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
protocolLayerOptions.Metadata
= std::map<std::string, std::string>(metadata.begin(), metadata.end());
protocolLayerOptions.AllowTrailingDot = m_allowTrailingDot;
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;
return _detail::DirectoryClient::SetMetadata(
*m_pipeline, m_shareDirectoryUrl, protocolLayerOptions, context);
}
Expand All @@ -451,6 +494,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
protocolLayerOptions.Include = options.Include;
protocolLayerOptions.IncludeExtendedInfo = options.IncludeExtendedInfo;
protocolLayerOptions.AllowTrailingDot = m_allowTrailingDot;
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;
auto response = _detail::DirectoryClient::ListFilesAndDirectoriesSegment(
*m_pipeline, m_shareDirectoryUrl, protocolLayerOptions, context);

Expand Down Expand Up @@ -522,6 +566,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
protocolLayerOptions.MaxResults = options.PageSizeHint;
protocolLayerOptions.Recursive = options.Recursive;
protocolLayerOptions.AllowTrailingDot = m_allowTrailingDot;
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;
auto response = _detail::DirectoryClient::ListHandles(
*m_pipeline, m_shareDirectoryUrl, protocolLayerOptions, context);

Expand Down Expand Up @@ -569,6 +614,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
auto protocolLayerOptions = _detail::DirectoryClient::ForceDirectoryCloseHandlesOptions();
protocolLayerOptions.HandleId = handleId;
protocolLayerOptions.AllowTrailingDot = m_allowTrailingDot;
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;
auto result = _detail::DirectoryClient::ForceCloseHandles(
*m_pipeline, m_shareDirectoryUrl, protocolLayerOptions, context);
Models::ForceCloseDirectoryHandleResult ret;
Expand All @@ -585,6 +631,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
protocolLayerOptions.Marker = options.ContinuationToken;
protocolLayerOptions.Recursive = options.Recursive;
protocolLayerOptions.AllowTrailingDot = m_allowTrailingDot;
protocolLayerOptions.FileRequestIntent = m_shareTokenIntent;
auto response = _detail::DirectoryClient::ForceCloseHandles(
*m_pipeline, m_shareDirectoryUrl, protocolLayerOptions, context);

Expand Down
Loading