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

Function ParseRoleInheritanceResult

pg_documentdb/src/commands/roles.c:1627–1683  ·  view source on GitHub ↗

* ParseRoleInheritanceResult parses a BSON document from the role inheritance query. * Extracts the child_role and parent_roles fields. */

Source from the content-addressed store, hash-verified

1625 * Extracts the child_role and parent_roles fields.
1626 */
1627static void
1628ParseRoleInheritanceResult(pgbson *rowBson, const char **childRole, List **parentRoles)
1629{
1630 bson_iter_t iter;
1631 PgbsonInitIterator(rowBson, &iter);
1632
1633 *childRole = NULL;
1634 *parentRoles = NIL;
1635
1636 while (bson_iter_next(&iter))
1637 {
1638 const char *key = bson_iter_key(&iter);
1639
1640 if (strcmp(key, "child_role") == 0)
1641 {
1642 if (bson_iter_type(&iter) != BSON_TYPE_UTF8)
1643 {
1644 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
1645 errmsg(
1646 "Invalid type for 'child_role' in role inheritance query result.")));
1647 }
1648
1649 *childRole = bson_iter_utf8(&iter, NULL);
1650 }
1651 else if (strcmp(key, "parent_roles") == 0)
1652 {
1653 if (bson_iter_type(&iter) != BSON_TYPE_ARRAY)
1654 {
1655 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
1656 errmsg(
1657 "Invalid type for 'parent_roles' in role inheritance query result.")));
1658 }
1659
1660 bson_iter_t arrayIter;
1661 bson_iter_recurse(&iter, &arrayIter);
1662 while (bson_iter_next(&arrayIter))
1663 {
1664 if (bson_iter_type(&arrayIter) != BSON_TYPE_UTF8)
1665 {
1666 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
1667 errmsg(
1668 "Invalid type for element in 'parent_roles' array in role inheritance query result.")));
1669 }
1670
1671 const char *parentRole = bson_iter_utf8(&arrayIter, NULL);
1672 *parentRoles = lappend(*parentRoles, pstrdup(parentRole));
1673 }
1674 }
1675 else
1676 {
1677 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
1678 errmsg(
1679 "Unknown field '%s' in role inheritance query result.",
1680 key)));
1681 }
1682 }
1683}
1684

Callers 1

Calls 1

PgbsonInitIteratorFunction · 0.85

Tested by

no test coverage detected