summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@hq.newdream.net>2011-10-12 00:06:34 +0200
committerYehuda Sadeh <yehuda@hq.newdream.net>2011-10-12 00:06:34 +0200
commite07b956b84962fd794160a54847aa4ccbcecfc89 (patch)
tree33ecc2d861b55142e6f76028d5f5bbea50130df5
parentrgw: encoded swift key contains full user name (diff)
downloadceph-e07b956b84962fd794160a54847aa4ccbcecfc89.tar.xz
ceph-e07b956b84962fd794160a54847aa4ccbcecfc89.zip
rgw: implement some missing swift api, other swift fixes
-rw-r--r--src/rgw/rgw_op.cc37
-rw-r--r--src/rgw/rgw_op.h23
-rw-r--r--src/rgw/rgw_rest.cc5
-rw-r--r--src/rgw/rgw_rest.h6
-rw-r--r--src/rgw/rgw_rest_swift.cc46
-rw-r--r--src/rgw/rgw_rest_swift.h9
-rw-r--r--src/rgw/rgw_swift_auth.cc2
7 files changed, 115 insertions, 13 deletions
diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc
index 6416921bfe0..4f8ebe6bcd4 100644
--- a/src/rgw/rgw_op.cc
+++ b/src/rgw/rgw_op.cc
@@ -350,6 +350,43 @@ void RGWListBuckets::execute()
send_response();
}
+int RGWStatAccount::verify_permission()
+{
+ return 0;
+}
+
+void RGWStatAccount::execute()
+{
+ RGWUserBuckets buckets;
+
+ ret = rgw_read_user_buckets(s->user.user_id, buckets, true);
+ if (ret < 0) {
+ /* hmm.. something wrong here.. the user was authenticated, so it
+ should exist, just try to recreate */
+ dout(10) << "WARNING: failed on rgw_get_user_buckets uid=" << s->user.user_id << dendl;
+
+ /*
+
+ on a second thought, this is probably a bug and we should fail
+
+ rgw_put_user_buckets(s->user.user_id, buckets);
+ ret = 0;
+
+ */
+ } else {
+ map<string, RGWBucketEnt>& m = buckets.get_buckets();
+ map<string, RGWBucketEnt>::iterator iter;
+ for (iter = m.begin(); iter != m.end(); ++iter) {
+ RGWBucketEnt& bucket = iter->second;
+ buckets_size += bucket.size;
+ buckets_objcount += bucket.count;
+ }
+ buckets_count = m.size();
+ }
+
+ send_response();
+}
+
int RGWStatBucket::verify_permission()
{
if (!::verify_permission(s, RGW_PERM_READ))
diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h
index 1687e62635d..c1bd60eb4c4 100644
--- a/src/rgw/rgw_op.h
+++ b/src/rgw/rgw_op.h
@@ -124,6 +124,29 @@ public:
virtual void send_response() = 0;
};
+class RGWStatAccount : public RGWOp {
+protected:
+ int ret;
+ uint32_t buckets_count;
+ uint64_t buckets_objcount;
+ uint64_t buckets_size;
+
+public:
+ virtual void init(struct req_state *s) {
+ RGWOp::init(s);
+ ret = 0;
+ buckets_count = 0;
+ buckets_objcount = 0;
+ buckets_size = 0;
+ }
+ RGWStatAccount() {}
+
+ int verify_permission();
+ void execute();
+
+ virtual void send_response() = 0;
+};
+
class RGWListBucket : public RGWOp {
protected:
string prefix;
diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc
index d372dec0a67..7daeb9a8cae 100644
--- a/src/rgw/rgw_rest.cc
+++ b/src/rgw/rgw_rest.cc
@@ -455,16 +455,13 @@ void init_entities_from_header(struct req_state *s)
if (s->prot_flags & RGW_REST_SWIFT) {
string ver;
- string auth_key;
next_tok(req, ver, '/');
dout(10) << "ver=" << ver << dendl;
- next_tok(req, auth_key, '/');
- dout(10) << "auth_key=" << auth_key << dendl;
s->os_auth_token = s->env->get("HTTP_X_AUTH_TOKEN");
next_tok(req, first, '/');
- dout(10) << "ver=" << ver << " auth_key=" << auth_key << " first=" << first << " req=" << req << dendl;
+ dout(10) << "ver=" << ver << " first=" << first << " req=" << req << dendl;
if (first.size() == 0)
goto done;
diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h
index d94d29952d8..178e767d45d 100644
--- a/src/rgw/rgw_rest.h
+++ b/src/rgw/rgw_rest.h
@@ -32,6 +32,12 @@ public:
~RGWListBucket_REST() {}
};
+class RGWStatAccount_REST : public RGWStatAccount {
+public:
+ RGWStatAccount_REST() {}
+ ~RGWStatAccount_REST() {}
+};
+
class RGWStatBucket_REST : public RGWStatBucket {
public:
RGWStatBucket_REST() {}
diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc
index 8ffdcb656c7..13e73422996 100644
--- a/src/rgw/rgw_rest_swift.cc
+++ b/src/rgw/rgw_rest_swift.cc
@@ -120,31 +120,58 @@ void RGWListBucket_REST_SWIFT::send_response()
static void dump_container_metadata(struct req_state *s, RGWBucketEnt& bucket)
{
- char buf[16];
+ char buf[32];
snprintf(buf, sizeof(buf), "%lld", (long long)bucket.count);
CGI_PRINTF(s,"X-Container-Object-Count: %s\n", buf);
snprintf(buf, sizeof(buf), "%lld", (long long)bucket.size);
CGI_PRINTF(s,"X-Container-Bytes-Used: %s\n", buf);
}
+static void dump_account_metadata(struct req_state *s, uint32_t buckets_count,
+ uint64_t buckets_object_count, uint64_t buckets_size)
+{
+ char buf[32];
+ snprintf(buf, sizeof(buf), "%lld", (long long)buckets_count);
+ CGI_PRINTF(s,"X-Account-Container-Count: %s\n", buf);
+ snprintf(buf, sizeof(buf), "%lld", (long long)buckets_object_count);
+ CGI_PRINTF(s,"X-Account-Object-Count: %s\n", buf);
+ snprintf(buf, sizeof(buf), "%lld", (long long)buckets_size);
+ CGI_PRINTF(s,"X-Account-Bytes-Used: %s\n", buf);
+}
+
+void RGWStatAccount_REST_SWIFT::send_response()
+{
+ if (ret >= 0) {
+ ret = 204;
+ dump_account_metadata(s, buckets_count, buckets_objcount, buckets_size);
+ }
+
+ set_req_state_err(s, ret);
+ dump_errno(s);
+
+ end_header(s);
+ dump_start(s);
+}
+
void RGWStatBucket_REST_SWIFT::send_response()
{
- if (ret >= 0)
+ if (ret >= 0) {
+ ret = 204;
dump_container_metadata(s, bucket);
+ }
- if (ret < 0)
- set_req_state_err(s, ret);
+ set_req_state_err(s, ret);
dump_errno(s);
end_header(s);
dump_start(s);
- flush_formatter_to_req_state(s, s->formatter);
}
void RGWCreateBucket_REST_SWIFT::send_response()
{
- if (ret)
- set_req_state_err(s, ret);
+ if (!ret)
+ ret = 201; // "created"
+ set_req_state_err(s, ret);
dump_errno(s);
end_header(s);
flush_formatter_to_req_state(s, s->formatter);
@@ -270,7 +297,10 @@ RGWOp *RGWHandler_REST_SWIFT::get_retrieve_op(bool get_data)
return get_retrieve_obj_op(get_data);
}
- return new RGWListBuckets_REST_SWIFT;
+ if (get_data)
+ return new RGWListBuckets_REST_SWIFT;
+ else
+ return new RGWStatAccount_REST_SWIFT;
}
RGWOp *RGWHandler_REST_SWIFT::get_create_op()
diff --git a/src/rgw/rgw_rest_swift.h b/src/rgw/rgw_rest_swift.h
index c9bb6ff51aa..9a20b636c76 100644
--- a/src/rgw/rgw_rest_swift.h
+++ b/src/rgw/rgw_rest_swift.h
@@ -32,6 +32,15 @@ public:
void send_response();
};
+class RGWStatAccount_REST_SWIFT : public RGWStatAccount_REST {
+public:
+ RGWStatAccount_REST_SWIFT() {
+ }
+ ~RGWStatAccount_REST_SWIFT() {}
+
+ void send_response();
+};
+
class RGWStatBucket_REST_SWIFT : public RGWStatBucket_REST {
public:
RGWStatBucket_REST_SWIFT() {}
diff --git a/src/rgw/rgw_swift_auth.cc b/src/rgw/rgw_swift_auth.cc
index 41d00111bc7..8305a0299c3 100644
--- a/src/rgw/rgw_swift_auth.cc
+++ b/src/rgw/rgw_swift_auth.cc
@@ -165,7 +165,7 @@ void RGW_SWIFT_Auth_Get::execute()
goto done;
}
- CGI_PRINTF(s, "X-Storage-Url: %s/%s/v1/AUTH_rgw\n", g_conf->rgw_swift_url.c_str(),
+ CGI_PRINTF(s, "X-Storage-Url: %s/%s/v1\n", g_conf->rgw_swift_url.c_str(),
g_conf->rgw_swift_url_prefix.c_str());
if ((ret = encode_token(swift_key->id, swift_key->key, bl)) < 0)