mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-06 19:12:50 -05:00
### Does this PR have any customer impact? ### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) ### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes) ### Are you introducing any new config? If yes, do you have tests with and without them being set? ### ChangeLog (Refer [Template](../oss/CHANGELOG.md)) ### Description ---- #### AI description (iteration 1) #### PR Classification This PR refactors and centralizes role/user CRUD utility functions. #### PR Summary The changes migrate and consolidate the logic for user and role management into a new utility module and header file, streamlining the codebase and removing redundant implementations from command files. - `src/utils/role_utils.c` adds core functions for password hashing, privilege consolidation, and user/role document writing. - `include/utils/role_utils.h` provides declarations for the newly centralized role/user utilities. - `src/commands/users.c` and `src/commands/roles.c` are cleaned up by removing duplicated role/user functionality now handled in the new module. - `pgmongo.c` and related metadata files are updated to use the new role replacement variable and adjust related constants. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Related work items: #4639026, #4639027
78 lines
1.4 KiB
C
78 lines
1.4 KiB
C
/*-------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
*
|
|
* include/users.h
|
|
*
|
|
* User CRUD functions.
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
|
|
#ifndef EXTENSION_USERS_H
|
|
#define EXTENSION_USERS_H
|
|
|
|
#include "postgres.h"
|
|
#include "utils/string_view.h"
|
|
|
|
enum DocumentDB_BuiltInRoles
|
|
{
|
|
DocumentDB_Role_Read_AnyDatabase = 0x1,
|
|
DocumentDB_Role_ReadWrite_AnyDatabase = 0x2,
|
|
DocumentDB_Role_Cluster_Admin = 0x4,
|
|
};
|
|
|
|
typedef struct
|
|
{
|
|
/* "createUser" field */
|
|
const char *createUser;
|
|
|
|
/* "pwd" field */
|
|
const char *pwd;
|
|
|
|
/* "roles" field */
|
|
bson_value_t roles;
|
|
|
|
/* "identityProvider" field*/
|
|
bson_value_t identityProviderData;
|
|
|
|
/* pgRole the passed in role maps to */
|
|
char *pgRole;
|
|
|
|
/* principalType */
|
|
char *principalType;
|
|
|
|
/* has_identity_provider */
|
|
bool has_identity_provider;
|
|
} CreateUserSpec;
|
|
|
|
typedef struct
|
|
{
|
|
/* "updateUser" field */
|
|
const char *updateUser;
|
|
|
|
/* "pwd" field */
|
|
const char *pwd;
|
|
} UpdateUserSpec;
|
|
|
|
typedef struct
|
|
{
|
|
StringView user;
|
|
|
|
bool showPrivileges;
|
|
} GetUserSpec;
|
|
|
|
/*
|
|
* Hash entry structure for user roles.
|
|
*/
|
|
typedef struct UserRoleHashEntry
|
|
{
|
|
char *user;
|
|
HTAB *roles;
|
|
bool isExternal;
|
|
} UserRoleHashEntry;
|
|
|
|
/* Method to call Connection Status command */
|
|
Datum connection_status(pgbson *showPrivilegesSpec);
|
|
|
|
#endif
|