Skip to content

Commit b373329

Browse files
committed
rgw/s3: add ObjectOwnership and OwnershipControls
Signed-off-by: Casey Bodley <[email protected]>
1 parent ce6c4a9 commit b373329

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

src/rgw/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ set(librgw_common_srcs
7272
rgw_multi_del.cc
7373
rgw_multipart_meta_filter.cc
7474
rgw_obj_manifest.cc
75+
rgw_object_ownership.cc
7576
rgw_period.cc
7677
rgw_realm.cc
7778
rgw_sync.cc

src/rgw/rgw_object_ownership.cc

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2+
// vim: ts=8 sw=2 smarttab ft=cpp
3+
4+
/*
5+
* Ceph - scalable distributed file system
6+
*
7+
* Copyright contributors to the Ceph project
8+
*
9+
* This is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License version 2.1, as published by the Free Software
12+
* Foundation. See file COPYING.
13+
*
14+
*/
15+
16+
#include "rgw_object_ownership.h"
17+
#include "rgw_xml.h"
18+
19+
namespace rgw::s3 {
20+
21+
std::string to_string(ObjectOwnership ownership)
22+
{
23+
switch (ownership) {
24+
case ObjectOwnership::BucketOwnerEnforced:
25+
return "BucketOwnerEnforced";
26+
case ObjectOwnership::BucketOwnerPreferred:
27+
return "BucketOwnerPreferred";
28+
case ObjectOwnership::ObjectWriter:
29+
return "ObjectWriter";
30+
default:
31+
return "invalid";
32+
}
33+
}
34+
35+
bool parse(std::string_view input, ObjectOwnership& ownership,
36+
std::string& error_message)
37+
{
38+
if (input == "BucketOwnerEnforced") {
39+
ownership = ObjectOwnership::BucketOwnerEnforced;
40+
return true;
41+
}
42+
if (input == "BucketOwnerPreferred") {
43+
ownership = ObjectOwnership::BucketOwnerPreferred;
44+
return true;
45+
}
46+
if (input == "ObjectWriter") {
47+
ownership = ObjectOwnership::ObjectWriter;
48+
return true;
49+
}
50+
error_message = "ObjectOwnership must be one of "
51+
"BucketOwnerEnforced | BucketOwnerPreferred | ObjectWriter";
52+
return false;
53+
}
54+
55+
bool OwnershipControls::decode_xml(XMLObj* xml, std::string& error_message)
56+
{
57+
XMLObj* r = xml->find_first("Rule");
58+
if (!r) {
59+
error_message = "Missing required element Rule";
60+
return false;
61+
}
62+
XMLObj* o = r->find_first("ObjectOwnership");
63+
if (!o) {
64+
error_message = "Missing required element ObjectOwnership";
65+
return false;
66+
}
67+
return parse(o->get_data(), object_ownership, error_message);
68+
}
69+
70+
void OwnershipControls::dump_xml(Formatter *f) const
71+
{
72+
auto rule = Formatter::ObjectSection{*f, "Rule"};
73+
encode_xml("ObjectOwnership", to_string(object_ownership), f);
74+
}
75+
76+
void encode(const OwnershipControls& c, bufferlist& bl, uint64_t f)
77+
{
78+
ENCODE_START(1, 1, bl);
79+
encode(c.object_ownership, bl);
80+
ENCODE_FINISH(bl);
81+
}
82+
83+
void decode(OwnershipControls& c, bufferlist::const_iterator& bl)
84+
{
85+
DECODE_START(1, bl);
86+
decode(c.object_ownership, bl);
87+
DECODE_FINISH(bl);
88+
}
89+
90+
} // namespace rgw::s3

src/rgw/rgw_object_ownership.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2+
// vim: ts=8 sw=2 smarttab ft=cpp
3+
4+
/*
5+
* Ceph - scalable distributed file system
6+
*
7+
* Copyright contributors to the Ceph project
8+
*
9+
* This is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License version 2.1, as published by the Free Software
12+
* Foundation. See file COPYING.
13+
*
14+
*/
15+
16+
#pragma once
17+
18+
#include <cstdint>
19+
#include <optional>
20+
#include <string>
21+
#include "include/encoding.h"
22+
23+
class XMLObj;
24+
namespace ceph { class Formatter; }
25+
26+
namespace rgw::s3 {
27+
28+
/// S3 Object Ownership configuration
29+
enum class ObjectOwnership : uint8_t {
30+
BucketOwnerEnforced,
31+
BucketOwnerPreferred,
32+
ObjectWriter,
33+
};
34+
35+
/// Format ObjectOwnership configuration as a string
36+
std::string to_string(ObjectOwnership ownership);
37+
38+
/// Parse ObjectOwnership configuration from a string
39+
bool parse(std::string_view input, ObjectOwnership& ownership,
40+
std::string& error_message);
41+
42+
43+
/// Ownership controls for a bucket, encoded in RGW_ATTR_OWNERSHIP_CONTROLS.
44+
struct OwnershipControls {
45+
ObjectOwnership object_ownership = ObjectOwnership::ObjectWriter;
46+
47+
bool decode_xml(XMLObj* xml, std::string& error_message);
48+
void dump_xml(ceph::Formatter* f) const;
49+
};
50+
51+
void encode(const OwnershipControls&, bufferlist&, uint64_t f=0);
52+
void decode(OwnershipControls&, bufferlist::const_iterator&);
53+
54+
} // namespace rgw::s3

0 commit comments

Comments
 (0)