* roles_info implements the core logic for rolesInfo command */
| 819 | * roles_info implements the core logic for rolesInfo command |
| 820 | */ |
| 821 | Datum |
| 822 | roles_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 |
no test coverage detected