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

Function documentdb_extension_get_users

pg_documentdb/src/commands/users.c:918–1003  ·  view source on GitHub ↗

* documentdb_extension_get_users implements the * core logic to get user info */

Source from the content-addressed store, hash-verified

916 * core logic to get user info
917 */
918Datum
919documentdb_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;

Callers

nothing calls this directly

Calls 12

ReportFeatureUsageFunction · 0.85
ParseGetUserSpecFunction · 0.85
GetAllUsersInfoFunction · 0.85
GetSingleUserInfoFunction · 0.85
PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendInt32Function · 0.85
PgbsonWriterGetPgbsonFunction · 0.85
BuildUserRoleEntryTableFunction · 0.85
PgbsonWriterStartArrayFunction · 0.85
WriteSingleUserDocumentFunction · 0.85
PgbsonWriterEndArrayFunction · 0.85
FreeUserRoleEntryTableFunction · 0.85

Tested by

no test coverage detected