* documentdb_extension_get_users implements the * core logic to get user info */
| 916 | * core logic to get user info |
| 917 | */ |
| 918 | Datum |
| 919 | documentdb_extension_get_users(PG_FUNCTION_ARGS) |
| 920 | { |
| 921 | if (!EnableUserCrud) |
| 922 | { |
| 923 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), |
| 924 | errmsg("UsersInfo command is not supported."), |
| 925 | errdetail_log("UsersInfo command is not supported."))); |
| 926 | } |
| 927 | |
| 928 | ReportFeatureUsage(FEATURE_USER_GET); |
| 929 | |
| 930 | if (PG_ARGISNULL(0)) |
| 931 | { |
| 932 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 933 | errmsg("'usersInfo' must be provided."))); |
| 934 | } |
| 935 | |
| 936 | GetUserSpec userSpec = { 0 }; |
| 937 | ParseGetUserSpec(PG_GETARG_PGBSON(0), &userSpec); |
| 938 | const char *userName = userSpec.user.length > 0 ? userSpec.user.string : NULL; |
| 939 | const bool showAllUsers = userSpec.showAllUsers; |
| 940 | const bool showPrivileges = userSpec.showPrivileges; |
| 941 | |
| 942 | if (showAllUsers && showPrivileges) |
| 943 | { |
| 944 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 945 | errmsg( |
| 946 | "The 'showPrivileges' option is not supported when 'usersInfo' is set to 1."))); |
| 947 | } |
| 948 | |
| 949 | Datum userInfoDatum; |
| 950 | if (showAllUsers) |
| 951 | { |
| 952 | userInfoDatum = GetAllUsersInfo(); |
| 953 | } |
| 954 | else |
| 955 | { |
| 956 | bool returnDocuments = true; |
| 957 | userInfoDatum = GetSingleUserInfo(userName, returnDocuments); |
| 958 | } |
| 959 | |
| 960 | pgbson_writer finalWriter; |
| 961 | PgbsonWriterInit(&finalWriter); |
| 962 | |
| 963 | if (userInfoDatum == (Datum) 0) |
| 964 | { |
| 965 | PgbsonWriterAppendInt32(&finalWriter, "ok", 2, 1); |
| 966 | pgbson *result = PgbsonWriterGetPgbson(&finalWriter); |
| 967 | PG_RETURN_POINTER(result); |
| 968 | } |
| 969 | |
| 970 | ArrayType *userArray = DatumGetArrayTypeP(userInfoDatum); |
| 971 | Datum *userDatums; |
| 972 | bool *userIsNullMarker; |
| 973 | int userCount; |
| 974 | |
| 975 | bool arrayByVal = false; |
nothing calls this directly
no test coverage detected