Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / rgw / rgw_role.h
1 #ifndef CEPH_RGW_ROLE_H
2 #define CEPH_RGW_ROLE_H
3
4 class RGWRole
5 {
6   static const string role_name_oid_prefix;
7   static const string role_oid_prefix;
8   static const string role_path_oid_prefix;
9   static const string role_arn_prefix;
10   static constexpr int MAX_ROLE_NAME_LEN = 64;
11   static constexpr int MAX_PATH_NAME_LEN = 512;
12
13   CephContext *cct;
14   RGWRados *store;
15   string id;
16   string name;
17   string path;
18   string arn;
19   string creation_date;
20   string trust_policy;
21   map<string, string> perm_policy_map;
22   string tenant;
23
24   int store_info(bool exclusive);
25   int store_name(bool exclusive);
26   int store_path(bool exclusive);
27   int read_id(const string& role_name, const string& tenant, string& role_id);
28   int read_name();
29   int read_info();
30   void set_id(const string& id) { this->id = id; }
31   bool validate_input();
32   void extract_name_tenant(const std::string& str);
33
34 public:
35   RGWRole(CephContext *cct,
36           RGWRados *store,
37           string name,
38           string path,
39           string trust_policy,
40           string tenant)
41   : cct(cct),
42     store(store),
43     name(std::move(name)),
44     path(std::move(path)),
45     trust_policy(std::move(trust_policy)),
46     tenant(std::move(tenant)) {
47     if (this->path.empty())
48       this->path = "/";
49     extract_name_tenant(this->name);
50   }
51
52   RGWRole(CephContext *cct,
53           RGWRados *store,
54           string name,
55           string tenant)
56   : cct(cct),
57     store(store),
58     name(std::move(name)),
59     tenant(std::move(tenant)) {
60     extract_name_tenant(this->name);
61   }
62
63   RGWRole(CephContext *cct,
64           RGWRados *store,
65           string id)
66   : cct(cct),
67     store(store),
68     id(std::move(id)) {}
69
70   RGWRole(CephContext *cct,
71           RGWRados *store)
72   : cct(cct),
73     store(store) {}
74
75   RGWRole() {}
76
77   ~RGWRole() = default;
78
79   void encode(bufferlist& bl) const {
80     ENCODE_START(2, 1, bl);
81     ::encode(id, bl);
82     ::encode(name, bl);
83     ::encode(path, bl);
84     ::encode(arn, bl);
85     ::encode(creation_date, bl);
86     ::encode(trust_policy, bl);
87     ::encode(perm_policy_map, bl);
88     ::encode(tenant, bl);
89     ENCODE_FINISH(bl);
90   }
91
92   void decode(bufferlist::iterator& bl) {
93     DECODE_START(2, bl);
94     ::decode(id, bl);
95     ::decode(name, bl);
96     ::decode(path, bl);
97     ::decode(arn, bl);
98     ::decode(creation_date, bl);
99     ::decode(trust_policy, bl);
100     ::decode(perm_policy_map, bl);
101     if (struct_v >= 2) {
102       ::decode(tenant, bl);
103     }
104     DECODE_FINISH(bl);
105   }
106
107   const string& get_id() const { return id; }
108   const string& get_name() const { return name; }
109   const string& get_path() const { return path; }
110   const string& get_create_date() const { return creation_date; }
111   const string& get_assume_role_policy() const { return trust_policy;}
112
113   int create(bool exclusive);
114   int delete_obj();
115   int get();
116   int get_by_id();
117   int update();
118   void update_trust_policy(string& trust_policy);
119   void set_perm_policy(const string& policy_name, const string& perm_policy);
120   vector<string> get_role_policy_names();
121   int get_role_policy(const string& policy_name, string& perm_policy);
122   int delete_policy(const string& policy_name);
123   void dump(Formatter *f) const;
124   void decode_json(JSONObj *obj);
125
126   static const string& get_names_oid_prefix();
127   static const string& get_info_oid_prefix();
128   static const string& get_path_oid_prefix();
129   static int get_roles_by_path_prefix(RGWRados *store,
130                                       CephContext *cct,
131                                       const string& path_prefix,
132                                       const string& tenant,
133                                       vector<RGWRole>& roles);
134 };
135 WRITE_CLASS_ENCODER(RGWRole)
136 #endif /* CEPH_RGW_ROLE_H */
137