Files
William Wang 5a37471d7d Merged PR 1784924: Utility File and Query Refactoring for Role/User CRUD APIs
### 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
2025-09-09 11:03:42 +08:00

49 lines
946 B
C

/*-------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* include/roles.h
*
* Role CRUD functions.
*
*-------------------------------------------------------------------------
*/
#ifndef EXTENSION_ROLES_H
#define EXTENSION_ROLES_H
#include "postgres.h"
#include "utils/string_view.h"
typedef struct
{
const char *roleName;
List *inheritedBuiltInRoles;
} CreateRoleSpec;
typedef struct
{
List *roleNames;
bool showAllRoles;
bool showBuiltInRoles;
bool showPrivileges;
} RolesInfoSpec;
typedef struct
{
const char *roleName;
} DropRoleSpec;
/* Method to create a role */
Datum create_role(pgbson *createRoleBson);
/* Method to drop a role */
Datum drop_role(pgbson *dropRoleBson);
/* Method to get roles information */
Datum roles_info(pgbson *rolesInfoBson);
/* Method to update a role */
Datum update_role(pgbson *updateRoleBson);
#endif