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

Function connection_status

pg_documentdb/src/commands/users.c:1127–1207  ·  view source on GitHub ↗

* connection_status implements the * core logic for connectionStatus command */

Source from the content-addressed store, hash-verified

1125 * core logic for connectionStatus command
1126 */
1127Datum
1128connection_status(pgbson *showPrivilegesSpec)
1129{
1130 ReportFeatureUsage(FEATURE_CONNECTION_STATUS);
1131
1132 bool showPrivileges = false;
1133 if (showPrivilegesSpec != NULL)
1134 {
1135 showPrivileges = ParseConnectionStatusSpec(showPrivilegesSpec);
1136 }
1137
1138 bool noError = true;
1139 const char *currentUser = GetUserNameFromId(GetUserId(), noError);
1140
1141 bool returnDocuments = false;
1142 Datum userInfoDatum = GetSingleUserInfo(currentUser, returnDocuments);
1143
1144 if (userInfoDatum == (Datum) 0)
1145 {
1146 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
1147 errmsg(
1148 "Cannot find logged-in user")));
1149 }
1150
1151 const char *parentRole = text_to_cstring(DatumGetTextP(userInfoDatum));
1152 if (parentRole == NULL)
1153 {
1154 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
1155 errmsg(
1156 "Unable to locate appropriate role for the specified user")));
1157 }
1158
1159 /*
1160 * Example output structure:
1161 * {
1162 * authInfo: {
1163 * authenticatedUsers: [ { user: ..., db: ... } ], // always 1 element
1164 * authenticatedUserRoles: [ { role: ..., db: ... }, ... ],
1165 * authenticatedUserPrivileges: [ { privilege }, ... ] // if showPrivileges
1166 * },
1167 * ok: 1
1168 * }
1169 *
1170 * privilege: { resource: { db:, collection: }, actions: [...] }
1171 */
1172 pgbson_writer finalWriter;
1173 PgbsonWriterInit(&finalWriter);
1174 pgbson_writer authInfoWriter;
1175 PgbsonWriterStartDocument(&finalWriter, "authInfo", 8,
1176 &authInfoWriter);
1177
1178 pgbson_array_writer usersArrayWriter;
1179 PgbsonWriterStartArray(&authInfoWriter, "authenticatedUsers", 18, &usersArrayWriter);
1180 pgbson_writer userWriter;
1181 PgbsonArrayWriterStartDocument(&usersArrayWriter, &userWriter);
1182 PgbsonWriterAppendUtf8(&userWriter, "user", 4, currentUser);
1183 PgbsonWriterAppendUtf8(&userWriter, "db", 2, "admin");
1184 PgbsonArrayWriterEndDocument(&usersArrayWriter, &userWriter);

Callers 1

Calls 15

ReportFeatureUsageFunction · 0.85
GetSingleUserInfoFunction · 0.85
PgbsonWriterInitFunction · 0.85
PgbsonWriterStartArrayFunction · 0.85
PgbsonWriterAppendUtf8Function · 0.85
PgbsonWriterEndArrayFunction · 0.85
WritePrivilegesFunction · 0.85
PgbsonWriterEndDocumentFunction · 0.85

Tested by

no test coverage detected