* drop_role implements the core logic for dropRole command */
| 676 | * drop_role implements the core logic for dropRole command |
| 677 | */ |
| 678 | Datum |
| 679 | drop_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 | /* |
no test coverage detected