]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_basic_types.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rgw / rgw_basic_types.h
CommitLineData
1e59de90 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
1e59de90
TL
4/*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2019 Red Hat, Inc.
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/* N.B., this header defines fundamental serialized types. Do not
17 * introduce changes or include files which can only be compiled in
18 * radosgw or OSD contexts (e.g., rgw_sal.h, rgw_common.h)
19 */
20
21#pragma once
7c673cae
FG
22
23#include <string>
1e59de90 24#include <fmt/format.h>
7c673cae
FG
25
26#include "include/types.h"
1e59de90
TL
27#include "rgw_compression_types.h"
28#include "rgw_pool_types.h"
29#include "rgw_acl_types.h"
30#include "rgw_zone_types.h"
31#include "rgw_user_types.h"
32#include "rgw_bucket_types.h"
33#include "rgw_obj_types.h"
34#include "rgw_obj_manifest.h"
35
36#include "common/Formatter.h"
7c673cae 37
9f95a23c
TL
38class JSONObj;
39class cls_user_bucket;
40
1e59de90
TL
41enum RGWIntentEvent {
42 DEL_OBJ = 0,
43 DEL_DIR = 1,
7c673cae 44};
9f95a23c 45
1e59de90
TL
46/** Store error returns for output at a different point in the program */
47struct rgw_err {
48 rgw_err();
49 void clear();
50 bool is_clear() const;
51 bool is_err() const;
52 friend std::ostream& operator<<(std::ostream& oss, const rgw_err &err);
9f95a23c 53
1e59de90
TL
54 int http_ret;
55 int ret;
56 std::string err_code;
57 std::string message;
58}; /* rgw_err */
9f95a23c
TL
59
60struct rgw_zone_id {
f67539c2 61 std::string id;
9f95a23c
TL
62
63 rgw_zone_id() {}
f67539c2
TL
64 rgw_zone_id(const std::string& _id) : id(_id) {}
65 rgw_zone_id(std::string&& _id) : id(std::move(_id)) {}
9f95a23c 66
f67539c2 67 void encode(ceph::buffer::list& bl) const {
9f95a23c
TL
68 /* backward compatiblity, not using ENCODE_{START,END} macros */
69 ceph::encode(id, bl);
70 }
71
f67539c2 72 void decode(ceph::buffer::list::const_iterator& bl) {
9f95a23c
TL
73 /* backward compatiblity, not using DECODE_{START,END} macros */
74 ceph::decode(id, bl);
75 }
76
77 void clear() {
78 id.clear();
79 }
80
f67539c2 81 bool operator==(const std::string& _id) const {
9f95a23c
TL
82 return (id == _id);
83 }
84 bool operator==(const rgw_zone_id& zid) const {
85 return (id == zid.id);
86 }
87 bool operator!=(const rgw_zone_id& zid) const {
88 return (id != zid.id);
89 }
90 bool operator<(const rgw_zone_id& zid) const {
91 return (id < zid.id);
92 }
93 bool operator>(const rgw_zone_id& zid) const {
94 return (id > zid.id);
95 }
96
97 bool empty() const {
98 return id.empty();
99 }
100};
101WRITE_CLASS_ENCODER(rgw_zone_id)
102
f67539c2 103inline std::ostream& operator<<(std::ostream& os, const rgw_zone_id& zid) {
9f95a23c
TL
104 os << zid.id;
105 return os;
106}
107
20effc67
TL
108struct obj_version;
109struct rgw_placement_rule;
110struct RGWAccessKey;
111class RGWUserCaps;
9f95a23c 112
20effc67
TL
113extern void encode_json(const char *name, const obj_version& v, Formatter *f);
114extern void encode_json(const char *name, const RGWUserCaps& val, Formatter *f);
115extern void encode_json(const char *name, const rgw_pool& pool, Formatter *f);
116extern void encode_json(const char *name, const rgw_placement_rule& r, Formatter *f);
117extern void encode_json_impl(const char *name, const rgw_zone_id& zid, ceph::Formatter *f);
118extern void encode_json_plain(const char *name, const RGWAccessKey& val, Formatter *f);
119
120extern void decode_json_obj(obj_version& v, JSONObj *obj);
121extern void decode_json_obj(rgw_zone_id& zid, JSONObj *obj);
122extern void decode_json_obj(rgw_pool& pool, JSONObj *obj);
123extern void decode_json_obj(rgw_placement_rule& v, JSONObj *obj);
9f95a23c 124
31f18b77
FG
125// Represents an identity. This is more wide-ranging than a
126// 'User'. Its purposes is to be matched against by an
127// IdentityApplier. The internal representation will doubtless change as
128// more types are added. We may want to expose the type enum and make
129// the member public so people can switch/case on it.
130
131namespace rgw {
132namespace auth {
133class Principal {
f91f0fd5 134 enum types { User, Role, Tenant, Wildcard, OidcProvider, AssumedRole };
31f18b77
FG
135 types t;
136 rgw_user u;
f67539c2 137 std::string idp_url;
31f18b77 138
11fdf7f2 139 explicit Principal(types t)
31f18b77
FG
140 : t(t) {}
141
142 Principal(types t, std::string&& n, std::string i)
143 : t(t), u(std::move(n), std::move(i)) {}
144
f67539c2 145 Principal(std::string&& idp_url)
11fdf7f2
TL
146 : t(OidcProvider), idp_url(std::move(idp_url)) {}
147
31f18b77
FG
148public:
149
150 static Principal wildcard() {
151 return Principal(Wildcard);
152 }
153
154 static Principal user(std::string&& t, std::string&& u) {
155 return Principal(User, std::move(t), std::move(u));
156 }
157
158 static Principal role(std::string&& t, std::string&& u) {
159 return Principal(Role, std::move(t), std::move(u));
160 }
161
162 static Principal tenant(std::string&& t) {
163 return Principal(Tenant, std::move(t), {});
164 }
165
f67539c2 166 static Principal oidc_provider(std::string&& idp_url) {
11fdf7f2
TL
167 return Principal(std::move(idp_url));
168 }
169
f91f0fd5
TL
170 static Principal assumed_role(std::string&& t, std::string&& u) {
171 return Principal(AssumedRole, std::move(t), std::move(u));
172 }
173
31f18b77
FG
174 bool is_wildcard() const {
175 return t == Wildcard;
176 }
177
178 bool is_user() const {
179 return t == User;
180 }
181
182 bool is_role() const {
183 return t == Role;
184 }
185
186 bool is_tenant() const {
187 return t == Tenant;
188 }
189
11fdf7f2
TL
190 bool is_oidc_provider() const {
191 return t == OidcProvider;
192 }
193
f91f0fd5
TL
194 bool is_assumed_role() const {
195 return t == AssumedRole;
196 }
197
31f18b77 198 const std::string& get_tenant() const {
31f18b77
FG
199 return u.tenant;
200 }
201
202 const std::string& get_id() const {
31f18b77
FG
203 return u.id;
204 }
205
f67539c2 206 const std::string& get_idp_url() const {
11fdf7f2
TL
207 return idp_url;
208 }
209
20effc67 210 const std::string& get_role_session() const {
f91f0fd5
TL
211 return u.id;
212 }
213
20effc67 214 const std::string& get_role() const {
f91f0fd5
TL
215 return u.id;
216 }
217
31f18b77
FG
218 bool operator ==(const Principal& o) const {
219 return (t == o.t) && (u == o.u);
220 }
221
222 bool operator <(const Principal& o) const {
223 return (t < o.t) || ((t == o.t) && (u < o.u));
224 }
225};
226
227std::ostream& operator <<(std::ostream& m, const Principal& p);
31f18b77
FG
228}
229}
7c673cae
FG
230
231class JSONObj;
232
233void decode_json_obj(rgw_user& val, JSONObj *obj);
f67539c2
TL
234void encode_json(const char *name, const rgw_user& val, ceph::Formatter *f);
235void encode_xml(const char *name, const rgw_user& val, ceph::Formatter *f);
7c673cae 236
f67539c2
TL
237inline std::ostream& operator<<(std::ostream& out, const rgw_user &u) {
238 std::string s;
7c673cae
FG
239 u.to_str(s);
240 return out << s;
241}
242
1e59de90
TL
243struct RGWUploadPartInfo {
244 uint32_t num;
245 uint64_t size;
246 uint64_t accounted_size{0};
247 std::string etag;
248 ceph::real_time modified;
249 RGWObjManifest manifest;
250 RGWCompressionInfo cs_info;
251
252 // Previous part obj prefixes. Recorded here for later cleanup.
253 std::set<std::string> past_prefixes;
254
255 RGWUploadPartInfo() : num(0), size(0) {}
256
257 void encode(bufferlist& bl) const {
258 ENCODE_START(5, 2, bl);
259 encode(num, bl);
260 encode(size, bl);
261 encode(etag, bl);
262 encode(modified, bl);
263 encode(manifest, bl);
264 encode(cs_info, bl);
265 encode(accounted_size, bl);
266 encode(past_prefixes, bl);
267 ENCODE_FINISH(bl);
268 }
269 void decode(bufferlist::const_iterator& bl) {
270 DECODE_START_LEGACY_COMPAT_LEN(5, 2, 2, bl);
271 decode(num, bl);
272 decode(size, bl);
273 decode(etag, bl);
274 decode(modified, bl);
275 if (struct_v >= 3)
276 decode(manifest, bl);
277 if (struct_v >= 4) {
278 decode(cs_info, bl);
279 decode(accounted_size, bl);
280 } else {
281 accounted_size = size;
282 }
283 if (struct_v >= 5) {
284 decode(past_prefixes, bl);
285 }
286 DECODE_FINISH(bl);
287 }
288 void dump(Formatter *f) const;
289 static void generate_test_instances(std::list<RGWUploadPartInfo*>& o);
290};
291WRITE_CLASS_ENCODER(RGWUploadPartInfo)