* documentdb_extension_drop_user implements the * core logic to drop a user */
| 519 | * core logic to drop a user |
| 520 | */ |
| 521 | Datum |
| 522 | documentdb_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"); |
nothing calls this directly
no test coverage detected