Index
shotgrid_casbin_adapter ¶
ShotGrid Casbin Adapter.
A Casbin policy adapter that enables loading and saving access control policies from/to Autodesk ShotGrid (formerly Shotgun).
Adapter ¶
Adapter(sg: Shotgun | None = None, base_url: str | None = None, script_name: str | None = None, api_key: str | None = None, entity_type: str | None = None, project_id: int | None = None, filtered: bool = False)
Bases: Adapter, UpdateAdapter
Casbin policy adapter backed by Autodesk ShotGrid.
This adapter maps Casbin policy rules to ShotGrid custom entity records.
Each record contains ptype and v0-v5 fields representing one
policy line.
When project_id is provided, all operations are scoped to that project:
queries include a project filter, and created entities are linked to the
project. This enables per-project policy isolation within a single ShotGrid
site. When project_id is None, the adapter operates at site level.
ShotGrid's delete() operation retires entities rather than destroying
them, and find() excludes retired records by default. This provides
natural soft-delete behavior without additional configuration.
| PARAMETER | DESCRIPTION |
|---|---|
sg
|
An existing
TYPE:
|
base_url
|
ShotGrid server URL. Falls back to
TYPE:
|
script_name
|
ShotGrid script name. Falls back to
TYPE:
|
api_key
|
ShotGrid API key. Falls back to
TYPE:
|
entity_type
|
ShotGrid entity type for storing rules.
Falls back to
TYPE:
|
project_id
|
ShotGrid project ID for scoping operations.
Falls back to
TYPE:
|
filtered
|
Whether this adapter supports filtered policy loading.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If neither |
Initialize the ShotGrid Casbin adapter.
| PARAMETER | DESCRIPTION |
|---|---|
sg
|
An existing
TYPE:
|
base_url
|
ShotGrid server URL. Falls back to
TYPE:
|
script_name
|
ShotGrid script name. Falls back to
TYPE:
|
api_key
|
ShotGrid API key. Falls back to
TYPE:
|
entity_type
|
ShotGrid entity type for storing rules.
Falls back to
TYPE:
|
project_id
|
ShotGrid project ID for scoping operations.
Falls back to
TYPE:
|
filtered
|
Whether this adapter supports filtered policy loading.
TYPE:
|
Source code in shotgrid_casbin_adapter/core.py
project_id
property
¶
The ShotGrid project ID for scoping operations, or None for site-wide.
add_policies ¶
Add multiple policy rules to ShotGrid via batch operation.
| PARAMETER | DESCRIPTION |
|---|---|
sec
|
The policy section (
TYPE:
|
ptype
|
The policy type identifier.
TYPE:
|
rules
|
A list of policy rule value lists.
TYPE:
|
Source code in shotgrid_casbin_adapter/core.py
add_policy ¶
Add a policy rule to ShotGrid.
| PARAMETER | DESCRIPTION |
|---|---|
sec
|
The policy section (
TYPE:
|
ptype
|
The policy type identifier.
TYPE:
|
rule
|
The policy rule values.
TYPE:
|
Source code in shotgrid_casbin_adapter/core.py
is_filtered ¶
Check whether the adapter is in filtered mode.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
load_filtered_policy ¶
Load policy rules matching the filter from ShotGrid.
After loading, the adapter is marked as filtered (is_filtered()
returns True).
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The Casbin model to populate with matching policy rules.
TYPE:
|
filter
|
A :class:
TYPE:
|
Source code in shotgrid_casbin_adapter/core.py
load_policy ¶
Load all policy rules from ShotGrid into the Casbin model.
Queries all non-retired entities of the configured type (optionally
scoped to the configured project) and feeds each one into
:func:casbin.persist.load_policy_line.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The Casbin model to populate with policy rules.
TYPE:
|
Source code in shotgrid_casbin_adapter/core.py
remove_filtered_policy ¶
Remove policy rules matching a field filter from ShotGrid.
| PARAMETER | DESCRIPTION |
|---|---|
sec
|
The policy section (
TYPE:
|
ptype
|
The policy type identifier.
TYPE:
|
field_index
|
The starting field index (0-5) for filtering.
TYPE:
|
*field_values
|
The field values to match starting at
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
Source code in shotgrid_casbin_adapter/core.py
remove_policies ¶
Remove multiple policy rules from ShotGrid via batch operation.
| PARAMETER | DESCRIPTION |
|---|---|
sec
|
The policy section (
TYPE:
|
ptype
|
The policy type identifier.
TYPE:
|
rules
|
A list of policy rule value lists to remove.
TYPE:
|
Source code in shotgrid_casbin_adapter/core.py
remove_policy ¶
Remove a policy rule from ShotGrid.
ShotGrid's delete retires the entity (soft-delete). ``find() excludes retired records by default.
| PARAMETER | DESCRIPTION |
|---|---|
sec
|
The policy section (
TYPE:
|
ptype
|
The policy type identifier.
TYPE:
|
rule
|
The policy rule values to remove.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
Source code in shotgrid_casbin_adapter/core.py
save_policy ¶
Save all policy rules from the Casbin model to ShotGrid.
Replaces all existing rules with the current model state. First
deletes all existing entities (optionally scoped to the configured
project), then creates new ones for every rule in the model's
"p" and "g" sections.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The Casbin model whose rules to persist.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
Source code in shotgrid_casbin_adapter/core.py
update_filtered_policies ¶
update_filtered_policies(sec: str, ptype: str, new_rules: list[list[str]], field_index: int, *field_values: str) -> list[list[str]]
Update all policies matching a filter with new rules.
Deletes all entities matching the filter, then creates new entities
for each rule in new_rules.
| PARAMETER | DESCRIPTION |
|---|---|
sec
|
The policy section (
TYPE:
|
ptype
|
The policy type identifier.
TYPE:
|
new_rules
|
The replacement policy rule value lists.
TYPE:
|
field_index
|
The starting field index (0-5) for filtering.
TYPE:
|
*field_values
|
The field values to match starting at
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[list[str]]
|
A list of the old rule value lists that were replaced. |
Source code in shotgrid_casbin_adapter/core.py
update_policies ¶
update_policies(sec: str, ptype: str, old_rules: list[list[str]], new_rules: list[list[str]]) -> None
Update multiple policy rules in ShotGrid.
| PARAMETER | DESCRIPTION |
|---|---|
sec
|
The policy section (
TYPE:
|
ptype
|
The policy type identifier.
TYPE:
|
old_rules
|
The current policy rule value lists.
TYPE:
|
new_rules
|
The replacement policy rule value lists.
TYPE:
|
Source code in shotgrid_casbin_adapter/core.py
update_policy ¶
Update a policy rule in ShotGrid.
Finds the first entity matching old_rule and updates its fields
to new_policy. If the new policy is shorter than the old rule,
excess fields are set to None.
| PARAMETER | DESCRIPTION |
|---|---|
sec
|
The policy section (
TYPE:
|
ptype
|
The policy type identifier.
TYPE:
|
old_rule
|
The current policy rule values.
TYPE:
|
new_policy
|
The replacement policy rule values.
TYPE:
|
Source code in shotgrid_casbin_adapter/core.py
Filter ¶
Filter for loading filtered policies from ShotGrid.
Each attribute is a list of values to match against the corresponding Casbin field. An empty list means the field is not filtered.
| ATTRIBUTE | DESCRIPTION |
|---|---|
ptype |
List of policy type values to filter by.
TYPE:
|
v0 |
List of v0 field values to filter by (maps to
TYPE:
|
v1 |
List of v1 field values to filter by.
TYPE:
|
v2 |
List of v2 field values to filter by.
TYPE:
|
v3 |
List of v3 field values to filter by.
TYPE:
|
v4 |
List of v4 field values to filter by.
TYPE:
|
v5 |
List of v5 field values to filter by.
TYPE:
|
Initialize a Filter with empty filter lists.