3D Repo Bouncer  1.4
repo_bson_role.h
1 
18 #pragma once
19 #include "repo_bson.h"
20 
21 namespace repo {
22  namespace core {
23  namespace model {
24  enum class DBActions {
25  INSERT, UPDATE, REMOVE, FIND, CREATE_USER, CREATE_ROLE,
26  DROP_ROLE, GRANT_ROLE, REVOKE_ROLE, VIEW_ROLE, UNKNOWN
27  };
28  enum class AccessRight { READ, WRITE, READ_WRITE };
29 
31  {
32  std::string database;
33  std::string collection;
34  std::vector<DBActions> actions;
35  };
36 
38  {
39  std::string database;
40  //Project name (not collection! put "model" instead of "model.{scene,history,stash,...}" in here.)
41  std::string project;
42  AccessRight permission;
43  };
44 
45  class REPO_API_EXPORT RepoRole : public RepoBSON
46  {
47 #define REPO_ROLE_LABEL_ROLE "role"
48 #define REPO_ROLE_LABEL_DATABASE "db"
49 #define REPO_ROLE_LABEL_COLLECTION "collection"
50 #define REPO_ROLE_LABEL_RESOURCE "resource"
51 #define REPO_ROLE_LABEL_ACTIONS "actions"
52 #define REPO_ROLE_LABEL_PRIVILEGES "privileges"
53 #define REPO_ROLE_LABEL_INHERITED_ROLES "roles"
54 
55  public:
56 
57  RepoRole() {}
58 
59  RepoRole(RepoBSON bson) : RepoBSON(bson){}
60 
61  ~RepoRole() {}
62 
63  public:
64 
70  static std::string dbActionToString(const DBActions &action);
71 
77  static std::vector<std::string> dbActionsToStrings(
78  const std::vector<DBActions> &actions);
79 
85  static DBActions stringToDBAction(const std::string &action);
86 
93  static std::vector<DBActions> stringsToDBActions(
94  const std::vector<std::string> &strings);
95 
101  static std::vector<RepoPrivilege> translatePermissions(
102  const std::vector<RepoPermission> &permissions);
103 
109  static std::vector<RepoPermission> translatePrivileges(
110  const std::vector<RepoPrivilege> &permissions);
111 
119  static void updateActions(
120  const std::string &collectionType,
121  const AccessRight &permission,
122  std::vector<DBActions> &vec
123  );
124 
140  RepoRole cloneAndUpdatePermissions(
141  const std::vector<RepoPermission> &permissions
142  ) const;
143 
149  RepoRole cloneAndUpdatePrivileges(
150  const std::vector<RepoPrivilege> &privileges
151  ) const;
152 
161  std::string getDatabase() const
162  {
163  return getStringField(REPO_ROLE_LABEL_DATABASE);
164  }
165 
170  std::vector<std::pair<std::string, std::string>> getInheritedRoles() const;
171 
176  std::string getName() const
177  {
178  return getStringField(REPO_ROLE_LABEL_ROLE);
179  }
180 
185  std::vector<RepoPrivilege> getPrivileges() const;
186 
191  std::unordered_map<std::string, RepoPrivilege> getPrivilegesMapped() const
192  {
193  return getPrivilegesMapped(getPrivileges());
194  }
195 
196  static std::unordered_map<std::string, RepoPrivilege>
197  getPrivilegesMapped(const std::vector<RepoPrivilege> &ps);
198 
203  std::vector<RepoPermission> getProjectAccessRights() const
204  {
205  return translatePrivileges(getPrivileges());
206  }
207 
208  private:
209 
216  std::vector<DBActions> getActions(RepoBSON actionArr) const;
217  };
218  }// end namespace model
219  } // end namespace core
220 } // end namespace repo
Definition: repo_bson_role.h:37
Definition: repo_connection_pool_mongo.h:32
std::unordered_map< std::string, RepoPrivilege > getPrivilegesMapped() const
Definition: repo_bson_role.h:191
std::string getName() const
Definition: repo_bson_role.h:176
std::vector< RepoPermission > getProjectAccessRights() const
Definition: repo_bson_role.h:203
Definition: repo_bson.h:53
Definition: repo_bson_role.h:30
std::string getDatabase() const
Definition: repo_bson_role.h:161
Definition: repo_bson_role.h:45