Add two APIS: set_container_metadata and set_blob_metadata
This commit is contained in:
Родитель
5eaca17a0e
Коммит
3c87b389f4
|
@ -47,11 +47,13 @@ set(AZURE_STORAGE_LITE_HEADER
|
|||
include/copy_blob_request_base.h
|
||||
include/create_container_request_base.h
|
||||
include/delete_container_request_base.h
|
||||
include/set_container_metadata_request_base.h
|
||||
include/list_containers_request_base.h
|
||||
include/list_blobs_request_base.h
|
||||
include/get_block_list_request_base.h
|
||||
include/put_block_request_base.h
|
||||
include/get_blob_property_request_base.h
|
||||
include/set_blob_metadata_request_base.h
|
||||
include/get_container_property_request_base.h
|
||||
include/put_block_list_request_base.h
|
||||
include/append_block_request_base.h
|
||||
|
@ -68,9 +70,11 @@ set(AZURE_STORAGE_LITE_HEADER
|
|||
include/blob/copy_blob_request.h
|
||||
include/blob/create_container_request.h
|
||||
include/blob/delete_container_request.h
|
||||
include/blob/set_container_metadata_request.h
|
||||
include/blob/list_containers_request.h
|
||||
include/blob/list_blobs_request.h
|
||||
include/blob/get_blob_property_request.h
|
||||
include/blob/set_blob_metadata_request.h
|
||||
include/blob/get_container_property_request.h
|
||||
include/blob/get_block_list_request.h
|
||||
include/blob/put_block_request.h
|
||||
|
@ -100,9 +104,11 @@ set(AZURE_STORAGE_LITE_SOURCE
|
|||
src/copy_blob_request_base.cpp
|
||||
src/create_container_request_base.cpp
|
||||
src/delete_container_request_base.cpp
|
||||
src/set_container_metadata_request_base.cpp
|
||||
src/list_containers_request_base.cpp
|
||||
src/list_blobs_request_base.cpp
|
||||
src/get_blob_property_request_base.cpp
|
||||
src/set_blob_metadata_request_base.cpp
|
||||
src/get_block_list_request_base.cpp
|
||||
src/get_container_property_request_base.cpp
|
||||
src/put_block_request_base.cpp
|
||||
|
|
|
@ -160,6 +160,14 @@ namespace azure { namespace storage_lite {
|
|||
/// <returns>A <see cref="std::future" /> object that represents the current operation's result.</returns>
|
||||
AZURE_STORAGE_API std::future<storage_outcome<container_property>> get_container_properties(const std::string &container);
|
||||
|
||||
/// <summary>
|
||||
/// Intitiates a synchronous operation to set the container metadata.
|
||||
/// </summary>
|
||||
/// <param name="container">The container name.</param>
|
||||
/// <param name="metadata">A <see cref="std::vector"> that respresents metadatas.</param>
|
||||
/// <returns>A <see cref="std::future" /> object that represents the current operation's result.</returns>
|
||||
AZURE_STORAGE_API std::future<storage_outcome<void>> set_container_metadata(const std::string &container, const std::vector<std::pair<std::string, std::string>>& metadata);
|
||||
|
||||
/// <summary>
|
||||
/// Intitiates an asynchronous operation to list containers.
|
||||
/// </summary>
|
||||
|
@ -186,6 +194,15 @@ namespace azure { namespace storage_lite {
|
|||
/// <returns>A <see cref="std::future" /> object that represents the current operation.</returns>
|
||||
AZURE_STORAGE_API std::future<storage_outcome<blob_property>> get_blob_properties(const std::string &container, const std::string &blob);
|
||||
|
||||
/// <summary>
|
||||
/// Intitiates a synchronous operation to set the blob metadata.
|
||||
/// </summary>
|
||||
/// <param name="container">The container name.</param>
|
||||
/// <param name="blob">The blob name.</param>
|
||||
/// <param name="metadata">A <see cref="std::vector"> that respresents metadatas.</param>
|
||||
/// <returns>A <see cref="std::future" /> object that represents the current operation's result.</returns>
|
||||
AZURE_STORAGE_API std::future<storage_outcome<void>> set_blob_metadata(const std::string &container, const std::string& blob, const std::vector<std::pair<std::string, std::string>>& metadata);
|
||||
|
||||
/// <summary>
|
||||
/// Intitiates an asynchronous operation to download the block list of a blob.
|
||||
/// </summary>
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include "set_blob_metadata_request_base.h"
|
||||
|
||||
namespace azure { namespace storage_lite {
|
||||
|
||||
class set_blob_metadata_request final : public set_blob_metadata_request_base
|
||||
{
|
||||
public:
|
||||
set_blob_metadata_request(const std::string &container, const std::string& blob, const std::vector<std::pair<std::string, std::string>>& metadata)
|
||||
: m_container(container), m_blob(blob), m_metadata(metadata) {}
|
||||
|
||||
std::string container() const override
|
||||
{
|
||||
return m_container;
|
||||
}
|
||||
|
||||
std::string blob() const override
|
||||
{
|
||||
return m_blob;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> metadata() const override
|
||||
{
|
||||
return m_metadata;
|
||||
}
|
||||
private:
|
||||
std::string m_container;
|
||||
std::string m_blob;
|
||||
std::vector<std::pair<std::string, std::string>> m_metadata;
|
||||
};
|
||||
|
||||
}} // azure::storage_lite
|
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include "set_container_metadata_request_base.h"
|
||||
|
||||
namespace azure { namespace storage_lite {
|
||||
|
||||
class set_container_metadata_request final : public set_container_metadata_request_base
|
||||
{
|
||||
public:
|
||||
set_container_metadata_request(const std::string &container, const std::vector<std::pair<std::string, std::string>>& metadata)
|
||||
: m_container(container), m_metadata(metadata) {}
|
||||
|
||||
std::string container() const override
|
||||
{
|
||||
return m_container;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> metadata() const override
|
||||
{
|
||||
return m_metadata;
|
||||
}
|
||||
private:
|
||||
std::string m_container;
|
||||
std::vector<std::pair<std::string, std::string>> m_metadata;
|
||||
};
|
||||
|
||||
}} // azure::storage_lite
|
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "storage_EXPORTS.h"
|
||||
|
||||
#include "http_base.h"
|
||||
#include "storage_account.h"
|
||||
#include "storage_request_base.h"
|
||||
|
||||
namespace azure { namespace storage_lite {
|
||||
|
||||
class set_blob_metadata_request_base : public blob_request_base
|
||||
{
|
||||
public:
|
||||
virtual std::string container() const = 0;
|
||||
virtual std::string blob() const = 0;
|
||||
virtual std::vector<std::pair<std::string, std::string>> metadata() const = 0;
|
||||
|
||||
AZURE_STORAGE_API void build_request(const storage_account &a, http_base &h) const override;
|
||||
};
|
||||
|
||||
}} // azure::storage_lite
|
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "storage_EXPORTS.h"
|
||||
|
||||
#include "http_base.h"
|
||||
#include "storage_account.h"
|
||||
#include "storage_request_base.h"
|
||||
|
||||
namespace azure { namespace storage_lite {
|
||||
|
||||
class set_container_metadata_request_base : public blob_request_base
|
||||
{
|
||||
public:
|
||||
virtual std::string container() const = 0;
|
||||
virtual std::vector<std::pair<std::string, std::string>> metadata() const = 0;
|
||||
|
||||
AZURE_STORAGE_API void build_request(const storage_account &a, http_base &h) const override;
|
||||
};
|
||||
|
||||
}} // azure::storage_lite
|
|
@ -24,6 +24,8 @@ typedef SSIZE_T ssize_t;
|
|||
#include "blob/append_block_request.h"
|
||||
#include "blob/put_page_request.h"
|
||||
#include "blob/get_page_ranges_request.h"
|
||||
#include "blob/set_container_metadata_request.h"
|
||||
#include "blob/set_blob_metadata_request.h"
|
||||
|
||||
#include "executor.h"
|
||||
#include "utility.h"
|
||||
|
@ -212,6 +214,15 @@ std::future<storage_outcome<container_property>> blob_client::get_container_prop
|
|||
return container_properties;
|
||||
}
|
||||
|
||||
std::future<storage_outcome<void>> blob_client::set_container_metadata(const std::string &container, const std::vector<std::pair<std::string, std::string>>& metadata)
|
||||
{
|
||||
auto http = m_client->get_handle();
|
||||
|
||||
auto request = std::make_shared<set_container_metadata_request>(container, metadata);
|
||||
|
||||
return async_executor<void>::submit(m_account, request, http, m_context);
|
||||
}
|
||||
|
||||
std::future<storage_outcome<list_constainers_segmented_response>> blob_client::list_containers_segmented(const std::string &prefix, const std::string& continuation_token, const int max_result, bool include_metadata)
|
||||
{
|
||||
auto http = m_client->get_handle();
|
||||
|
@ -291,6 +302,15 @@ std::future<storage_outcome<blob_property>> blob_client::get_blob_properties(con
|
|||
return blob_properties;
|
||||
}
|
||||
|
||||
std::future<storage_outcome<void>> blob_client::set_blob_metadata(const std::string &container, const std::string& blob, const std::vector<std::pair<std::string, std::string>>& metadata)
|
||||
{
|
||||
auto http = m_client->get_handle();
|
||||
|
||||
auto request = std::make_shared<set_blob_metadata_request>(container, blob, metadata);
|
||||
|
||||
return async_executor<void>::submit(m_account, request, http, m_context);
|
||||
}
|
||||
|
||||
std::future<storage_outcome<void>> blob_client::upload_block_from_stream(const std::string &container, const std::string &blob, const std::string &blockid, std::istream &is)
|
||||
{
|
||||
auto http = m_client->get_handle();
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
#include "set_blob_metadata_request_base.h"
|
||||
|
||||
#include "constants.h"
|
||||
#include "utility.h"
|
||||
|
||||
namespace azure { namespace storage_lite {
|
||||
|
||||
void set_blob_metadata_request_base::build_request(const storage_account &a, http_base &h) const
|
||||
{
|
||||
const auto &r = *this;
|
||||
|
||||
h.set_absolute_timeout(5L);
|
||||
|
||||
h.set_method(http_base::http_method::put);
|
||||
|
||||
storage_url url = a.get_url(storage_account::service::blob);
|
||||
url.append_path(r.container()).append_path(r.blob());
|
||||
|
||||
url.add_query(constants::query_comp, constants::query_comp_metadata);
|
||||
add_optional_query(url, constants::query_timeout, r.timeout());
|
||||
h.set_url(url.to_string());
|
||||
|
||||
storage_headers headers;
|
||||
|
||||
add_content_length(h, headers, 0);
|
||||
add_ms_header(h, headers, constants::header_ms_client_request_id, r.ms_client_request_id(), true);
|
||||
// les is not supported.
|
||||
// add_ms_header(h, headers, constants::header_ms_lease_id, r.ms_lease_id(), true);
|
||||
|
||||
h.add_header(constants::header_user_agent, constants::header_value_user_agent);
|
||||
add_ms_header(h, headers, constants::header_ms_date, get_ms_date(date_format::rfc_1123));
|
||||
add_ms_header(h, headers, constants::header_ms_version, constants::header_value_storage_version);
|
||||
|
||||
for (const auto& m : metadata())
|
||||
{
|
||||
add_metadata_header(h, headers, m.first, m.second);
|
||||
}
|
||||
|
||||
a.credential()->sign_request(r, h, url, headers);
|
||||
}
|
||||
}}
|
|
@ -0,0 +1,42 @@
|
|||
#include "set_container_metadata_request_base.h"
|
||||
|
||||
#include "constants.h"
|
||||
#include "utility.h"
|
||||
|
||||
namespace azure { namespace storage_lite {
|
||||
|
||||
void set_container_metadata_request_base::build_request(const storage_account &a, http_base &h) const
|
||||
{
|
||||
const auto &r = *this;
|
||||
|
||||
h.set_absolute_timeout(5L);
|
||||
|
||||
h.set_method(http_base::http_method::put);
|
||||
|
||||
storage_url url = a.get_url(storage_account::service::blob);
|
||||
url.append_path(r.container());
|
||||
|
||||
url.add_query(constants::query_restype, constants::query_restype_container);
|
||||
url.add_query(constants::query_comp, constants::query_comp_metadata);
|
||||
add_optional_query(url, constants::query_timeout, r.timeout());
|
||||
h.set_url(url.to_string());
|
||||
|
||||
storage_headers headers;
|
||||
|
||||
add_content_length(h, headers, 0);
|
||||
add_ms_header(h, headers, constants::header_ms_client_request_id, r.ms_client_request_id(), true);
|
||||
// les is not supported.
|
||||
// add_ms_header(h, headers, constants::header_ms_lease_id, r.ms_lease_id(), true);
|
||||
|
||||
h.add_header(constants::header_user_agent, constants::header_value_user_agent);
|
||||
add_ms_header(h, headers, constants::header_ms_date, get_ms_date(date_format::rfc_1123));
|
||||
add_ms_header(h, headers, constants::header_ms_version, constants::header_value_storage_version);
|
||||
|
||||
for (const auto& m : metadata())
|
||||
{
|
||||
add_metadata_header(h, headers, m.first, m.second);
|
||||
}
|
||||
|
||||
a.credential()->sign_request(r, h, url, headers);
|
||||
}
|
||||
}}
|
|
@ -77,6 +77,25 @@ TEST_CASE("Get Container Property", "[container], [blob_service]")
|
|||
auto second_outcome = client.get_container_properties(container_name).get();
|
||||
REQUIRE(second_outcome.success());
|
||||
REQUIRE_FALSE(second_outcome.response().etag.empty());
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> metadata;
|
||||
metadata.emplace_back(std::make_pair("mkey1", "mvalue1"));
|
||||
metadata.emplace_back(std::make_pair("mkEy2", "MValUe2# % %2D"));
|
||||
auto third_outcome = client.set_container_metadata(container_name, metadata).get();
|
||||
REQUIRE(third_outcome.success());
|
||||
|
||||
auto fourth_outcome = client.get_container_properties(container_name).get();
|
||||
REQUIRE(fourth_outcome.success());
|
||||
REQUIRE(fourth_outcome.response().metadata == metadata);
|
||||
|
||||
metadata.clear();
|
||||
auto fifth_outcome = client.set_container_metadata(container_name, metadata).get();
|
||||
REQUIRE(fifth_outcome.success());
|
||||
|
||||
auto sixth_outcome = client.get_container_properties(container_name).get();
|
||||
REQUIRE(sixth_outcome.success());
|
||||
REQUIRE(sixth_outcome.response().metadata == metadata);
|
||||
|
||||
client.delete_container(container_name).wait();
|
||||
}
|
||||
|
||||
|
|
|
@ -191,6 +191,24 @@ TEST_CASE("Get blob property", "[blob],[blob_service]")
|
|||
auto get_blob_property_outcome = client.get_blob_properties(container_name, blob_name).get();
|
||||
REQUIRE(get_blob_property_outcome.success());
|
||||
REQUIRE(get_blob_property_outcome.response().size == 1024);
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> metadata;
|
||||
metadata.emplace_back(std::make_pair("mkey1", "mvalue1"));
|
||||
metadata.emplace_back(std::make_pair("mkEy2", "MValUe2# % %2d"));
|
||||
auto set_metadata_outcome = client.set_blob_metadata(container_name, blob_name, metadata).get();
|
||||
REQUIRE(set_metadata_outcome.success());
|
||||
|
||||
get_blob_property_outcome = client.get_blob_properties(container_name, blob_name).get();
|
||||
REQUIRE(get_blob_property_outcome.success());
|
||||
REQUIRE(get_blob_property_outcome.response().metadata == metadata);
|
||||
|
||||
metadata.clear();
|
||||
set_metadata_outcome = client.set_blob_metadata(container_name, blob_name, metadata).get();
|
||||
REQUIRE(set_metadata_outcome.success());
|
||||
|
||||
get_blob_property_outcome = client.get_blob_properties(container_name, blob_name).get();
|
||||
REQUIRE(get_blob_property_outcome.success());
|
||||
REQUIRE(get_blob_property_outcome.response().metadata == metadata);
|
||||
}
|
||||
|
||||
SECTION("Get blob property for non-existing blob successfully")
|
||||
|
|
Загрузка…
Ссылка в новой задаче