]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
11fdf7f2 | 3 | |
31f18b77 FG |
4 | #include <iostream> |
5 | #include <sstream> | |
6 | #include <string> | |
7 | ||
9f95a23c TL |
8 | #include "cls/user/cls_user_types.h" |
9 | ||
7c673cae | 10 | #include "rgw_basic_types.h" |
eafe8130 | 11 | #include "rgw_xml.h" |
7c673cae FG |
12 | #include "common/ceph_json.h" |
13 | ||
31f18b77 FG |
14 | using std::string; |
15 | using std::stringstream; | |
16 | ||
7c673cae FG |
17 | void decode_json_obj(rgw_user& val, JSONObj *obj) |
18 | { | |
eafe8130 | 19 | val.from_str(obj->get_data()); |
7c673cae FG |
20 | } |
21 | ||
22 | void encode_json(const char *name, const rgw_user& val, Formatter *f) | |
23 | { | |
eafe8130 TL |
24 | f->dump_string(name, val.to_str()); |
25 | } | |
26 | ||
27 | void encode_xml(const char *name, const rgw_user& val, Formatter *f) | |
28 | { | |
29 | encode_xml(name, val.to_str(), f); | |
7c673cae | 30 | } |
31f18b77 | 31 | |
9f95a23c TL |
32 | rgw_bucket::rgw_bucket(const rgw_user& u, const cls_user_bucket& b) : |
33 | tenant(u.tenant), | |
34 | name(b.name), | |
35 | marker(b.marker), | |
36 | bucket_id(b.bucket_id), | |
37 | explicit_placement(b.explicit_placement.data_pool, | |
38 | b.explicit_placement.data_extra_pool, | |
39 | b.explicit_placement.index_pool) | |
40 | { | |
41 | } | |
42 | ||
43 | void rgw_bucket::convert(cls_user_bucket *b) const | |
44 | { | |
45 | b->name = name; | |
46 | b->marker = marker; | |
47 | b->bucket_id = bucket_id; | |
48 | b->explicit_placement.data_pool = explicit_placement.data_pool.to_str(); | |
49 | b->explicit_placement.data_extra_pool = explicit_placement.data_extra_pool.to_str(); | |
50 | b->explicit_placement.index_pool = explicit_placement.index_pool.to_str(); | |
51 | } | |
52 | ||
53 | std::string rgw_bucket::get_key(char tenant_delim, char id_delim, size_t reserve) const | |
54 | { | |
55 | const size_t max_len = tenant.size() + sizeof(tenant_delim) + | |
56 | name.size() + sizeof(id_delim) + bucket_id.size() + reserve; | |
57 | ||
58 | std::string key; | |
59 | key.reserve(max_len); | |
60 | if (!tenant.empty() && tenant_delim) { | |
61 | key.append(tenant); | |
62 | key.append(1, tenant_delim); | |
63 | } | |
64 | key.append(name); | |
65 | if (!bucket_id.empty() && id_delim) { | |
66 | key.append(1, id_delim); | |
67 | key.append(bucket_id); | |
68 | } | |
69 | return key; | |
70 | } | |
71 | ||
72 | std::string rgw_bucket_shard::get_key(char tenant_delim, char id_delim, | |
73 | char shard_delim) const | |
74 | { | |
75 | static constexpr size_t shard_len{12}; // ":4294967295\0" | |
76 | auto key = bucket.get_key(tenant_delim, id_delim, shard_len); | |
77 | if (shard_id >= 0 && shard_delim) { | |
78 | key.append(1, shard_delim); | |
79 | key.append(std::to_string(shard_id)); | |
80 | } | |
81 | return key; | |
82 | } | |
83 | ||
84 | void encode_json_impl(const char *name, const rgw_zone_id& zid, Formatter *f) | |
85 | { | |
86 | encode_json(name, zid.id, f); | |
87 | } | |
88 | ||
89 | void decode_json_obj(rgw_zone_id& zid, JSONObj *obj) | |
90 | { | |
91 | decode_json_obj(zid.id, obj); | |
92 | } | |
93 | ||
31f18b77 FG |
94 | namespace rgw { |
95 | namespace auth { | |
96 | ostream& operator <<(ostream& m, const Principal& p) { | |
97 | if (p.is_wildcard()) { | |
98 | return m << "*"; | |
99 | } | |
100 | ||
101 | m << "arn:aws:iam:" << p.get_tenant() << ":"; | |
102 | if (p.is_tenant()) { | |
103 | return m << "root"; | |
104 | } | |
105 | return m << (p.is_user() ? "user/" : "role/") << p.get_id(); | |
106 | } | |
31f18b77 FG |
107 | } |
108 | } |