Added file protocol layer. (#367)

* Added file protocol layer.

* Resolved some comments.
This commit is contained in:
Kan Tang 2020-08-02 11:23:50 +08:00 committed by GitHub
parent fb729fcf10
commit 1b4ea7ac70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 6732 additions and 2 deletions

View File

@ -138,9 +138,25 @@ set (AZURE_STORAGE_DATALAKE_SOURCE
add_library(azure-storage-file-datalake ${AZURE_STORAGE_DATALAKE_HEADER} ${AZURE_STORAGE_DATALAKE_SOURCE})
target_link_libraries(azure-storage-file-datalake azure-storage-blob)
set (AZURE_STORAGE_SHARES_HEADER
inc/shares/shares.hpp
inc/shares/protocol/share_rest_client.hpp
inc/shares/share_options.hpp
inc/shares/share_responses.hpp
inc/shares/service_client.hpp
)
set (AZURE_STORAGE_SHARES_SOURCE
src/shares/service_client.cpp
)
add_library(azure-storage-file-share ${AZURE_STORAGE_SHARES_HEADER} ${AZURE_STORAGE_SHARES_SOURCE})
target_link_libraries(azure-storage-file-share azure-storage-common)
add_library(azure::storage::common ALIAS azure-storage-common)
add_library(azure::storage::blob ALIAS azure-storage-blob)
add_library(azure::storage::file::datalake ALIAS azure-storage-file-datalake)
add_library(azure::storage::file::share ALIAS azure-storage-file-share)
if(BUILD_STORAGE_SAMPLES)
add_subdirectory(sample)

View File

@ -8,5 +8,6 @@ namespace Azure { namespace Storage {
constexpr static const char* CommonComponentVersion = "1.0.0-private.beta.1";
constexpr static const char* BlobServiceVersion = "1.0.0-private.beta.1";
constexpr static const char* DataLakeServiceVersion = "1.0.0-private.beta.1";
constexpr static const char* FileServiceVersion = "1.0.0-private.beta.1";
}} // namespace Azure::Storage

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,83 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#pragma once
#include "common/storage_credential.hpp"
#include "common/storage_uri_builder.hpp"
#include "credentials/credentials.hpp"
#include "http/pipeline.hpp"
#include "protocol/share_rest_client.hpp"
#include "response.hpp"
#include "share_options.hpp"
#include "share_responses.hpp"
#include <memory>
#include <string>
namespace Azure { namespace Storage { namespace Files { namespace Shares {
class ServiceClient {
public:
/**
* @brief Create from connection string
* @param connectionString Azure Storage connection string.
* @param options Optional parameters used to initialize the client.
* @return ServiceClient
*/
static ServiceClient CreateFromConnectionString(
const std::string& connectionString,
const ServiceClientOptions& options = ServiceClientOptions());
/**
* @brief Shared key authentication client.
* @param serviceUri The service URI this client's request targets.
* @param credential The shared key credential used to initialize the client.
* @param options Optional parameters used to initialize the client.
*/
explicit ServiceClient(
const std::string& serviceUri,
std::shared_ptr<SharedKeyCredential> credential,
const ServiceClientOptions& options = ServiceClientOptions());
/**
* @brief Bearer token authentication client.
* @param serviceUri The service URI this client's request targets.
* @param credential The token credential used to initialize the client.
* @param options Optional parameters used to initialize the client.
*/
explicit ServiceClient(
const std::string& serviceUri,
std::shared_ptr<Core::Credentials::TokenCredential> credential,
const ServiceClientOptions& options = ServiceClientOptions());
/**
* @brief Anonymous/SAS/customized pipeline auth.
* @param serviceUri The service URI this client's request targets.
* @param options Optional parameters used to initialize the client.
*/
explicit ServiceClient(
const std::string& serviceUri,
const ServiceClientOptions& options = ServiceClientOptions());
/**
* @brief Gets the file share service's primary uri endpoint.
*
* @return The file share service's primary uri endpoint.
*/
std::string GetUri() const { return m_serviceUri.ToString(); }
/**
* @brief List the shares from the service.
* @param options Optional parameters to list the shares.
* @return Azure::Core::Response<ListSharesResult> The results containing the shares returned
* and information used for future list operation on valid result not yet returned.
*/
Azure::Core::Response<ListSharesSegmentResult> ListSharesSegment(
const ListSharesOptions& options = ListSharesOptions()) const;
private:
UriBuilder m_serviceUri;
std::shared_ptr<Azure::Core::Http::HttpPipeline> m_pipeline;
};
}}}} // namespace Azure::Storage::Files::Shares

View File

@ -0,0 +1,60 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#pragma once
#include "common/access_conditions.hpp"
#include "nullable.hpp"
#include "protocol/share_rest_client.hpp"
#include <map>
#include <memory>
#include <string>
#include <vector>
namespace Azure { namespace Storage { namespace Files { namespace Shares {
/**
* @brief Service client options used to initalize ServiceClient.
*/
struct ServiceClientOptions
{
std::vector<std::unique_ptr<Azure::Core::Http::HttpPolicy>> PerOperationPolicies;
std::vector<std::unique_ptr<Azure::Core::Http::HttpPolicy>> PerRetryPolicies;
};
struct ListSharesOptions
{
/**
* @brief Context for cancelling long running operations.
*/
Azure::Core::Context Context;
/**
* @brief Filters the results to return only entries whose name begins with the specified
* prefix.
*/
Azure::Core::Nullable<std::string> Prefix;
/**
* @brief A string value that identifies the portion of the list to be returned with the next
* list operation. The operation returns a marker value within the response body if the list
* returned was not complete. The marker value may then be used in a subsequent call to request
* the next set of list items. The marker value is opaque to the client.
*/
Azure::Core::Nullable<std::string> Marker;
/**
* @brief Specifies the maximum number of entries to return. If the request does not specify
* maxresults, or specifies a value greater than 5,000, the server will return up to 5,000
* items.
*/
Azure::Core::Nullable<int32_t> MaxResults;
/**
* @brief Include this parameter to specify one or more datasets to include in the response.
*/
Azure::Core::Nullable<ListSharesIncludeType> ListSharesInclude;
};
}}}} // namespace Azure::Storage::Files::Shares

View File

@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#pragma once
#include "protocol/share_rest_client.hpp"
namespace Azure { namespace Storage { namespace Files { namespace Shares {
// ServiceClient models:
using ListSharesSegmentResult = ServiceListSharesSegmentResponse;
}}}} // namespace Azure::Storage::Files::Shares

View File

@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#pragma once
#include "service_client.hpp"

View File

@ -9,6 +9,6 @@ add_executable (
samples_common.hpp
blob_getting_started.cpp
datalake_getting_started.cpp
)
file_share_getting_started.cpp)
target_link_libraries(azure-storage-sample azure::storage::blob azure::storage::file::datalake)
target_link_libraries(azure-storage-sample azure::storage::blob azure::storage::file::datalake azure::storage::file::share)

View File

@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "datalake/datalake.hpp"
#include "samples_common.hpp"
#include <iostream>
SAMPLE(FileShareGettingStarted, FileShareGettingStarted)
void FileShareGettingStarted() {}

View File

@ -0,0 +1,121 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "shares/service_client.hpp"
#include "common/common_headers_request_policy.hpp"
#include "common/constants.hpp"
#include "common/shared_key_policy.hpp"
#include "common/storage_common.hpp"
#include "common/storage_credential.hpp"
#include "common/storage_version.hpp"
#include "credentials/policy/policies.hpp"
#include "http/curl/curl.hpp"
namespace Azure { namespace Storage { namespace Files { namespace Shares {
ServiceClient ServiceClient::CreateFromConnectionString(
const std::string& connectionString,
const ServiceClientOptions& options)
{
auto parsedConnectionString = Azure::Storage::Details::ParseConnectionString(connectionString);
auto serviceUri = std::move(parsedConnectionString.DataLakeServiceUri);
if (parsedConnectionString.KeyCredential)
{
return ServiceClient(serviceUri.ToString(), parsedConnectionString.KeyCredential, options);
}
else
{
return ServiceClient(serviceUri.ToString(), options);
}
}
ServiceClient::ServiceClient(
const std::string& serviceUri,
std::shared_ptr<SharedKeyCredential> credential,
const ServiceClientOptions& options)
: m_serviceUri(serviceUri)
{
std::vector<std::unique_ptr<Azure::Core::Http::HttpPolicy>> policies;
policies.emplace_back(std::make_unique<Azure::Core::Http::TelemetryPolicy>(
Azure::Storage::Details::c_FileServicePackageName, FileServiceVersion));
for (const auto& p : options.PerOperationPolicies)
{
policies.emplace_back(p->Clone());
}
policies.emplace_back(
std::make_unique<Azure::Core::Http::RetryPolicy>(Azure::Core::Http::RetryOptions()));
for (const auto& p : options.PerRetryPolicies)
{
policies.emplace_back(p->Clone());
}
policies.emplace_back(std::make_unique<CommonHeadersRequestPolicy>());
policies.emplace_back(std::make_unique<SharedKeyPolicy>(credential));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);
}
ServiceClient::ServiceClient(
const std::string& serviceUri,
std::shared_ptr<Core::Credentials::TokenCredential> credential,
const ServiceClientOptions& options)
: m_serviceUri(serviceUri)
{
std::vector<std::unique_ptr<Azure::Core::Http::HttpPolicy>> policies;
policies.emplace_back(std::make_unique<Azure::Core::Http::TelemetryPolicy>(
Azure::Storage::Details::c_FileServicePackageName, FileServiceVersion));
for (const auto& p : options.PerOperationPolicies)
{
policies.emplace_back(p->Clone());
}
policies.emplace_back(
std::make_unique<Azure::Core::Http::RetryPolicy>(Azure::Core::Http::RetryOptions()));
for (const auto& p : options.PerRetryPolicies)
{
policies.emplace_back(p->Clone());
}
policies.emplace_back(std::make_unique<CommonHeadersRequestPolicy>());
policies.emplace_back(
std::make_unique<Core::Credentials::Policy::BearerTokenAuthenticationPolicy>(
credential, Azure::Storage::Details::c_StorageScope));
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);
}
ServiceClient::ServiceClient(const std::string& serviceUri, const ServiceClientOptions& options)
: m_serviceUri(serviceUri)
{
std::vector<std::unique_ptr<Azure::Core::Http::HttpPolicy>> policies;
policies.emplace_back(std::make_unique<Azure::Core::Http::TelemetryPolicy>(
Azure::Storage::Details::c_FileServicePackageName, FileServiceVersion));
for (const auto& p : options.PerOperationPolicies)
{
policies.emplace_back(p->Clone());
}
policies.emplace_back(
std::make_unique<Azure::Core::Http::RetryPolicy>(Azure::Core::Http::RetryOptions()));
for (const auto& p : options.PerRetryPolicies)
{
policies.emplace_back(p->Clone());
}
policies.emplace_back(std::make_unique<CommonHeadersRequestPolicy>());
policies.emplace_back(std::make_unique<Azure::Core::Http::TransportPolicy>(
std::make_shared<Azure::Core::Http::CurlTransport>()));
m_pipeline = std::make_shared<Azure::Core::Http::HttpPipeline>(policies);
}
Azure::Core::Response<ListSharesSegmentResult> ServiceClient::ListSharesSegment(
const ListSharesOptions& options) const
{
auto protocolLayerOptions = ShareRestClient::Service::ListSharesSegmentOptions();
protocolLayerOptions.ListSharesInclude = std::move(options.ListSharesInclude);
protocolLayerOptions.Marker = std::move(options.Marker);
protocolLayerOptions.MaxResults = std::move(options.MaxResults);
protocolLayerOptions.Prefix = std::move(options.Prefix);
return ShareRestClient::Service::ListSharesSegment(
m_serviceUri.ToString(), *m_pipeline, options.Context, protocolLayerOptions);
}
}}}} // namespace Azure::Storage::Files::Shares