]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: create user cr
authorYehuda Sadeh <yehuda@redhat.com>
Thu, 28 Jun 2018 22:26:30 +0000 (15:26 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 11 Dec 2018 08:10:41 +0000 (00:10 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/CMakeLists.txt
src/rgw/rgw_cr_tools.cc [new file with mode: 0644]
src/rgw/rgw_cr_tools.h [new file with mode: 0644]

index 1072631f072d9f92aa686fc82944270e43a62b40..30a6af0e3151602bb795d377d0098f8536cbe84f 100644 (file)
@@ -94,6 +94,7 @@ set(librgw_common_srcs
   rgw_coroutine.cc
   rgw_cr_rados.cc
   rgw_cr_rest.cc
+  rgw_cr_tools.cc
   rgw_object_expirer_core.cc
   rgw_op.cc
   rgw_otp.cc
diff --git a/src/rgw/rgw_cr_tools.cc b/src/rgw/rgw_cr_tools.cc
new file mode 100644 (file)
index 0000000..ee9b9e1
--- /dev/null
@@ -0,0 +1,79 @@
+#include "rgw_cr_tools.h"
+#include "rgw_user.h"
+
+template<>
+int RGWUserCreateCR::Request::_send_request()
+{
+  CephContext *cct = store->ctx();
+
+  int32_t default_max_buckets = cct->_conf->rgw_user_max_buckets;
+
+  RGWUserAdminOpState op_state;
+
+  rgw_user uid(params.uid);
+
+  uid.tenant = params.tenant_name;
+
+  op_state.set_user_id(uid);
+  op_state.set_display_name(params.display_name);
+  op_state.set_user_email(params.email);
+  op_state.set_caps(params.caps);
+  op_state.set_access_key(params.access_key);
+  op_state.set_secret_key(params.secret_key);
+
+  if (!params.key_type.empty()) {
+    int32_t key_type = KEY_TYPE_S3;
+    if (params.key_type == "swift") {
+      key_type = KEY_TYPE_SWIFT;
+    }
+
+    op_state.set_key_type(key_type);
+  }
+
+  op_state.set_max_buckets(params.max_buckets.value_or(default_max_buckets));
+  op_state.set_suspension(params.suspended);
+  op_state.set_system(params.system);
+  op_state.set_exclusive(params.exclusive);
+
+  if (params.generate_key) {
+    op_state.set_generate_key();
+  }
+
+
+  if (params.apply_quota) {
+    RGWQuotaInfo bucket_quota;
+    RGWQuotaInfo user_quota;
+
+    if (cct->_conf->rgw_bucket_default_quota_max_objects >= 0) {
+      bucket_quota.max_objects = cct->_conf->rgw_bucket_default_quota_max_objects;
+      bucket_quota.enabled = true;
+    }
+
+    if (cct->_conf->rgw_bucket_default_quota_max_size >= 0) {
+      bucket_quota.max_size = cct->_conf->rgw_bucket_default_quota_max_size;
+      bucket_quota.enabled = true;
+    }
+
+    if (cct->_conf->rgw_user_default_quota_max_objects >= 0) {
+      user_quota.max_objects = cct->_conf->rgw_user_default_quota_max_objects;
+      user_quota.enabled = true;
+    }
+
+    if (cct->_conf->rgw_user_default_quota_max_size >= 0) {
+      user_quota.max_size = cct->_conf->rgw_user_default_quota_max_size;
+      user_quota.enabled = true;
+    }
+
+    if (bucket_quota.enabled) {
+      op_state.set_bucket_quota(bucket_quota);
+    }
+
+    if (user_quota.enabled) {
+      op_state.set_user_quota(user_quota);
+    }
+  }
+
+  RGWNullFlusher flusher;
+  return RGWUserAdminOp_User::create(store, op_state, flusher);
+}
+
diff --git a/src/rgw/rgw_cr_tools.h b/src/rgw/rgw_cr_tools.h
new file mode 100644 (file)
index 0000000..9cd0b01
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef CEPH_RGW_CR_TOOLS_H
+#define CEPH_RGW_CR_TOOLS_H
+
+#include "rgw_cr_rados.h"
+
+
+struct rgw_user_create_params {
+  std::string uid;
+  std::string display_name;
+  std::string email;
+  std::string access_key;
+  std::string secret_key;
+  std::string key_type; /* "swift" or "s3" */
+  std::string caps;
+  std::string tenant_name;
+
+  bool generate_key{true};
+  bool suspended{false};
+  std::optional<int32_t> max_buckets;
+  bool system{false};
+  bool exclusive{false};
+  bool apply_quota{true};
+};
+
+using RGWUserCreateCR = RGWSimpleWriteOnlyAsyncCR<rgw_user_create_params>;
+
+
+
+#endif