1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
4 #ifndef CEPH_RGW_ROLE_H
5 #define CEPH_RGW_ROLE_H
9 #include "common/ceph_context.h"
15 using string
= std::string
;
16 static const string role_name_oid_prefix
;
17 static const string role_oid_prefix
;
18 static const string role_path_oid_prefix
;
19 static const string role_arn_prefix
;
20 static constexpr int MAX_ROLE_NAME_LEN
= 64;
21 static constexpr int MAX_PATH_NAME_LEN
= 512;
22 static constexpr uint64_t SESSION_DURATION_MIN
= 3600; // in seconds
23 static constexpr uint64_t SESSION_DURATION_MAX
= 43200; // in seconds
33 map
<string
, string
> perm_policy_map
;
35 uint64_t max_session_duration
;
37 int store_info(bool exclusive
);
38 int store_name(bool exclusive
);
39 int store_path(bool exclusive
);
40 int read_id(const string
& role_name
, const string
& tenant
, string
& role_id
);
43 void set_id(const string
& id
) { this->id
= id
; }
44 bool validate_input();
45 void extract_name_tenant(const std::string
& str
);
48 RGWRole(CephContext
*cct
,
54 string max_session_duration_str
="")
57 name(std::move(name
)),
58 path(std::move(path
)),
59 trust_policy(std::move(trust_policy
)),
60 tenant(std::move(tenant
)) {
61 if (this->path
.empty())
63 extract_name_tenant(this->name
);
64 if (max_session_duration_str
.empty()) {
65 max_session_duration
= SESSION_DURATION_MIN
;
67 max_session_duration
= std::stoull(max_session_duration_str
);
71 RGWRole(CephContext
*cct
,
77 name(std::move(name
)),
78 tenant(std::move(tenant
)) {
79 extract_name_tenant(this->name
);
82 RGWRole(CephContext
*cct
,
89 RGWRole(CephContext
*cct
,
98 void encode(bufferlist
& bl
) const {
99 ENCODE_START(3, 1, bl
);
104 encode(creation_date
, bl
);
105 encode(trust_policy
, bl
);
106 encode(perm_policy_map
, bl
);
108 encode(max_session_duration
, bl
);
112 void decode(bufferlist::const_iterator
& bl
) {
118 decode(creation_date
, bl
);
119 decode(trust_policy
, bl
);
120 decode(perm_policy_map
, bl
);
125 decode(max_session_duration
, bl
);
130 const string
& get_id() const { return id
; }
131 const string
& get_name() const { return name
; }
132 const string
& get_path() const { return path
; }
133 const string
& get_create_date() const { return creation_date
; }
134 const string
& get_assume_role_policy() const { return trust_policy
;}
135 const uint64_t& get_max_session_duration() const { return max_session_duration
; }
137 int create(bool exclusive
);
142 void update_trust_policy(string
& trust_policy
);
143 void set_perm_policy(const string
& policy_name
, const string
& perm_policy
);
144 vector
<string
> get_role_policy_names();
145 int get_role_policy(const string
& policy_name
, string
& perm_policy
);
146 int delete_policy(const string
& policy_name
);
147 void dump(Formatter
*f
) const;
148 void decode_json(JSONObj
*obj
);
150 static const string
& get_names_oid_prefix();
151 static const string
& get_info_oid_prefix();
152 static const string
& get_path_oid_prefix();
153 static int get_roles_by_path_prefix(RGWRados
*store
,
155 const string
& path_prefix
,
156 const string
& tenant
,
157 vector
<RGWRole
>& roles
);
159 WRITE_CLASS_ENCODER(RGWRole
)
160 #endif /* CEPH_RGW_ROLE_H */