From: Yehuda Sadeh Date: Thu, 28 Jun 2018 22:26:30 +0000 (-0700) Subject: rgw: create user cr X-Git-Tag: v14.1.0~616^2~69 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d3bcc077a1cffd7200d63bc754711e9fe5dd19dd;p=ceph.git rgw: create user cr Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/CMakeLists.txt b/src/rgw/CMakeLists.txt index 1072631f072d9..30a6af0e31516 100644 --- a/src/rgw/CMakeLists.txt +++ b/src/rgw/CMakeLists.txt @@ -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 index 0000000000000..ee9b9e1376473 --- /dev/null +++ b/src/rgw/rgw_cr_tools.cc @@ -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 index 0000000000000..9cd0b01cf76ff --- /dev/null +++ b/src/rgw/rgw_cr_tools.h @@ -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 max_buckets; + bool system{false}; + bool exclusive{false}; + bool apply_quota{true}; +}; + +using RGWUserCreateCR = RGWSimpleWriteOnlyAsyncCR; + + + +#endif