mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-07 03:22:46 -05:00
### Does this PR have any customer impact? Yes ### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) Feature ### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes) No ### Are you introducing any new config? If yes, do you have tests with and without them being set? No ### ChangeLog (Refer [Template](../oss/CHANGELOG.md)) 1.108 ### Description We are adding support for the RolesInfo command in Engine ---- #### AI description (iteration 1) #### PR Classification New feature enhancement: introducing the `rolesInfo` command to retrieve detailed role information including inherited roles and privileges. #### PR Summary This pull request adds comprehensive support for the `rolesInfo` command in the engine, implementing new parsing, processing, and BSON output functions while updating tests and auxiliary query strings. - `oss/pg_documentdb/src/commands/roles.c`: Added functions (e.g., `ParseRolesInfoSpec`, `WriteRoleDocumentWithInheritedRoles`, `WriteInheritedRolesToArray`) to parse rolesInfo parameters and construct role documents with inherited roles and optional privileges. - `oss/pg_documentdb/src/test/regress/expected/role_crud_commands.out` and `pgmongo/src/test/regress/expected/role_crud_commands.out`: Expanded test suites with numerous rolesInfo scenarios, error conditions, and inheritance verification tests. - `oss/pg_documentdb/include/roles.h`: Introduced new types and function prototypes to support rolesInfo and role CRUD operations. - `pgmongo/src/pgmongo.c`: Updated query string definitions to handle role name substitutions for OSS compatibility. - `oss/pg_documentdb/src/commands/users.c`: Modified role checking and privilege extraction utilities to align with the new rolesInfo functionality. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Related work items: #4552244 Signed-off-by: Shuai Tian <shuaitian@microsoft.com>
57 lines
1.6 KiB
C
57 lines
1.6 KiB
C
#ifndef ROLE_UTILS_H
|
|
#define ROLE_UTILS_H
|
|
|
|
#include "postgres.h"
|
|
#include "fmgr.h"
|
|
|
|
/* Macro to check if a role is a system role */
|
|
#define IS_SYSTEM_ROLE(roleName) \
|
|
(strcmp((roleName), ApiBgWorkerRole) == 0)
|
|
|
|
/* Macro to check if a role is a customer facing built-in role */
|
|
#define IS_BUILTIN_ROLE(roleName) \
|
|
(strcmp((roleName), ApiAdminRoleV2) == 0 || \
|
|
strcmp((roleName), ApiReadOnlyRole) == 0 || \
|
|
strcmp((roleName), ApiReadWriteRole) == 0 || \
|
|
strcmp((roleName), ApiRootRole) == 0 || \
|
|
strcmp((roleName), ApiUserAdminRole) == 0)
|
|
|
|
/*
|
|
* Privilege stores a privilege and its actions.
|
|
*/
|
|
typedef struct
|
|
{
|
|
const char *db;
|
|
const char *collection;
|
|
bool isCluster;
|
|
size_t numActions;
|
|
const StringView *actions;
|
|
} Privilege;
|
|
|
|
/*
|
|
* ConsolidatedPrivilege contains the db, collection, isCluster, and actions of a privilege.
|
|
*/
|
|
typedef struct
|
|
{
|
|
const char *db;
|
|
const char *collection;
|
|
bool isCluster;
|
|
HTAB *actions;
|
|
} ConsolidatedPrivilege;
|
|
|
|
/* Function to write a single role's privileges to a BSON array writer */
|
|
void WriteSingleRolePrivileges(const char *roleName,
|
|
pgbson_array_writer *privilegesArrayWriter);
|
|
|
|
/* Function to write multiple roles' privileges from an HTAB to a BSON array writer*/
|
|
void WriteMultipleRolePrivileges(HTAB *rolesTable,
|
|
pgbson_array_writer *privilegesArrayWriter);
|
|
|
|
/* Function to check if a given role name contains any reserved pg role name prefixes. */
|
|
bool ContainsReservedPgRoleNamePrefix(const char *name);
|
|
|
|
/* Function to build a List of parent role names from an array of Datums */
|
|
List * ConvertUserOrRoleNamesDatumToList(Datum *parentRolesDatums, int parentRolesCount);
|
|
|
|
#endif
|