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

Function WriteSinglePrivilegeDocument

pg_documentdb/src/utils/role_utils.c:587–646  ·  view source on GitHub ↗

* Helper function to write a single privilege document. */

Source from the content-addressed store, hash-verified

585 * Helper function to write a single privilege document.
586 */
587static void
588WriteSinglePrivilegeDocument(const ConsolidatedPrivilege *privilege,
589 pgbson_array_writer *privilegesArrayWriter)
590{
591 pgbson_writer privilegeWriter;
592 PgbsonArrayWriterStartDocument(privilegesArrayWriter, &privilegeWriter);
593
594 pgbson_writer resourceWriter;
595 PgbsonWriterStartDocument(&privilegeWriter, "resource", 8,
596 &resourceWriter);
597 if (privilege->isCluster)
598 {
599 PgbsonWriterAppendBool(&resourceWriter, "cluster", 7,
600 true);
601 }
602 else
603 {
604 PgbsonWriterAppendUtf8(&resourceWriter, "db", 2,
605 privilege->db);
606 PgbsonWriterAppendUtf8(&resourceWriter, "collection", 10,
607 privilege->collection);
608 }
609 PgbsonWriterEndDocument(&privilegeWriter, &resourceWriter);
610
611 pgbson_array_writer actionsArrayWriter;
612 PgbsonWriterStartArray(&privilegeWriter, "actions", 7,
613 &actionsArrayWriter);
614
615 if (privilege->actions != NULL)
616 {
617 HASH_SEQ_STATUS status;
618 StringView *privilegeEntry;
619 List *actionList = NIL;
620
621 hash_seq_init(&status, privilege->actions);
622 while ((privilegeEntry = hash_seq_search(&status)) != NULL)
623 {
624 char *actionString = palloc(privilegeEntry->length + 1);
625 memcpy(actionString, privilegeEntry->string, privilegeEntry->length);
626 actionString[privilegeEntry->length] = '\0';
627 actionList = lappend(actionList, actionString);
628 }
629
630 if (actionList != NIL)
631 {
632 SortStringList(actionList);
633 ListCell *cell;
634 foreach(cell, actionList)
635 {
636 PgbsonArrayWriterWriteUtf8(&actionsArrayWriter, (const char *) lfirst(
637 cell));
638 }
639 list_free_deep(actionList);
640 }
641 }
642
643 PgbsonWriterEndArray(&privilegeWriter, &actionsArrayWriter);
644

Callers 1

Calls 11

PgbsonWriterAppendBoolFunction · 0.85
PgbsonWriterAppendUtf8Function · 0.85
PgbsonWriterEndDocumentFunction · 0.85
PgbsonWriterStartArrayFunction · 0.85
SortStringListFunction · 0.85
PgbsonWriterEndArrayFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected