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

Function WriteRoles

pg_documentdb/src/commands/roles.c:1268–1295  ·  view source on GitHub ↗

* WriteRoles writes the parent roles to the roles array. * Each internal role name is looked up in the inheritance table to get * its native name for output. */

Source from the content-addressed store, hash-verified

1266 * its native name for output.
1267 */
1268static void
1269WriteRoles(List *parentRoles, pgbson_array_writer *rolesArrayWriter,
1270 HTAB *roleInheritanceTable, const char *childRoleName)
1271{
1272 ListCell *roleCell;
1273 foreach(roleCell, parentRoles)
1274 {
1275 const char *internalParentRole = (const char *) lfirst(roleCell);
1276
1277 /* Look up parent role in HTAB to get its native name */
1278 bool parentFound = false;
1279 RoleParentEntry *parentEntry = (RoleParentEntry *) hash_search(
1280 roleInheritanceTable, internalParentRole, HASH_FIND, &parentFound);
1281 if (!parentFound)
1282 {
1283 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
1284 errmsg("Parent role '%s' of '%s' not found.",
1285 internalParentRole, childRoleName)));
1286 }
1287
1288 pgbson_writer parentRoleWriter;
1289 PgbsonArrayWriterStartDocument(rolesArrayWriter, &parentRoleWriter);
1290 PgbsonWriterAppendUtf8(&parentRoleWriter, "role", 4,
1291 parentEntry->nativeRoleName);
1292 PgbsonWriterAppendUtf8(&parentRoleWriter, "db", 2, "admin");
1293 PgbsonArrayWriterEndDocument(rolesArrayWriter, &parentRoleWriter);
1294 }
1295}
1296
1297
1298/*

Callers 1

WriteRoleResponseFunction · 0.70

Calls 4

PgbsonWriterAppendUtf8Function · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected