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

Function drop_role

pg_documentdb/src/commands/roles.c:678–732  ·  view source on GitHub ↗

* drop_role implements the core logic for dropRole command */

Source from the content-addressed store, hash-verified

676 * drop_role implements the core logic for dropRole command
677 */
678Datum
679drop_role(pgbson *dropRoleBson)
680{
681 if (!EnableRoleCrud)
682 {
683 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED),
684 errmsg("DropRole command is not supported."),
685 errdetail_log("DropRole command is not supported.")));
686 }
687
688 if (!IsMetadataCoordinator())
689 {
690 StringInfo dropRoleQuery = makeStringInfo();
691 appendStringInfo(dropRoleQuery,
692 "SELECT %s.drop_role(%s::%s.bson)",
693 ApiSchemaNameV2,
694 quote_literal_cstr(PgbsonToHexadecimalString(dropRoleBson)),
695 CoreSchemaNameV2);
696 DistributedRunCommandResult result = RunCommandOnMetadataCoordinator(
697 dropRoleQuery->data);
698
699 if (!result.success)
700 {
701 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
702 errmsg(
703 "Drop role operation failed: %s",
704 text_to_cstring(result.response)),
705 errdetail_log(
706 "Drop role operation failed: %s",
707 text_to_cstring(result.response))));
708 }
709
710 pgbson_writer finalWriter;
711 PgbsonWriterInit(&finalWriter);
712 PgbsonWriterAppendInt32(&finalWriter, "ok", 2, 1);
713 return PointerGetDatum(PgbsonWriterGetPgbson(&finalWriter));
714 }
715
716 DropRoleSpec dropRoleSpec = { NULL };
717 ParseDropRoleSpec(dropRoleBson, &dropRoleSpec);
718
719 StringInfo dropUserInfo = makeStringInfo();
720 appendStringInfo(dropUserInfo, "DROP ROLE %s;", quote_identifier(
721 dropRoleSpec.roleName));
722
723 bool readOnly = false;
724 bool isNull = false;
725 ExtensionExecuteQueryViaSPI(dropUserInfo->data, readOnly, SPI_OK_UTILITY,
726 &isNull);
727
728 pgbson_writer finalWriter;
729 PgbsonWriterInit(&finalWriter);
730 PgbsonWriterAppendInt32(&finalWriter, "ok", 2, 1);
731 return PointerGetDatum(PgbsonWriterGetPgbson(&finalWriter));
732}
733
734
735/*

Callers 1

command_drop_roleFunction · 0.85

Calls 8

IsMetadataCoordinatorFunction · 0.85
PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendInt32Function · 0.85
PgbsonWriterGetPgbsonFunction · 0.85
ParseDropRoleSpecFunction · 0.85

Tested by

no test coverage detected