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

Function WriteRoles

pg_documentdb/src/commands/users.c:1738–1803  ·  view source on GitHub ↗

* WriteRoles writes role information to a BSON array writer based on the parent role. * This consolidates the role mapping logic used by both usersInfo and connectionStatus commands. */

Source from the content-addressed store, hash-verified

1736 * This consolidates the role mapping logic used by both usersInfo and connectionStatus commands.
1737 */
1738static void
1739WriteRoles(const char *parentRole, pgbson_array_writer *roleArrayWriter)
1740{
1741 if (parentRole == NULL)
1742 {
1743 return;
1744 }
1745
1746 pgbson_writer roleWriter;
1747 PgbsonWriterInit(&roleWriter);
1748 if (strcmp(parentRole, ApiReadOnlyRole) == 0)
1749 {
1750 PgbsonWriterAppendUtf8(&roleWriter, "role", 4, "readAnyDatabase");
1751 PgbsonWriterAppendUtf8(&roleWriter, "db", 2, "admin");
1752 PgbsonArrayWriterWriteDocument(roleArrayWriter,
1753 PgbsonWriterGetPgbson(
1754 &roleWriter));
1755 }
1756 else if (strcmp(parentRole, ApiReadWriteRole) == 0)
1757 {
1758 PgbsonWriterAppendUtf8(&roleWriter, "role", 4,
1759 "readWriteAnyDatabase");
1760 PgbsonWriterAppendUtf8(&roleWriter, "db", 2, "admin");
1761 PgbsonArrayWriterWriteDocument(roleArrayWriter,
1762 PgbsonWriterGetPgbson(
1763 &roleWriter));
1764 }
1765 else if (strcmp(parentRole, ApiAdminRoleV2) == 0)
1766 {
1767 PgbsonWriterAppendUtf8(&roleWriter, "role", 4,
1768 "readWriteAnyDatabase");
1769 PgbsonWriterAppendUtf8(&roleWriter, "db", 2, "admin");
1770 PgbsonArrayWriterWriteDocument(roleArrayWriter,
1771 PgbsonWriterGetPgbson(
1772 &roleWriter));
1773 PgbsonWriterInit(&roleWriter);
1774 PgbsonWriterAppendUtf8(&roleWriter, "role", 4,
1775 "clusterAdmin");
1776 PgbsonWriterAppendUtf8(&roleWriter, "db", 2, "admin");
1777 PgbsonArrayWriterWriteDocument(roleArrayWriter,
1778 PgbsonWriterGetPgbson(
1779 &roleWriter));
1780 }
1781 else if (strcmp(parentRole, ApiUserAdminRole) == 0)
1782 {
1783 PgbsonWriterAppendUtf8(&roleWriter, "role", 4,
1784 "userAdminAnyDatabase");
1785 PgbsonWriterAppendUtf8(&roleWriter, "db", 2, "admin");
1786 PgbsonArrayWriterWriteDocument(roleArrayWriter,
1787 PgbsonWriterGetPgbson(
1788 &roleWriter));
1789 }
1790 else if (strcmp(parentRole, ApiRootRole) == 0)
1791 {
1792 PgbsonWriterAppendUtf8(&roleWriter, "role", 4,
1793 "root");
1794 PgbsonWriterAppendUtf8(&roleWriter, "db", 2, "admin");
1795 PgbsonArrayWriterWriteDocument(roleArrayWriter,

Callers 2

connection_statusFunction · 0.70
WriteMultipleRolesFunction · 0.70

Calls 4

PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendUtf8Function · 0.85
PgbsonWriterGetPgbsonFunction · 0.85

Tested by

no test coverage detected