couchbase 3.0.0.alpha.1-universal-darwin-19 → 3.0.0.alpha.2-universal-darwin-19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests-6.0.3.yml +49 -0
  3. data/.github/workflows/tests.yml +47 -0
  4. data/.gitmodules +3 -0
  5. data/.idea/dictionaries/gem_terms.xml +5 -0
  6. data/.idea/inspectionProfiles/Project_Default.xml +1 -0
  7. data/.idea/vcs.xml +1 -0
  8. data/Gemfile +1 -0
  9. data/README.md +55 -2
  10. data/Rakefile +18 -0
  11. data/bin/init-cluster +62 -0
  12. data/bin/setup +1 -0
  13. data/couchbase.gemspec +3 -2
  14. data/examples/crud.rb +1 -2
  15. data/examples/managing_buckets.rb +47 -0
  16. data/examples/managing_collections.rb +58 -0
  17. data/examples/managing_query_indexes.rb +63 -0
  18. data/examples/query.rb +3 -2
  19. data/examples/query_with_consistency.rb +76 -0
  20. data/examples/subdocument.rb +23 -1
  21. data/ext/.clang-format +1 -1
  22. data/ext/.idea/dictionaries/couchbase_terms.xml +2 -0
  23. data/ext/.idea/vcs.xml +1 -0
  24. data/ext/CMakeLists.txt +30 -12
  25. data/ext/build_version.hxx.in +26 -0
  26. data/ext/couchbase/bucket.hxx +69 -8
  27. data/ext/couchbase/cluster.hxx +70 -54
  28. data/ext/couchbase/collections_manifest.hxx +3 -3
  29. data/ext/couchbase/configuration.hxx +14 -0
  30. data/ext/couchbase/couchbase.cxx +2044 -383
  31. data/ext/couchbase/{operations/document_id.hxx → document_id.hxx} +5 -4
  32. data/ext/couchbase/io/http_message.hxx +5 -1
  33. data/ext/couchbase/io/http_parser.hxx +2 -1
  34. data/ext/couchbase/io/http_session.hxx +6 -3
  35. data/ext/couchbase/io/{binary_message.hxx → mcbp_message.hxx} +15 -12
  36. data/ext/couchbase/io/mcbp_parser.hxx +99 -0
  37. data/ext/couchbase/io/{key_value_session.hxx → mcbp_session.hxx} +200 -95
  38. data/ext/couchbase/io/session_manager.hxx +37 -22
  39. data/ext/couchbase/mutation_token.hxx +2 -1
  40. data/ext/couchbase/operations.hxx +38 -8
  41. data/ext/couchbase/operations/bucket_create.hxx +138 -0
  42. data/ext/couchbase/operations/bucket_drop.hxx +65 -0
  43. data/ext/couchbase/operations/bucket_flush.hxx +65 -0
  44. data/ext/couchbase/operations/bucket_get.hxx +69 -0
  45. data/ext/couchbase/operations/bucket_get_all.hxx +62 -0
  46. data/ext/couchbase/operations/bucket_settings.hxx +111 -0
  47. data/ext/couchbase/operations/bucket_update.hxx +115 -0
  48. data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +60 -0
  49. data/ext/couchbase/operations/collection_create.hxx +86 -0
  50. data/ext/couchbase/operations/collection_drop.hxx +82 -0
  51. data/ext/couchbase/operations/command.hxx +10 -10
  52. data/ext/couchbase/operations/document_decrement.hxx +80 -0
  53. data/ext/couchbase/operations/document_exists.hxx +80 -0
  54. data/ext/couchbase/operations/{get.hxx → document_get.hxx} +4 -2
  55. data/ext/couchbase/operations/document_get_and_lock.hxx +64 -0
  56. data/ext/couchbase/operations/document_get_and_touch.hxx +64 -0
  57. data/ext/couchbase/operations/document_increment.hxx +80 -0
  58. data/ext/couchbase/operations/document_insert.hxx +74 -0
  59. data/ext/couchbase/operations/{lookup_in.hxx → document_lookup_in.hxx} +2 -2
  60. data/ext/couchbase/operations/{mutate_in.hxx → document_mutate_in.hxx} +11 -2
  61. data/ext/couchbase/operations/{query.hxx → document_query.hxx} +101 -6
  62. data/ext/couchbase/operations/document_remove.hxx +67 -0
  63. data/ext/couchbase/operations/document_replace.hxx +76 -0
  64. data/ext/couchbase/operations/{upsert.hxx → document_touch.hxx} +14 -14
  65. data/ext/couchbase/operations/{remove.hxx → document_unlock.hxx} +12 -10
  66. data/ext/couchbase/operations/document_upsert.hxx +74 -0
  67. data/ext/couchbase/operations/query_index_build_deferred.hxx +85 -0
  68. data/ext/couchbase/operations/query_index_create.hxx +134 -0
  69. data/ext/couchbase/operations/query_index_drop.hxx +108 -0
  70. data/ext/couchbase/operations/query_index_get_all.hxx +106 -0
  71. data/ext/couchbase/operations/scope_create.hxx +81 -0
  72. data/ext/couchbase/operations/scope_drop.hxx +79 -0
  73. data/ext/couchbase/operations/scope_get_all.hxx +72 -0
  74. data/ext/couchbase/protocol/client_opcode.hxx +35 -0
  75. data/ext/couchbase/protocol/client_request.hxx +56 -9
  76. data/ext/couchbase/protocol/client_response.hxx +52 -15
  77. data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +81 -0
  78. data/ext/couchbase/protocol/cmd_decrement.hxx +187 -0
  79. data/ext/couchbase/protocol/cmd_exists.hxx +171 -0
  80. data/ext/couchbase/protocol/cmd_get.hxx +31 -8
  81. data/ext/couchbase/protocol/cmd_get_and_lock.hxx +142 -0
  82. data/ext/couchbase/protocol/cmd_get_and_touch.hxx +142 -0
  83. data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +16 -3
  84. data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +16 -3
  85. data/ext/couchbase/protocol/cmd_get_error_map.hxx +16 -3
  86. data/ext/couchbase/protocol/cmd_hello.hxx +24 -8
  87. data/ext/couchbase/protocol/cmd_increment.hxx +187 -0
  88. data/ext/couchbase/protocol/cmd_info.hxx +1 -0
  89. data/ext/couchbase/protocol/cmd_insert.hxx +172 -0
  90. data/ext/couchbase/protocol/cmd_lookup_in.hxx +28 -13
  91. data/ext/couchbase/protocol/cmd_mutate_in.hxx +65 -13
  92. data/ext/couchbase/protocol/cmd_remove.hxx +59 -4
  93. data/ext/couchbase/protocol/cmd_replace.hxx +172 -0
  94. data/ext/couchbase/protocol/cmd_sasl_auth.hxx +15 -3
  95. data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +15 -3
  96. data/ext/couchbase/protocol/cmd_sasl_step.hxx +15 -3
  97. data/ext/couchbase/protocol/cmd_select_bucket.hxx +14 -2
  98. data/ext/couchbase/protocol/cmd_touch.hxx +102 -0
  99. data/ext/couchbase/protocol/cmd_unlock.hxx +95 -0
  100. data/ext/couchbase/protocol/cmd_upsert.hxx +50 -14
  101. data/ext/couchbase/protocol/durability_level.hxx +67 -0
  102. data/ext/couchbase/protocol/frame_info_id.hxx +187 -0
  103. data/ext/couchbase/protocol/hello_feature.hxx +137 -0
  104. data/ext/couchbase/protocol/server_opcode.hxx +57 -0
  105. data/ext/couchbase/protocol/server_request.hxx +122 -0
  106. data/ext/couchbase/protocol/unsigned_leb128.h +15 -15
  107. data/ext/couchbase/utils/byteswap.hxx +1 -2
  108. data/ext/couchbase/utils/url_codec.hxx +225 -0
  109. data/ext/couchbase/version.hxx +3 -1
  110. data/ext/extconf.rb +4 -1
  111. data/ext/test/main.cxx +37 -113
  112. data/ext/third_party/snappy/.appveyor.yml +36 -0
  113. data/ext/third_party/snappy/.gitignore +8 -0
  114. data/ext/third_party/snappy/.travis.yml +98 -0
  115. data/ext/third_party/snappy/AUTHORS +1 -0
  116. data/ext/third_party/snappy/CMakeLists.txt +345 -0
  117. data/ext/third_party/snappy/CONTRIBUTING.md +26 -0
  118. data/ext/third_party/snappy/COPYING +54 -0
  119. data/ext/third_party/snappy/NEWS +188 -0
  120. data/ext/third_party/snappy/README.md +148 -0
  121. data/ext/third_party/snappy/cmake/SnappyConfig.cmake.in +33 -0
  122. data/ext/third_party/snappy/cmake/config.h.in +59 -0
  123. data/ext/third_party/snappy/docs/README.md +72 -0
  124. data/ext/third_party/snappy/format_description.txt +110 -0
  125. data/ext/third_party/snappy/framing_format.txt +135 -0
  126. data/ext/third_party/snappy/snappy-c.cc +90 -0
  127. data/ext/third_party/snappy/snappy-c.h +138 -0
  128. data/ext/third_party/snappy/snappy-internal.h +315 -0
  129. data/ext/third_party/snappy/snappy-sinksource.cc +121 -0
  130. data/ext/third_party/snappy/snappy-sinksource.h +182 -0
  131. data/ext/third_party/snappy/snappy-stubs-internal.cc +42 -0
  132. data/ext/third_party/snappy/snappy-stubs-internal.h +493 -0
  133. data/ext/third_party/snappy/snappy-stubs-public.h.in +63 -0
  134. data/ext/third_party/snappy/snappy-test.cc +613 -0
  135. data/ext/third_party/snappy/snappy-test.h +526 -0
  136. data/ext/third_party/snappy/snappy.cc +1770 -0
  137. data/ext/third_party/snappy/snappy.h +209 -0
  138. data/ext/third_party/snappy/snappy_compress_fuzzer.cc +60 -0
  139. data/ext/third_party/snappy/snappy_uncompress_fuzzer.cc +58 -0
  140. data/ext/third_party/snappy/snappy_unittest.cc +1512 -0
  141. data/ext/third_party/snappy/testdata/alice29.txt +3609 -0
  142. data/ext/third_party/snappy/testdata/asyoulik.txt +4122 -0
  143. data/ext/third_party/snappy/testdata/baddata1.snappy +0 -0
  144. data/ext/third_party/snappy/testdata/baddata2.snappy +0 -0
  145. data/ext/third_party/snappy/testdata/baddata3.snappy +0 -0
  146. data/ext/third_party/snappy/testdata/fireworks.jpeg +0 -0
  147. data/ext/third_party/snappy/testdata/geo.protodata +0 -0
  148. data/ext/third_party/snappy/testdata/html +1 -0
  149. data/ext/third_party/snappy/testdata/html_x_4 +1 -0
  150. data/ext/third_party/snappy/testdata/kppkn.gtb +0 -0
  151. data/ext/third_party/snappy/testdata/lcet10.txt +7519 -0
  152. data/ext/third_party/snappy/testdata/paper-100k.pdf +600 -2
  153. data/ext/third_party/snappy/testdata/plrabn12.txt +10699 -0
  154. data/ext/third_party/snappy/testdata/urls.10K +10000 -0
  155. data/lib/couchbase/binary_collection.rb +33 -76
  156. data/lib/couchbase/binary_collection_options.rb +94 -0
  157. data/lib/couchbase/bucket.rb +9 -3
  158. data/lib/couchbase/cluster.rb +161 -23
  159. data/lib/couchbase/collection.rb +108 -191
  160. data/lib/couchbase/collection_options.rb +430 -0
  161. data/lib/couchbase/errors.rb +136 -134
  162. data/lib/couchbase/json_transcoder.rb +32 -0
  163. data/lib/couchbase/management/analytics_index_manager.rb +185 -9
  164. data/lib/couchbase/management/bucket_manager.rb +84 -33
  165. data/lib/couchbase/management/collection_manager.rb +166 -1
  166. data/lib/couchbase/management/query_index_manager.rb +261 -0
  167. data/lib/couchbase/management/search_index_manager.rb +291 -0
  168. data/lib/couchbase/management/user_manager.rb +12 -10
  169. data/lib/couchbase/management/view_index_manager.rb +151 -1
  170. data/lib/couchbase/mutation_state.rb +11 -1
  171. data/lib/couchbase/scope.rb +4 -4
  172. data/lib/couchbase/version.rb +1 -1
  173. metadata +113 -18
  174. data/.travis.yml +0 -7
  175. data/ext/couchbase/io/binary_parser.hxx +0 -64
  176. data/lib/couchbase/results.rb +0 -307
@@ -0,0 +1,62 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include <tao/json.hpp>
21
+
22
+ #include <version.hxx>
23
+ #include <operations/bucket_settings.hxx>
24
+
25
+ namespace couchbase::operations
26
+ {
27
+
28
+ struct bucket_get_all_response {
29
+ std::error_code ec;
30
+ std::vector<bucket_settings> buckets{};
31
+ };
32
+
33
+ struct bucket_get_all_request {
34
+ using response_type = bucket_get_all_response;
35
+ using encoded_request_type = io::http_request;
36
+ using encoded_response_type = io::http_response;
37
+
38
+ static const inline service_type type = service_type::management;
39
+
40
+ void encode_to(encoded_request_type& encoded)
41
+ {
42
+ encoded.method = "GET";
43
+ encoded.path = "/pools/default/buckets";
44
+ }
45
+ };
46
+
47
+ bucket_get_all_response
48
+ make_response(std::error_code ec, bucket_get_all_request&, bucket_get_all_request::encoded_response_type encoded)
49
+ {
50
+ bucket_get_all_response response{ ec };
51
+ if (!ec) {
52
+ auto payload = tao::json::from_string(encoded.body);
53
+ const auto& entries = payload.get_array();
54
+ response.buckets.reserve(entries.size());
55
+ for (const auto& entry : entries) {
56
+ response.buckets.emplace_back(entry.as<bucket_settings>());
57
+ }
58
+ }
59
+ return response;
60
+ }
61
+
62
+ } // namespace couchbase::operations
@@ -0,0 +1,111 @@
1
+ #pragma once
2
+
3
+ namespace couchbase::operations
4
+ {
5
+ struct bucket_settings {
6
+ enum class bucket_type { unknown, couchbase, memcached, ephemeral };
7
+ enum class compression_mode { unknown, off, active, passive };
8
+ enum class ejection_policy { unknown, full, value_only };
9
+ enum class conflict_resolution_type { unknown, timestamp, sequence_number };
10
+ struct node {
11
+ std::string hostname;
12
+ std::string status;
13
+ std::string version;
14
+ std::vector<std::string> services;
15
+ std::map<std::string, std::uint16_t> ports;
16
+ };
17
+
18
+ std::string name;
19
+ std::string uuid;
20
+ bucket_type bucket_type{ bucket_type::unknown };
21
+ std::uint64_t ram_quota_mb{ 100 };
22
+ std::uint32_t max_expiry{ 0 };
23
+ compression_mode compression_mode{ compression_mode::unknown };
24
+ std::uint32_t num_replicas{ 1 };
25
+ bool replica_indexes{ false };
26
+ bool flush_enabled{ false };
27
+ ejection_policy ejection_policy{ ejection_policy::unknown };
28
+ conflict_resolution_type conflict_resolution_type{ conflict_resolution_type::unknown };
29
+ std::vector<std::string> capabilities{};
30
+ std::vector<node> nodes{};
31
+ };
32
+ } // namespace couchbase::operations
33
+
34
+ namespace tao::json
35
+ {
36
+ template<>
37
+ struct traits<couchbase::operations::bucket_settings> {
38
+ template<template<typename...> class Traits>
39
+ static couchbase::operations::bucket_settings as(const tao::json::basic_value<Traits>& v)
40
+ {
41
+ couchbase::operations::bucket_settings result;
42
+ result.name = v.at("name").get_string();
43
+ result.uuid = v.at("uuid").get_string();
44
+ const static std::uint64_t megabyte = 1024 * 1024;
45
+ result.ram_quota_mb = v.at("quota").at("rawRAM").get_unsigned() / megabyte;
46
+ result.max_expiry = v.at("maxTTL").template as<std::uint32_t>();
47
+ result.num_replicas = v.at("replicaNumber").template as<std::uint32_t>();
48
+ {
49
+ auto& str = v.at("bucketType").get_string();
50
+ if (str == "couchbase" || str == "membase") {
51
+ result.bucket_type = couchbase::operations::bucket_settings::bucket_type::couchbase;
52
+ } else if (str == "ephemeral") {
53
+ result.bucket_type = couchbase::operations::bucket_settings::bucket_type::ephemeral;
54
+ } else if (str == "memcached") {
55
+ result.bucket_type = couchbase::operations::bucket_settings::bucket_type::memcached;
56
+ }
57
+ }
58
+ {
59
+ auto& str = v.at("compressionMode").get_string();
60
+ if (str == "active") {
61
+ result.compression_mode = couchbase::operations::bucket_settings::compression_mode::active;
62
+ } else if (str == "passive") {
63
+ result.compression_mode = couchbase::operations::bucket_settings::compression_mode::passive;
64
+ } else if (str == "off") {
65
+ result.compression_mode = couchbase::operations::bucket_settings::compression_mode::off;
66
+ }
67
+ }
68
+ {
69
+ auto& str = v.at("evictionPolicy").get_string();
70
+ if (str == "valueOnly") {
71
+ result.ejection_policy = couchbase::operations::bucket_settings::ejection_policy::value_only;
72
+ } else if (str == "fullEviction") {
73
+ result.ejection_policy = couchbase::operations::bucket_settings::ejection_policy::full;
74
+ }
75
+ }
76
+ {
77
+ auto& str = v.at("conflictResolutionType").get_string();
78
+ if (str == "lww") {
79
+ result.conflict_resolution_type = couchbase::operations::bucket_settings::conflict_resolution_type::timestamp;
80
+ } else if (str == "seqno") {
81
+ result.conflict_resolution_type = couchbase::operations::bucket_settings::conflict_resolution_type::sequence_number;
82
+ }
83
+ }
84
+ result.flush_enabled = v.at("controllers").find("flush") != nullptr;
85
+ const auto ri = v.find("replicaIndex");
86
+ if (ri) {
87
+ result.replica_indexes = ri->get_boolean();
88
+ }
89
+ const auto caps = v.find("bucketCapabilities");
90
+ if (caps != nullptr) {
91
+ for (auto& cap : caps->get_array()) {
92
+ result.capabilities.emplace_back(cap.get_string());
93
+ }
94
+ }
95
+ for (auto& n : v.at("nodes").get_array()) {
96
+ couchbase::operations::bucket_settings::node node;
97
+ node.status = n.at("status").get_string();
98
+ node.hostname = n.at("hostname").get_string();
99
+ node.version = n.at("version").get_string();
100
+ for (auto& s : n.at("services").get_array()) {
101
+ node.services.emplace_back(s.get_string());
102
+ }
103
+ for (auto& p : n.at("ports").get_object()) {
104
+ node.ports.emplace(p.first, p.second.template as<std::uint16_t>());
105
+ }
106
+ result.nodes.emplace_back(node);
107
+ }
108
+ return result;
109
+ }
110
+ };
111
+ } // namespace tao::json
@@ -0,0 +1,115 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include <tao/json.hpp>
21
+
22
+ #include <version.hxx>
23
+ #include <operations/bucket_settings.hxx>
24
+ #include <utils/url_codec.hxx>
25
+
26
+ namespace couchbase::operations
27
+ {
28
+
29
+ struct bucket_update_response {
30
+ std::error_code ec;
31
+ bucket_settings bucket{};
32
+ std::string error_message{};
33
+ };
34
+
35
+ struct bucket_update_request {
36
+ using response_type = bucket_update_response;
37
+ using encoded_request_type = io::http_request;
38
+ using encoded_response_type = io::http_response;
39
+
40
+ static const inline service_type type = service_type::management;
41
+
42
+ bucket_settings bucket{};
43
+
44
+ void encode_to(encoded_request_type& encoded)
45
+ {
46
+ encoded.method = "POST";
47
+ encoded.path = fmt::format("/pools/default/buckets/{}", bucket.name);
48
+
49
+ encoded.headers["content-type"] = "application/x-www-form-urlencoded";
50
+ encoded.body.append(fmt::format("&ramQuotaMB={}", bucket.ram_quota_mb));
51
+ encoded.body.append(fmt::format("&replicaNumber={}", bucket.num_replicas));
52
+ encoded.body.append(fmt::format("&maxTTL={}", bucket.max_expiry));
53
+ encoded.body.append(fmt::format("&replicaIndex={}", bucket.replica_indexes ? "1" : "0"));
54
+ encoded.body.append(fmt::format("&flushEnabled={}", bucket.flush_enabled ? "1" : "0"));
55
+ switch (bucket.ejection_policy) {
56
+ case bucket_settings::ejection_policy::full:
57
+ encoded.body.append("&evictionPolicy=fullEviction");
58
+ break;
59
+ case bucket_settings::ejection_policy::value_only:
60
+ encoded.body.append("&evictionPolicy=valueOnly");
61
+ break;
62
+ case bucket_settings::ejection_policy::unknown:
63
+ break;
64
+ }
65
+ switch (bucket.compression_mode) {
66
+ case bucket_settings::compression_mode::off:
67
+ encoded.body.append("&compressionMode=off");
68
+ break;
69
+ case bucket_settings::compression_mode::active:
70
+ encoded.body.append("&compressionMode=active");
71
+ break;
72
+ case bucket_settings::compression_mode::passive:
73
+ encoded.body.append("&compressionMode=passive");
74
+ break;
75
+ case bucket_settings::compression_mode::unknown:
76
+ break;
77
+ }
78
+ }
79
+ };
80
+
81
+ bucket_update_response
82
+ make_response(std::error_code ec, bucket_update_request&, bucket_update_request::encoded_response_type encoded)
83
+ {
84
+ bucket_update_response response{ ec };
85
+ if (!ec) {
86
+ switch (encoded.status_code) {
87
+ case 404:
88
+ response.ec = std::make_error_code(error::common_errc::bucket_not_found);
89
+ break;
90
+ case 400: {
91
+ response.ec = std::make_error_code(error::common_errc::invalid_argument);
92
+ auto payload = tao::json::from_string(encoded.body);
93
+ auto* errors = payload.find("errors");
94
+ if (errors != nullptr) {
95
+ std::vector<std::string> error_list{};
96
+ for (auto& err : errors->get_object()) {
97
+ error_list.emplace_back(err.second.get_string());
98
+ }
99
+ if (!error_list.empty()) {
100
+ response.error_message = fmt::format("{}", fmt::join(error_list.begin(), error_list.end(), ". "));
101
+ }
102
+ }
103
+ } break;
104
+ case 200:
105
+ case 202:
106
+ break;
107
+ default:
108
+ response.ec = std::make_error_code(error::common_errc::internal_server_failure);
109
+ break;
110
+ }
111
+ }
112
+ return response;
113
+ }
114
+
115
+ } // namespace couchbase::operations
@@ -0,0 +1,60 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include <tao/json.hpp>
21
+
22
+ #include <version.hxx>
23
+ #include <operations/bucket_settings.hxx>
24
+
25
+ namespace couchbase::operations
26
+ {
27
+
28
+ struct cluster_developer_preview_enable_response {
29
+ std::error_code ec;
30
+ };
31
+
32
+ struct cluster_developer_preview_enable_request {
33
+ using response_type = cluster_developer_preview_enable_response;
34
+ using encoded_request_type = io::http_request;
35
+ using encoded_response_type = io::http_response;
36
+
37
+ static const inline service_type type = service_type::management;
38
+
39
+ void encode_to(encoded_request_type& encoded)
40
+ {
41
+ encoded.method = "POST";
42
+ encoded.headers["content-type"] = "application/x-www-form-urlencoded";
43
+ encoded.path = "/settings/developerPreview";
44
+ encoded.body = "enabled=true";
45
+ }
46
+ };
47
+
48
+ cluster_developer_preview_enable_response
49
+ make_response(std::error_code ec, cluster_developer_preview_enable_request&, scope_get_all_request::encoded_response_type encoded)
50
+ {
51
+ cluster_developer_preview_enable_response response{ ec };
52
+ if (!ec) {
53
+ if (encoded.status_code != 200) {
54
+ response.ec = std::make_error_code(error::common_errc::internal_server_failure);
55
+ }
56
+ }
57
+ return response;
58
+ }
59
+
60
+ } // namespace couchbase::operations
@@ -0,0 +1,86 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include <tao/json.hpp>
21
+
22
+ #include <version.hxx>
23
+ #include <operations/bucket_settings.hxx>
24
+ #include <utils/url_codec.hxx>
25
+
26
+ namespace couchbase::operations
27
+ {
28
+
29
+ struct collection_create_response {
30
+ std::error_code ec;
31
+ std::uint64_t uid{ 0 };
32
+ };
33
+
34
+ struct collection_create_request {
35
+ using response_type = collection_create_response;
36
+ using encoded_request_type = io::http_request;
37
+ using encoded_response_type = io::http_response;
38
+
39
+ static const inline service_type type = service_type::management;
40
+
41
+ std::string bucket_name;
42
+ std::string scope_name;
43
+ std::string collection_name;
44
+ std::uint32_t max_expiry{ 0 };
45
+
46
+ void encode_to(encoded_request_type& encoded)
47
+ {
48
+ encoded.method = "POST";
49
+ encoded.path = fmt::format("/pools/default/buckets/{}/collections/{}", bucket_name, scope_name);
50
+ encoded.headers["content-type"] = "application/x-www-form-urlencoded";
51
+ encoded.body = fmt::format("name={}", utils::string_codec::form_encode(collection_name));
52
+ if (max_expiry > 0) {
53
+ encoded.body.append(fmt::format("&maxTTL={}", max_expiry));
54
+ }
55
+ }
56
+ };
57
+
58
+ collection_create_response
59
+ make_response(std::error_code ec, collection_create_request&, collection_create_request::encoded_response_type encoded)
60
+ {
61
+ collection_create_response response{ ec };
62
+ if (!ec) {
63
+ switch (encoded.status_code) {
64
+ case 400:
65
+ response.ec = std::make_error_code(error::management_errc::collection_exists);
66
+ break;
67
+ case 404:
68
+ if (encoded.body.find("Scope with this name is not found") != std::string::npos) {
69
+ response.ec = std::make_error_code(error::common_errc::scope_not_found);
70
+ } else {
71
+ response.ec = std::make_error_code(error::common_errc::bucket_not_found);
72
+ }
73
+ break;
74
+ case 200: {
75
+ tao::json::value payload = tao::json::from_string(encoded.body);
76
+ response.uid = std::stoull(payload.at("uid").get_string(), 0, 16);
77
+ } break;
78
+ default:
79
+ response.ec = std::make_error_code(error::common_errc::internal_server_failure);
80
+ break;
81
+ }
82
+ }
83
+ return response;
84
+ }
85
+
86
+ } // namespace couchbase::operations
@@ -0,0 +1,82 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include <tao/json.hpp>
21
+
22
+ #include <version.hxx>
23
+ #include <operations/bucket_settings.hxx>
24
+ #include <utils/url_codec.hxx>
25
+
26
+ namespace couchbase::operations
27
+ {
28
+
29
+ struct collection_drop_response {
30
+ std::error_code ec;
31
+ std::uint64_t uid{ 0 };
32
+ };
33
+
34
+ struct collection_drop_request {
35
+ using response_type = collection_drop_response;
36
+ using encoded_request_type = io::http_request;
37
+ using encoded_response_type = io::http_response;
38
+
39
+ static const inline service_type type = service_type::management;
40
+
41
+ std::string bucket_name;
42
+ std::string scope_name;
43
+ std::string collection_name;
44
+
45
+ void encode_to(encoded_request_type& encoded)
46
+ {
47
+ encoded.method = "DELETE";
48
+ encoded.path = fmt::format("/pools/default/buckets/{}/collections/{}/{}", bucket_name, scope_name, collection_name);
49
+ }
50
+ };
51
+
52
+ collection_drop_response
53
+ make_response(std::error_code ec, collection_drop_request&, collection_drop_request::encoded_response_type encoded)
54
+ {
55
+ collection_drop_response response{ ec };
56
+ if (!ec) {
57
+ switch (encoded.status_code) {
58
+ case 400:
59
+ response.ec = std::make_error_code(error::common_errc::unsupported_operation);
60
+ break;
61
+ case 404:
62
+ if (encoded.body.find("Collection with this name is not found") != std::string::npos) {
63
+ response.ec = std::make_error_code(error::common_errc::collection_not_found);
64
+ } else if (encoded.body.find("Scope with this name is not found") != std::string::npos) {
65
+ response.ec = std::make_error_code(error::common_errc::scope_not_found);
66
+ } else {
67
+ response.ec = std::make_error_code(error::common_errc::bucket_not_found);
68
+ }
69
+ break;
70
+ case 200: {
71
+ tao::json::value payload = tao::json::from_string(encoded.body);
72
+ response.uid = std::stoull(payload.at("uid").get_string(), 0, 16);
73
+ } break;
74
+ default:
75
+ response.ec = std::make_error_code(error::common_errc::internal_server_failure);
76
+ break;
77
+ }
78
+ }
79
+ return response;
80
+ }
81
+
82
+ } // namespace couchbase::operations