couchbase 3.0.2 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/CMakeLists.txt +3 -0
  4. data/ext/build_version.hxx.in +1 -1
  5. data/ext/cmake/CompilerWarnings.cmake +1 -0
  6. data/ext/cmake/PreventInSourceBuilds.cmake +4 -1
  7. data/ext/couchbase/bucket.hxx +28 -2
  8. data/ext/couchbase/cluster.hxx +8 -2
  9. data/ext/couchbase/couchbase.cxx +955 -511
  10. data/ext/couchbase/error_context/analytics.hxx +46 -0
  11. data/ext/couchbase/error_context/http.hxx +44 -0
  12. data/ext/couchbase/error_context/key_value.hxx +47 -0
  13. data/ext/couchbase/error_context/query.hxx +46 -0
  14. data/ext/couchbase/error_context/search.hxx +47 -0
  15. data/ext/couchbase/error_context/view.hxx +47 -0
  16. data/ext/couchbase/io/dns_codec.hxx +1 -2
  17. data/ext/couchbase/io/http_command.hxx +16 -3
  18. data/ext/couchbase/io/http_context.hxx +1 -1
  19. data/ext/couchbase/io/http_session.hxx +12 -6
  20. data/ext/couchbase/io/http_session_manager.hxx +25 -24
  21. data/ext/couchbase/io/mcbp_session.hxx +8 -2
  22. data/ext/couchbase/io/retry_context.hxx +1 -1
  23. data/ext/couchbase/operations/analytics_dataset_create.hxx +19 -12
  24. data/ext/couchbase/operations/analytics_dataset_drop.hxx +18 -10
  25. data/ext/couchbase/operations/analytics_dataset_get_all.hxx +16 -10
  26. data/ext/couchbase/operations/analytics_dataverse_create.hxx +18 -11
  27. data/ext/couchbase/operations/analytics_dataverse_drop.hxx +17 -11
  28. data/ext/couchbase/operations/analytics_get_pending_mutations.hxx +17 -10
  29. data/ext/couchbase/operations/analytics_index_create.hxx +17 -11
  30. data/ext/couchbase/operations/analytics_index_drop.hxx +16 -10
  31. data/ext/couchbase/operations/analytics_index_get_all.hxx +14 -10
  32. data/ext/couchbase/operations/analytics_link_connect.hxx +15 -9
  33. data/ext/couchbase/operations/analytics_link_disconnect.hxx +16 -10
  34. data/ext/couchbase/operations/bucket_create.hxx +33 -10
  35. data/ext/couchbase/operations/bucket_drop.hxx +9 -8
  36. data/ext/couchbase/operations/bucket_flush.hxx +8 -8
  37. data/ext/couchbase/operations/bucket_get.hxx +15 -10
  38. data/ext/couchbase/operations/bucket_get_all.hxx +14 -7
  39. data/ext/couchbase/operations/bucket_settings.hxx +16 -0
  40. data/ext/couchbase/operations/bucket_update.hxx +32 -10
  41. data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +6 -6
  42. data/ext/couchbase/operations/collection_create.hxx +19 -13
  43. data/ext/couchbase/operations/collection_drop.hxx +18 -12
  44. data/ext/couchbase/operations/collections_manifest_get.hxx +5 -10
  45. data/ext/couchbase/operations/document_analytics.hxx +39 -17
  46. data/ext/couchbase/operations/document_append.hxx +5 -10
  47. data/ext/couchbase/operations/document_decrement.hxx +5 -10
  48. data/ext/couchbase/operations/document_exists.hxx +4 -6
  49. data/ext/couchbase/operations/document_get.hxx +6 -10
  50. data/ext/couchbase/operations/document_get_and_lock.hxx +4 -9
  51. data/ext/couchbase/operations/document_get_and_touch.hxx +4 -9
  52. data/ext/couchbase/operations/document_get_projected.hxx +21 -14
  53. data/ext/couchbase/operations/document_increment.hxx +5 -10
  54. data/ext/couchbase/operations/document_insert.hxx +5 -10
  55. data/ext/couchbase/operations/document_lookup_in.hxx +4 -9
  56. data/ext/couchbase/operations/document_mutate_in.hxx +7 -12
  57. data/ext/couchbase/operations/document_prepend.hxx +5 -10
  58. data/ext/couchbase/operations/document_query.hxx +45 -28
  59. data/ext/couchbase/operations/document_remove.hxx +5 -10
  60. data/ext/couchbase/operations/document_replace.hxx +5 -10
  61. data/ext/couchbase/operations/document_search.hxx +37 -16
  62. data/ext/couchbase/operations/document_touch.hxx +4 -9
  63. data/ext/couchbase/operations/document_unlock.hxx +4 -9
  64. data/ext/couchbase/operations/document_upsert.hxx +5 -10
  65. data/ext/couchbase/operations/document_view.hxx +29 -13
  66. data/ext/couchbase/operations/group_drop.hxx +7 -7
  67. data/ext/couchbase/operations/group_get.hxx +14 -10
  68. data/ext/couchbase/operations/group_get_all.hxx +14 -8
  69. data/ext/couchbase/operations/group_upsert.hxx +15 -9
  70. data/ext/couchbase/operations/http_noop.hxx +5 -5
  71. data/ext/couchbase/operations/mcbp_noop.hxx +3 -9
  72. data/ext/couchbase/operations/query_index_build_deferred.hxx +15 -9
  73. data/ext/couchbase/operations/query_index_create.hxx +16 -10
  74. data/ext/couchbase/operations/query_index_drop.hxx +16 -10
  75. data/ext/couchbase/operations/query_index_get_all.hxx +13 -7
  76. data/ext/couchbase/operations/role_get_all.hxx +14 -8
  77. data/ext/couchbase/operations/scope_create.hxx +19 -13
  78. data/ext/couchbase/operations/scope_drop.hxx +17 -11
  79. data/ext/couchbase/operations/scope_get_all.hxx +15 -10
  80. data/ext/couchbase/operations/search_get_stats.hxx +5 -5
  81. data/ext/couchbase/operations/search_index_analyze_document.hxx +25 -13
  82. data/ext/couchbase/operations/search_index_control_ingest.hxx +23 -11
  83. data/ext/couchbase/operations/search_index_control_plan_freeze.hxx +23 -11
  84. data/ext/couchbase/operations/search_index_control_query.hxx +23 -11
  85. data/ext/couchbase/operations/search_index_drop.hxx +22 -10
  86. data/ext/couchbase/operations/search_index_get.hxx +22 -10
  87. data/ext/couchbase/operations/search_index_get_all.hxx +13 -7
  88. data/ext/couchbase/operations/search_index_get_documents_count.hxx +24 -13
  89. data/ext/couchbase/operations/search_index_get_stats.hxx +16 -10
  90. data/ext/couchbase/operations/search_index_upsert.hxx +23 -11
  91. data/ext/couchbase/operations/user_drop.hxx +8 -8
  92. data/ext/couchbase/operations/user_get.hxx +14 -10
  93. data/ext/couchbase/operations/user_get_all.hxx +14 -8
  94. data/ext/couchbase/operations/user_upsert.hxx +15 -9
  95. data/ext/couchbase/operations/view_index_drop.hxx +7 -7
  96. data/ext/couchbase/operations/view_index_get.hxx +15 -9
  97. data/ext/couchbase/operations/view_index_get_all.hxx +15 -9
  98. data/ext/couchbase/operations/view_index_upsert.hxx +8 -8
  99. data/ext/couchbase/origin.hxx +1 -0
  100. data/ext/couchbase/platform/terminate_handler.cc +12 -8
  101. data/ext/couchbase/protocol/client_request.hxx +2 -1
  102. data/ext/couchbase/protocol/client_response.hxx +18 -15
  103. data/ext/couchbase/protocol/cmd_exists.hxx +1 -0
  104. data/ext/couchbase/protocol/cmd_get.hxx +1 -1
  105. data/ext/couchbase/protocol/cmd_mutate_in.hxx +3 -4
  106. data/ext/couchbase/protocol/enhanced_error_info.hxx +28 -0
  107. data/ext/couchbase/utils/connection_string.hxx +1 -1
  108. data/ext/couchbase/version.hxx +1 -1
  109. data/ext/extconf.rb +1 -1
  110. data/ext/test/test_native_binary_operations.cxx +18 -18
  111. data/ext/test/test_native_diagnostics.cxx +2 -2
  112. data/ext/test/test_native_trivial_crud.cxx +2 -2
  113. data/ext/third_party/json/include/tao/json/external/pegtl/internal/file_reader.hpp +1 -5
  114. data/lib/active_support/cache/couchbase_store.rb +362 -0
  115. data/lib/couchbase.rb +2 -0
  116. data/lib/couchbase/authenticator.rb +26 -0
  117. data/lib/couchbase/binary_collection.rb +1 -0
  118. data/lib/couchbase/bucket.rb +1 -0
  119. data/lib/couchbase/cluster.rb +51 -27
  120. data/lib/couchbase/collection.rb +19 -4
  121. data/lib/couchbase/collection_options.rb +10 -0
  122. data/lib/couchbase/configuration.rb +57 -0
  123. data/lib/couchbase/datastructures.rb +6 -0
  124. data/lib/couchbase/errors.rb +111 -3
  125. data/lib/couchbase/management.rb +27 -0
  126. data/lib/couchbase/management/bucket_manager.rb +9 -2
  127. data/lib/couchbase/management/collection_manager.rb +1 -1
  128. data/lib/couchbase/management/user_manager.rb +18 -2
  129. data/lib/couchbase/options.rb +33 -23
  130. data/lib/couchbase/railtie.rb +45 -0
  131. data/lib/couchbase/scope.rb +44 -3
  132. data/lib/couchbase/utils.rb +21 -0
  133. data/lib/couchbase/utils/time.rb +52 -0
  134. data/lib/couchbase/version.rb +1 -1
  135. data/lib/rails/generators/couchbase/config/config_generator.rb +27 -0
  136. metadata +19 -5
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ struct analytics_index_create_response {
29
29
  std::string message;
30
30
  };
31
31
 
32
- std::string client_context_id;
33
- std::error_code ec;
32
+ error_context::http ctx;
34
33
  std::string status{};
35
34
  std::vector<problem> errors{};
36
35
  };
@@ -39,6 +38,7 @@ struct analytics_index_create_request {
39
38
  using response_type = analytics_index_create_response;
40
39
  using encoded_request_type = io::http_request;
41
40
  using encoded_response_type = io::http_response;
41
+ using error_context_type = error_context::http;
42
42
 
43
43
  static const inline service_type type = service_type::analytics;
44
44
 
@@ -79,11 +79,17 @@ struct analytics_index_create_request {
79
79
  };
80
80
 
81
81
  analytics_index_create_response
82
- make_response(std::error_code ec, analytics_index_create_request& request, analytics_index_create_request::encoded_response_type&& encoded)
82
+ make_response(error_context::http&& ctx, analytics_index_create_request&, analytics_index_create_request::encoded_response_type&& encoded)
83
83
  {
84
- analytics_index_create_response response{ request.client_context_id, ec };
85
- if (!ec) {
86
- auto payload = tao::json::from_string(encoded.body);
84
+ analytics_index_create_response response{ ctx };
85
+ if (!response.ctx.ec) {
86
+ tao::json::value payload{};
87
+ try {
88
+ payload = tao::json::from_string(encoded.body);
89
+ } catch (tao::json::pegtl::parse_error& e) {
90
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
91
+ return response;
92
+ }
87
93
  response.status = payload.at("status").get_string();
88
94
 
89
95
  if (response.status != "success") {
@@ -113,13 +119,13 @@ make_response(std::error_code ec, analytics_index_create_request& request, analy
113
119
  }
114
120
  }
115
121
  if (index_exists) {
116
- response.ec = std::make_error_code(error::common_errc::index_exists);
122
+ response.ctx.ec = std::make_error_code(error::common_errc::index_exists);
117
123
  } else if (dataset_not_found) {
118
- response.ec = std::make_error_code(error::analytics_errc::dataset_not_found);
124
+ response.ctx.ec = std::make_error_code(error::analytics_errc::dataset_not_found);
119
125
  } else if (link_not_found) {
120
- response.ec = std::make_error_code(error::analytics_errc::link_not_found);
126
+ response.ctx.ec = std::make_error_code(error::analytics_errc::link_not_found);
121
127
  } else {
122
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
128
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
123
129
  }
124
130
  }
125
131
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ struct analytics_index_drop_response {
29
29
  std::string message;
30
30
  };
31
31
 
32
- std::string client_context_id;
33
- std::error_code ec;
32
+ error_context::http ctx;
34
33
  std::string status{};
35
34
  std::vector<problem> errors{};
36
35
  };
@@ -39,6 +38,7 @@ struct analytics_index_drop_request {
39
38
  using response_type = analytics_index_drop_response;
40
39
  using encoded_request_type = io::http_request;
41
40
  using encoded_response_type = io::http_response;
41
+ using error_context_type = error_context::http;
42
42
 
43
43
  static const inline service_type type = service_type::analytics;
44
44
 
@@ -67,11 +67,17 @@ struct analytics_index_drop_request {
67
67
  };
68
68
 
69
69
  analytics_index_drop_response
70
- make_response(std::error_code ec, analytics_index_drop_request& request, analytics_index_drop_request::encoded_response_type&& encoded)
70
+ make_response(error_context::http&& ctx, analytics_index_drop_request&, analytics_index_drop_request::encoded_response_type&& encoded)
71
71
  {
72
- analytics_index_drop_response response{ request.client_context_id, ec };
73
- if (!ec) {
74
- auto payload = tao::json::from_string(encoded.body);
72
+ analytics_index_drop_response response{ ctx };
73
+ if (!response.ctx.ec) {
74
+ tao::json::value payload{};
75
+ try {
76
+ payload = tao::json::from_string(encoded.body);
77
+ } catch (tao::json::pegtl::parse_error& e) {
78
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
79
+ return response;
80
+ }
75
81
  response.status = payload.at("status").get_string();
76
82
 
77
83
  if (response.status != "success") {
@@ -97,11 +103,11 @@ make_response(std::error_code ec, analytics_index_drop_request& request, analyti
97
103
  }
98
104
  }
99
105
  if (index_does_not_exist) {
100
- response.ec = std::make_error_code(error::common_errc::index_not_found);
106
+ response.ctx.ec = std::make_error_code(error::common_errc::index_not_found);
101
107
  } else if (dataset_not_found) {
102
- response.ec = std::make_error_code(error::analytics_errc::dataset_not_found);
108
+ response.ctx.ec = std::make_error_code(error::analytics_errc::dataset_not_found);
103
109
  } else {
104
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
110
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
105
111
  }
106
112
  }
107
113
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -36,8 +36,7 @@ struct analytics_index_get_all_response {
36
36
  std::string message;
37
37
  };
38
38
 
39
- std::string client_context_id;
40
- std::error_code ec;
39
+ error_context::http ctx;
41
40
  std::string status{};
42
41
  std::vector<index> indexes{};
43
42
  std::vector<problem> errors{};
@@ -47,6 +46,7 @@ struct analytics_index_get_all_request {
47
46
  using response_type = analytics_index_get_all_response;
48
47
  using encoded_request_type = io::http_request;
49
48
  using encoded_response_type = io::http_response;
49
+ using error_context_type = error_context::http;
50
50
 
51
51
  static const inline service_type type = service_type::analytics;
52
52
 
@@ -68,14 +68,18 @@ struct analytics_index_get_all_request {
68
68
  };
69
69
 
70
70
  analytics_index_get_all_response
71
- make_response(std::error_code ec,
72
- analytics_index_get_all_request& request,
73
- analytics_index_get_all_request::encoded_response_type&& encoded)
71
+ make_response(error_context::http&& ctx, analytics_index_get_all_request&, analytics_index_get_all_request::encoded_response_type&& encoded)
74
72
  {
75
- analytics_index_get_all_response response{ request.client_context_id, ec };
73
+ analytics_index_get_all_response response{ ctx };
76
74
 
77
- if (!ec) {
78
- auto payload = tao::json::from_string(encoded.body);
75
+ if (!response.ctx.ec) {
76
+ tao::json::value payload{};
77
+ try {
78
+ payload = tao::json::from_string(encoded.body);
79
+ } catch (tao::json::pegtl::parse_error& e) {
80
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
81
+ return response;
82
+ }
79
83
  response.status = payload.at("status").get_string();
80
84
  if (response.status == "success") {
81
85
  auto* results = payload.find("results");
@@ -100,7 +104,7 @@ make_response(std::error_code ec,
100
104
  response.errors.emplace_back(err);
101
105
  }
102
106
  }
103
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
107
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
104
108
  }
105
109
  }
106
110
  return response;
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ struct analytics_link_connect_response {
29
29
  std::string message;
30
30
  };
31
31
 
32
- std::string client_context_id;
33
- std::error_code ec;
32
+ error_context::http ctx;
34
33
  std::string status{};
35
34
  std::vector<problem> errors{};
36
35
  };
@@ -39,6 +38,7 @@ struct analytics_link_connect_request {
39
38
  using response_type = analytics_link_connect_response;
40
39
  using encoded_request_type = io::http_request;
41
40
  using encoded_response_type = io::http_response;
41
+ using error_context_type = error_context::http;
42
42
 
43
43
  static const inline service_type type = service_type::analytics;
44
44
 
@@ -65,11 +65,17 @@ struct analytics_link_connect_request {
65
65
  };
66
66
 
67
67
  analytics_link_connect_response
68
- make_response(std::error_code ec, analytics_link_connect_request& request, analytics_link_connect_request::encoded_response_type&& encoded)
68
+ make_response(error_context::http&& ctx, analytics_link_connect_request&, analytics_link_connect_request::encoded_response_type&& encoded)
69
69
  {
70
- analytics_link_connect_response response{ request.client_context_id, ec };
71
- if (!ec) {
72
- auto payload = tao::json::from_string(encoded.body);
70
+ analytics_link_connect_response response{ ctx };
71
+ if (!response.ctx.ec) {
72
+ tao::json::value payload{};
73
+ try {
74
+ payload = tao::json::from_string(encoded.body);
75
+ } catch (tao::json::pegtl::parse_error& e) {
76
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
77
+ return response;
78
+ }
73
79
  response.status = payload.at("status").get_string();
74
80
 
75
81
  if (response.status != "success") {
@@ -91,9 +97,9 @@ make_response(std::error_code ec, analytics_link_connect_request& request, analy
91
97
  }
92
98
  }
93
99
  if (link_not_found) {
94
- response.ec = std::make_error_code(error::analytics_errc::link_not_found);
100
+ response.ctx.ec = std::make_error_code(error::analytics_errc::link_not_found);
95
101
  } else {
96
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
102
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
97
103
  }
98
104
  }
99
105
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ struct analytics_link_disconnect_response {
29
29
  std::string message;
30
30
  };
31
31
 
32
- std::string client_context_id;
33
- std::error_code ec;
32
+ error_context::http ctx;
34
33
  std::string status{};
35
34
  std::vector<problem> errors{};
36
35
  };
@@ -39,6 +38,7 @@ struct analytics_link_disconnect_request {
39
38
  using response_type = analytics_link_disconnect_response;
40
39
  using encoded_request_type = io::http_request;
41
40
  using encoded_response_type = io::http_response;
41
+ using error_context_type = error_context::http;
42
42
 
43
43
  static const inline service_type type = service_type::analytics;
44
44
 
@@ -62,13 +62,19 @@ struct analytics_link_disconnect_request {
62
62
  };
63
63
 
64
64
  analytics_link_disconnect_response
65
- make_response(std::error_code ec,
66
- analytics_link_disconnect_request& request,
65
+ make_response(error_context::http&& ctx,
66
+ analytics_link_disconnect_request&,
67
67
  analytics_link_disconnect_request::encoded_response_type&& encoded)
68
68
  {
69
- analytics_link_disconnect_response response{ request.client_context_id, ec };
70
- if (!ec) {
71
- auto payload = tao::json::from_string(encoded.body);
69
+ analytics_link_disconnect_response response{ ctx };
70
+ if (!response.ctx.ec) {
71
+ tao::json::value payload{};
72
+ try {
73
+ payload = tao::json::from_string(encoded.body);
74
+ } catch (tao::json::pegtl::parse_error& e) {
75
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
76
+ return response;
77
+ }
72
78
  response.status = payload.at("status").get_string();
73
79
 
74
80
  if (response.status != "success") {
@@ -90,9 +96,9 @@ make_response(std::error_code ec,
90
96
  }
91
97
  }
92
98
  if (link_not_found) {
93
- response.ec = std::make_error_code(error::analytics_errc::link_not_found);
99
+ response.ctx.ec = std::make_error_code(error::analytics_errc::link_not_found);
94
100
  } else {
95
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
101
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
96
102
  }
97
103
  }
98
104
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -22,13 +22,13 @@
22
22
  #include <version.hxx>
23
23
  #include <operations/bucket_settings.hxx>
24
24
  #include <utils/url_codec.hxx>
25
+ #include <error_context/http.hxx>
25
26
 
26
27
  namespace couchbase::operations
27
28
  {
28
29
 
29
30
  struct bucket_create_response {
30
- std::string client_context_id;
31
- std::error_code ec;
31
+ error_context::http ctx;
32
32
  std::string error_message{};
33
33
  };
34
34
 
@@ -36,6 +36,7 @@ struct bucket_create_request {
36
36
  using response_type = bucket_create_response;
37
37
  using encoded_request_type = io::http_request;
38
38
  using encoded_response_type = io::http_response;
39
+ using error_context_type = error_context::http;
39
40
 
40
41
  static const inline service_type type = service_type::management;
41
42
 
@@ -107,22 +108,44 @@ struct bucket_create_request {
107
108
  case bucket_settings::conflict_resolution_type::unknown:
108
109
  break;
109
110
  }
111
+ if (bucket.minimum_durability_level) {
112
+ switch (bucket.minimum_durability_level.value()) {
113
+ case protocol::durability_level::none:
114
+ encoded.body.append("&durabilityMinLevel=none");
115
+ break;
116
+ case protocol::durability_level::majority:
117
+ encoded.body.append("&durabilityMinLevel=majority");
118
+ break;
119
+ case protocol::durability_level::majority_and_persist_to_active:
120
+ encoded.body.append("&durabilityMinLevel=majorityAndPersistActive");
121
+ break;
122
+ case protocol::durability_level::persist_to_majority:
123
+ encoded.body.append("&durabilityMinLevel=persistToMajority");
124
+ break;
125
+ }
126
+ }
110
127
  return {};
111
128
  }
112
129
  };
113
130
 
114
131
  bucket_create_response
115
- make_response(std::error_code ec, bucket_create_request& request, bucket_create_request::encoded_response_type&& encoded)
132
+ make_response(error_context::http&& ctx, bucket_create_request&, bucket_create_request::encoded_response_type&& encoded)
116
133
  {
117
- bucket_create_response response{ request.client_context_id, ec };
118
- if (!ec) {
134
+ bucket_create_response response{ ctx };
135
+ if (!response.ctx.ec) {
119
136
  switch (encoded.status_code) {
120
137
  case 404:
121
- response.ec = std::make_error_code(error::common_errc::bucket_not_found);
138
+ response.ctx.ec = std::make_error_code(error::common_errc::bucket_not_found);
122
139
  break;
123
140
  case 400: {
124
- response.ec = std::make_error_code(error::common_errc::invalid_argument);
125
- auto payload = tao::json::from_string(encoded.body);
141
+ tao::json::value payload{};
142
+ try {
143
+ payload = tao::json::from_string(encoded.body);
144
+ } catch (tao::json::pegtl::parse_error& e) {
145
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
146
+ return response;
147
+ }
148
+ response.ctx.ec = std::make_error_code(error::common_errc::invalid_argument);
126
149
  auto* errors = payload.find("errors");
127
150
  if (errors != nullptr) {
128
151
  std::vector<std::string> error_list{};
@@ -138,7 +161,7 @@ make_response(std::error_code ec, bucket_create_request& request, bucket_create_
138
161
  case 202:
139
162
  break;
140
163
  default:
141
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
164
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
142
165
  break;
143
166
  }
144
167
  }
@@ -18,19 +18,20 @@
18
18
  #pragma once
19
19
 
20
20
  #include <tao/json.hpp>
21
+ #include <error_context/http.hxx>
21
22
 
22
23
  namespace couchbase::operations
23
24
  {
24
25
 
25
26
  struct bucket_drop_response {
26
- std::string client_context_id;
27
- std::error_code ec;
27
+ error_context::http ctx;
28
28
  };
29
29
 
30
30
  struct bucket_drop_request {
31
31
  using response_type = bucket_drop_response;
32
32
  using encoded_request_type = io::http_request;
33
33
  using encoded_response_type = io::http_response;
34
+ using error_context_type = error_context::http;
34
35
 
35
36
  static const inline service_type type = service_type::management;
36
37
 
@@ -47,19 +48,19 @@ struct bucket_drop_request {
47
48
  };
48
49
 
49
50
  bucket_drop_response
50
- make_response(std::error_code ec, bucket_drop_request& request, bucket_drop_request::encoded_response_type&& encoded)
51
+ make_response(error_context::http&& ctx, bucket_drop_request&, bucket_drop_request::encoded_response_type&& encoded)
51
52
  {
52
- bucket_drop_response response{ request.client_context_id, ec };
53
- if (!ec) {
53
+ bucket_drop_response response{ ctx };
54
+ if (!response.ctx.ec) {
54
55
  switch (encoded.status_code) {
55
56
  case 404:
56
- response.ec = std::make_error_code(error::common_errc::bucket_not_found);
57
+ response.ctx.ec = std::make_error_code(error::common_errc::bucket_not_found);
57
58
  break;
58
59
  case 200:
59
- response.ec = {};
60
+ response.ctx.ec = {};
60
61
  break;
61
62
  default:
62
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
63
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
63
64
  break;
64
65
  }
65
66
  }
@@ -23,14 +23,14 @@ namespace couchbase::operations
23
23
  {
24
24
 
25
25
  struct bucket_flush_response {
26
- std::string client_context_id;
27
- std::error_code ec;
26
+ error_context::http ctx;
28
27
  };
29
28
 
30
29
  struct bucket_flush_request {
31
30
  using response_type = bucket_flush_response;
32
31
  using encoded_request_type = io::http_request;
33
32
  using encoded_response_type = io::http_response;
33
+ using error_context_type = error_context::http;
34
34
 
35
35
  static const inline service_type type = service_type::management;
36
36
 
@@ -47,19 +47,19 @@ struct bucket_flush_request {
47
47
  };
48
48
 
49
49
  bucket_flush_response
50
- make_response(std::error_code ec, bucket_flush_request& request, bucket_flush_request::encoded_response_type&& encoded)
50
+ make_response(error_context::http&& ctx, bucket_flush_request&, bucket_flush_request::encoded_response_type&& encoded)
51
51
  {
52
- bucket_flush_response response{ request.client_context_id, ec };
53
- if (!ec) {
52
+ bucket_flush_response response{ ctx };
53
+ if (!response.ctx.ec) {
54
54
  switch (encoded.status_code) {
55
55
  case 404:
56
- response.ec = std::make_error_code(error::common_errc::bucket_not_found);
56
+ response.ctx.ec = std::make_error_code(error::common_errc::bucket_not_found);
57
57
  break;
58
58
  case 200:
59
- response.ec = {};
59
+ response.ctx.ec = {};
60
60
  break;
61
61
  default:
62
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
62
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
63
63
  break;
64
64
  }
65
65
  }