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

Function documentdb_extension_drop_user

pg_documentdb/src/commands/users.c:521–594  ·  view source on GitHub ↗

* documentdb_extension_drop_user implements the * core logic to drop a user */

Source from the content-addressed store, hash-verified

519 * core logic to drop a user
520 */
521Datum
522documentdb_extension_drop_user(PG_FUNCTION_ARGS)
523{
524 if (!EnableUserCrud)
525 {
526 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED),
527 errmsg("The DropUser operation is currently unsupported."),
528 errdetail_log(
529 "The DropUser operation is currently unsupported.")));
530 }
531
532 if (PG_ARGISNULL(0))
533 {
534 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
535 errmsg("The field 'dropUser' is mandatory.")));
536 }
537
538 if (!IsMetadataCoordinator())
539 {
540 StringInfo dropUserQuery = makeStringInfo();
541 appendStringInfo(dropUserQuery,
542 "SELECT %s.drop_user(%s::%s.bson)",
543 ApiSchemaNameV2,
544 quote_literal_cstr(PgbsonToHexadecimalString(PG_GETARG_PGBSON(
545 0))),
546 CoreSchemaNameV2);
547 DistributedRunCommandResult result = RunCommandOnMetadataCoordinator(
548 dropUserQuery->data);
549
550 if (!result.success)
551 {
552 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
553 errmsg(
554 "Internal error dropping user in metadata coordinator %s",
555 text_to_cstring(result.response)),
556 errdetail_log(
557 "Internal error dropping user in metadata coordinator via distributed call %s",
558 text_to_cstring(result.response))));
559 }
560
561 pgbson_writer finalWriter;
562 PgbsonWriterInit(&finalWriter);
563 PgbsonWriterAppendInt32(&finalWriter, "ok", 2, 1);
564 PG_RETURN_POINTER(PgbsonWriterGetPgbson(&finalWriter));
565 }
566
567 pgbson *dropUserSpec = PG_GETARG_PGBSON(0);
568 char *dropUser = ParseDropUserSpec(dropUserSpec);
569
570 if (IsUserExternal(dropUser))
571 {
572 if (!DropUserWithExternalIdentityProvider(dropUser))
573 {
574 pgbson_writer finalWriter;
575 PgbsonWriterInit(&finalWriter);
576 PgbsonWriterAppendInt32(&finalWriter, "ok", 2, 0);
577 PgbsonWriterAppendUtf8(&finalWriter, "errmsg", 6,
578 "External identity providers are currently unsupported");

Callers

nothing calls this directly

Calls 11

IsMetadataCoordinatorFunction · 0.85
PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendInt32Function · 0.85
PgbsonWriterGetPgbsonFunction · 0.85
ParseDropUserSpecFunction · 0.85
IsUserExternalFunction · 0.85
PgbsonWriterAppendUtf8Function · 0.85
DropNativeUserFunction · 0.85

Tested by

no test coverage detected