MCPcopy Create free account
hub / github.com/documentdb/documentdb / roles_info

Function roles_info

pg_documentdb/src/commands/roles.c:821–901  ·  view source on GitHub ↗

* roles_info implements the core logic for rolesInfo command */

Source from the content-addressed store, hash-verified

819 * roles_info implements the core logic for rolesInfo command
820 */
821Datum
822roles_info(pgbson *rolesInfoBson)
823{
824 if (!EnableRoleCrud)
825 {
826 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED),
827 errmsg("RolesInfo command is not supported."),
828 errdetail_log("RolesInfo command is not supported.")));
829 }
830
831 if (!IsMetadataCoordinator())
832 {
833 StringInfo rolesInfoQuery = makeStringInfo();
834 appendStringInfo(rolesInfoQuery,
835 "SELECT %s.roles_info(%s::%s.bson)",
836 ApiSchemaNameV2,
837 quote_literal_cstr(PgbsonToHexadecimalString(rolesInfoBson)),
838 CoreSchemaNameV2);
839 DistributedRunCommandResult result = RunCommandOnMetadataCoordinator(
840 rolesInfoQuery->data);
841
842 if (!result.success)
843 {
844 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
845 errmsg(
846 "Roles info operation failed: %s",
847 text_to_cstring(result.response)),
848 errdetail_log(
849 "Roles info operation failed: %s",
850 text_to_cstring(result.response))));
851 }
852
853 pgbson_writer finalWriter;
854 PgbsonWriterInit(&finalWriter);
855 PgbsonWriterAppendInt32(&finalWriter, "ok", 2, 1);
856 return PointerGetDatum(PgbsonWriterGetPgbson(&finalWriter));
857 }
858
859 RolesInfoSpec rolesInfoSpec = {
860 .roleNames = NIL,
861 .showAllRoles = false,
862 .showBuiltInRoles = false,
863 .showPrivileges = false
864 };
865 ParseRolesInfoSpec(rolesInfoBson, &rolesInfoSpec);
866
867 pgbson_writer finalWriter;
868 PgbsonWriterInit(&finalWriter);
869
870 pgbson_array_writer rolesArrayWriter;
871 PgbsonWriterStartArray(&finalWriter, "roles", 5, &rolesArrayWriter);
872
873 /*
874 * Build the role inheritance table once with a single query.
875 * This allows looking up parent/inherited roles in memory.
876 */
877 HTAB *roleInheritanceTable = BuildRoleInheritanceTable();
878

Callers 1

command_roles_infoFunction · 0.85

Calls 13

IsMetadataCoordinatorFunction · 0.85
PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendInt32Function · 0.85
PgbsonWriterGetPgbsonFunction · 0.85
ParseRolesInfoSpecFunction · 0.85
PgbsonWriterStartArrayFunction · 0.85
FreeRoleInheritanceTableFunction · 0.85

Tested by

no test coverage detected