]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_basic_types.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #ifndef CEPH_RGW_BASIC_TYPES_H
4 #define CEPH_RGW_BASIC_TYPES_H
8 #include "include/types.h"
15 // cppcheck-suppress noExplicitConstructor
16 rgw_user(const std::string
& s
) {
19 rgw_user(const std::string
& tenant
, const std::string
& id
)
23 rgw_user(std::string
&& tenant
, std::string
&& id
)
24 : tenant(std::move(tenant
)),
28 void encode(bufferlist
& bl
) const {
29 ENCODE_START(1, 1, bl
);
34 void decode(bufferlist::iterator
& bl
) {
41 void to_str(std::string
& str
) const {
42 if (!tenant
.empty()) {
43 str
= tenant
+ '$' + id
;
58 string
to_str() const {
64 void from_str(const std::string
& str
) {
65 size_t pos
= str
.find('$');
66 if (pos
!= std::string::npos
) {
67 tenant
= str
.substr(0, pos
);
68 id
= str
.substr(pos
+ 1);
75 rgw_user
& operator=(const string
& str
) {
80 int compare(const rgw_user
& u
) const {
81 int r
= tenant
.compare(u
.tenant
);
85 return id
.compare(u
.id
);
87 int compare(const string
& str
) const {
92 bool operator!=(const rgw_user
& rhs
) const {
93 return (compare(rhs
) != 0);
95 bool operator==(const rgw_user
& rhs
) const {
96 return (compare(rhs
) == 0);
98 bool operator<(const rgw_user
& rhs
) const {
99 if (tenant
< rhs
.tenant
) {
101 } else if (tenant
> rhs
.tenant
) {
104 return (id
< rhs
.id
);
107 WRITE_CLASS_ENCODER(rgw_user
)
109 // Represents an identity. This is more wide-ranging than a
110 // 'User'. Its purposes is to be matched against by an
111 // IdentityApplier. The internal representation will doubtless change as
112 // more types are added. We may want to expose the type enum and make
113 // the member public so people can switch/case on it.
118 enum types
{ User
, Role
, Tenant
, Wildcard
};
125 Principal(types t
, std::string
&& n
, std::string i
)
126 : t(t
), u(std::move(n
), std::move(i
)) {}
130 static Principal
wildcard() {
131 return Principal(Wildcard
);
134 static Principal
user(std::string
&& t
, std::string
&& u
) {
135 return Principal(User
, std::move(t
), std::move(u
));
138 static Principal
role(std::string
&& t
, std::string
&& u
) {
139 return Principal(Role
, std::move(t
), std::move(u
));
142 static Principal
tenant(std::string
&& t
) {
143 return Principal(Tenant
, std::move(t
), {});
146 bool is_wildcard() const {
147 return t
== Wildcard
;
150 bool is_user() const {
154 bool is_role() const {
158 bool is_tenant() const {
162 const std::string
& get_tenant() const {
163 ceph_assert(t
!= Wildcard
);
167 const std::string
& get_id() const {
168 ceph_assert(t
!= Wildcard
&& t
!= Tenant
);
172 bool operator ==(const Principal
& o
) const {
173 return (t
== o
.t
) && (u
== o
.u
);
176 bool operator <(const Principal
& o
) const {
177 return (t
< o
.t
) || ((t
== o
.t
) && (u
< o
.u
));
181 std::ostream
& operator <<(std::ostream
& m
, const Principal
& p
);
182 std::string
to_string(const Principal
& p
);
188 void decode_json_obj(rgw_user
& val
, JSONObj
*obj
);
189 void encode_json(const char *name
, const rgw_user
& val
, Formatter
*f
);
191 inline ostream
& operator<<(ostream
& out
, const rgw_user
&u
) {