1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2019 Red Hat, Inc.
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.
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)
24 #include <fmt/format.h>
26 #include "include/types.h"
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"
36 #include "common/Formatter.h"
39 class cls_user_bucket
;
46 /** Store error returns for output at a different point in the program */
50 bool is_clear() const;
52 friend std::ostream
& operator<<(std::ostream
& oss
, const rgw_err
&err
);
64 rgw_zone_id(const std::string
& _id
) : id(_id
) {}
65 rgw_zone_id(std::string
&& _id
) : id(std::move(_id
)) {}
67 void encode(ceph::buffer::list
& bl
) const {
68 /* backward compatiblity, not using ENCODE_{START,END} macros */
72 void decode(ceph::buffer::list::const_iterator
& bl
) {
73 /* backward compatiblity, not using DECODE_{START,END} macros */
81 bool operator==(const std::string
& _id
) const {
84 bool operator==(const rgw_zone_id
& zid
) const {
85 return (id
== zid
.id
);
87 bool operator!=(const rgw_zone_id
& zid
) const {
88 return (id
!= zid
.id
);
90 bool operator<(const rgw_zone_id
& zid
) const {
93 bool operator>(const rgw_zone_id
& zid
) const {
101 WRITE_CLASS_ENCODER(rgw_zone_id
)
103 inline std::ostream
& operator<<(std::ostream
& os
, const rgw_zone_id
& zid
) {
109 struct rgw_placement_rule
;
113 extern void encode_json(const char *name
, const obj_version
& v
, Formatter
*f
);
114 extern void encode_json(const char *name
, const RGWUserCaps
& val
, Formatter
*f
);
115 extern void encode_json(const char *name
, const rgw_pool
& pool
, Formatter
*f
);
116 extern void encode_json(const char *name
, const rgw_placement_rule
& r
, Formatter
*f
);
117 extern void encode_json_impl(const char *name
, const rgw_zone_id
& zid
, ceph::Formatter
*f
);
118 extern void encode_json_plain(const char *name
, const RGWAccessKey
& val
, Formatter
*f
);
120 extern void decode_json_obj(obj_version
& v
, JSONObj
*obj
);
121 extern void decode_json_obj(rgw_zone_id
& zid
, JSONObj
*obj
);
122 extern void decode_json_obj(rgw_pool
& pool
, JSONObj
*obj
);
123 extern void decode_json_obj(rgw_placement_rule
& v
, JSONObj
*obj
);
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.
134 enum types
{ User
, Role
, Tenant
, Wildcard
, OidcProvider
, AssumedRole
};
139 explicit Principal(types t
)
142 Principal(types t
, std::string
&& n
, std::string i
)
143 : t(t
), u(std::move(n
), std::move(i
)) {}
145 Principal(std::string
&& idp_url
)
146 : t(OidcProvider
), idp_url(std::move(idp_url
)) {}
150 static Principal
wildcard() {
151 return Principal(Wildcard
);
154 static Principal
user(std::string
&& t
, std::string
&& u
) {
155 return Principal(User
, std::move(t
), std::move(u
));
158 static Principal
role(std::string
&& t
, std::string
&& u
) {
159 return Principal(Role
, std::move(t
), std::move(u
));
162 static Principal
tenant(std::string
&& t
) {
163 return Principal(Tenant
, std::move(t
), {});
166 static Principal
oidc_provider(std::string
&& idp_url
) {
167 return Principal(std::move(idp_url
));
170 static Principal
assumed_role(std::string
&& t
, std::string
&& u
) {
171 return Principal(AssumedRole
, std::move(t
), std::move(u
));
174 bool is_wildcard() const {
175 return t
== Wildcard
;
178 bool is_user() const {
182 bool is_role() const {
186 bool is_tenant() const {
190 bool is_oidc_provider() const {
191 return t
== OidcProvider
;
194 bool is_assumed_role() const {
195 return t
== AssumedRole
;
198 const std::string
& get_tenant() const {
202 const std::string
& get_id() const {
206 const std::string
& get_idp_url() const {
210 const std::string
& get_role_session() const {
214 const std::string
& get_role() const {
218 bool operator ==(const Principal
& o
) const {
219 return (t
== o
.t
) && (u
== o
.u
);
222 bool operator <(const Principal
& o
) const {
223 return (t
< o
.t
) || ((t
== o
.t
) && (u
< o
.u
));
227 std::ostream
& operator <<(std::ostream
& m
, const Principal
& p
);
233 void decode_json_obj(rgw_user
& val
, JSONObj
*obj
);
234 void encode_json(const char *name
, const rgw_user
& val
, ceph::Formatter
*f
);
235 void encode_xml(const char *name
, const rgw_user
& val
, ceph::Formatter
*f
);
237 inline std::ostream
& operator<<(std::ostream
& out
, const rgw_user
&u
) {
243 struct RGWUploadPartInfo
{
246 uint64_t accounted_size
{0};
248 ceph::real_time modified
;
249 RGWObjManifest manifest
;
250 RGWCompressionInfo cs_info
;
252 // Previous part obj prefixes. Recorded here for later cleanup.
253 std::set
<std::string
> past_prefixes
;
255 RGWUploadPartInfo() : num(0), size(0) {}
257 void encode(bufferlist
& bl
) const {
258 ENCODE_START(5, 2, bl
);
262 encode(modified
, bl
);
263 encode(manifest
, bl
);
265 encode(accounted_size
, bl
);
266 encode(past_prefixes
, bl
);
269 void decode(bufferlist::const_iterator
& bl
) {
270 DECODE_START_LEGACY_COMPAT_LEN(5, 2, 2, bl
);
274 decode(modified
, bl
);
276 decode(manifest
, bl
);
279 decode(accounted_size
, bl
);
281 accounted_size
= size
;
284 decode(past_prefixes
, bl
);
288 void dump(Formatter
*f
) const;
289 static void generate_test_instances(std::list
<RGWUploadPartInfo
*>& o
);
291 WRITE_CLASS_ENCODER(RGWUploadPartInfo
)