Skip to content

Commit

Permalink
CXXCBC-620: Update core analytics_link_get_all to follow RFC (#687)
Browse files Browse the repository at this point in the history
Changes
=======
* Allow link_type, link_name and dataverse_name to be optional
* Raise invalid_argument if a link_name is provided but a dataverse_name
  is not
  • Loading branch information
thejcfactor authored Oct 25, 2024
1 parent b7086c0 commit 960bdda
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
38 changes: 23 additions & 15 deletions core/operations/management/analytics_link_get_all.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,33 @@ analytics_link_get_all_request::encode_to(encoded_request_type& encoded,
encoded.headers["content-type"] = "application/x-www-form-urlencoded";
encoded.headers["accept"] = "application/json";
encoded.method = "GET";
if (!link_type.empty()) {
values["type"] = link_type;
if (link_type.has_value() && !link_type.value().empty()) {
values["type"] = link_type.value();
}
if (std::count(dataverse_name.begin(), dataverse_name.end(), '/') == 0) {
if (!dataverse_name.empty()) {
values["dataverse"] = dataverse_name;
if (!link_name.empty()) {
values["name"] = link_name;
if ((link_name.has_value() && !link_name.value().empty()) &&
(!dataverse_name.has_value() || dataverse_name.value().empty())) {
return couchbase::errc::common::invalid_argument;
}

if (dataverse_name.has_value() && !dataverse_name.value().empty()) {
if (std::count(dataverse_name.value().begin(), dataverse_name.value().end(), '/') == 0) {
values["dataverse"] = dataverse_name.value();
if (link_name.has_value() && !link_name.value().empty()) {
values["name"] = link_name.value();
}
}
encoded.path = "/analytics/link";
} else {
if (link_name.empty()) {
encoded.path =
fmt::format("/analytics/link/{}", utils::string_codec::v2::path_escape(dataverse_name));
encoded.path = "/analytics/link";
} else {
encoded.path = fmt::format(
"/analytics/link/{}/{}", utils::string_codec::v2::path_escape(dataverse_name), link_name);
if (!link_name.has_value() || link_name.value().empty()) {
encoded.path = fmt::format("/analytics/link/{}",
utils::string_codec::v2::path_escape(dataverse_name.value()));
} else {
encoded.path = fmt::format("/analytics/link/{}/{}",
utils::string_codec::v2::path_escape(dataverse_name.value()),
link_name.value());
}
}
} else {
encoded.path = "/analytics/link";
}
if (!values.empty()) {
encoded.path.append(fmt::format("?{}", utils::string_codec::v2::form_encode(values)));
Expand Down
6 changes: 3 additions & 3 deletions core/operations/management/analytics_link_get_all.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ struct analytics_link_get_all_request {

static const inline service_type type = service_type::analytics;

std::string link_type{};
std::string link_name{};
std::string dataverse_name{};
std::optional<std::string> link_type{};
std::optional<std::string> link_name{};
std::optional<std::string> dataverse_name{};

std::optional<std::string> client_context_id{};
std::optional<std::chrono::milliseconds> timeout{};
Expand Down
14 changes: 14 additions & 0 deletions test/test_integration_management.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3930,6 +3930,13 @@ run_s3_link_test_core_api(test::utils::integration_test_guard& integration,
REQUIRE(resp.ctx.ec == couchbase::errc::analytics::link_exists);
}

{
couchbase::core::operations::management::analytics_link_get_all_request req{};
req.link_name = link_name;
auto resp = test::utils::execute(integration.cluster, req);
REQUIRE(resp.ctx.ec == couchbase::errc::common::invalid_argument);
}

{
couchbase::core::operations::management::analytics_link_get_all_request req{};
req.dataverse_name = dataverse_name;
Expand Down Expand Up @@ -4545,6 +4552,13 @@ run_s3_link_test_public_api(test::utils::integration_test_guard& integration,
REQUIRE(error.ec() == couchbase::errc::analytics::link_exists);
}

{
auto opts = couchbase::get_links_analytics_options().name(link_name);
auto [error, res] = mgr.get_links(opts).get();
REQUIRE(error.ec() == couchbase::errc::common::invalid_argument);
REQUIRE(res.empty());
}

{
auto opts = couchbase::get_links_analytics_options().dataverse_name(dataverse_name);
auto [error, res] = mgr.get_links(opts).get();
Expand Down

0 comments on commit 960bdda

Please sign in to comment.