* 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. */
| 1266 | * its native name for output. |
| 1267 | */ |
| 1268 | static void |
| 1269 | WriteRoles(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 | /* |
no test coverage detected