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

Function ParseActionsArray

pg_documentdb/src/commands/roles.c:606–659  ·  view source on GitHub ↗

* ParseActionsArray parses the "actions" field from a privilege entry. * Returns a hash set of action strings for automatic deduplication. */

Source from the content-addressed store, hash-verified

604 * Returns a hash set of action strings for automatic deduplication.
605 */
606static HTAB *
607ParseActionsArray(bson_iter_t *privilegeDocIter)
608{
609 if (bson_iter_type(privilegeDocIter) != BSON_TYPE_ARRAY)
610 {
611 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
612 errmsg("'actions' must be an array.")));
613 }
614
615 /* Create a hash set for deduplication */
616 HASHCTL hashCtl;
617 MemSet(&hashCtl, 0, sizeof(hashCtl));
618 hashCtl.keysize = NAMEDATALEN;
619 hashCtl.entrysize = NAMEDATALEN;
620 HTAB *actions = hash_create("ActionsSet", 8, &hashCtl, HASH_ELEM | HASH_STRINGS);
621
622 bson_iter_t actionsIter;
623 bson_iter_recurse(privilegeDocIter, &actionsIter);
624
625 while (bson_iter_next(&actionsIter))
626 {
627 if (bson_iter_type(&actionsIter) != BSON_TYPE_UTF8)
628 {
629 hash_destroy(actions);
630 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
631 errmsg("Each action must be a string.")));
632 }
633
634 uint32_t actionLength = 0;
635 const char *action = bson_iter_utf8(&actionsIter, &actionLength);
636
637 if (actionLength > 0 && actionLength < NAMEDATALEN)
638 {
639 if (!IsActionSupported(action))
640 {
641 hash_destroy(actions);
642 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
643 errmsg("Unsupported action '%s'.",
644 action)));
645 }
646
647 hash_search(actions, action, HASH_ENTER, NULL);
648 }
649 }
650
651 if (hash_get_num_entries(actions) == 0)
652 {
653 hash_destroy(actions);
654 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
655 errmsg("At least one valid action must be specified.")));
656 }
657
658 return actions;
659}
660
661
662/*

Callers 1

ParsePrivilegesArrayFunction · 0.85

Calls 1

IsActionSupportedFunction · 0.85

Tested by

no test coverage detected