I would like to programmatically download the entity (Artist, Admin, etc) permissions (Shot: see, created, delete, edit, etc) and haven’t been able to find a way with my limited knowledge of Shotgun. I have tried the shotgun_api3 module, but although I am able to get the PermissionRuleSet data itself (eg sg.schema_field_read("PermissionRuleSet")), I can’t find a way to get the actual permission data proper.
The permissions are available from a POST request in the REST API used by the webbrowser, obviously, so, using my limited web knowledge, I tried mimicking what it was doing with the Python requests module like so:
# Get authorization tokens
url = "https://<REDACTED>.shotgunstudio.com/api/v1/auth/access_token"
data = {"client_id": <REDACTED>,
"client_secret": <REDACTED>,
"grant_type": "client_credentials"}
response = requests.post(url, data=data)
authorization = response.json()
# Lookup permission rule set
url = "https://<REDACTED>.shotgunstudio.com/page/permissions_for_entity_types_for_role"
data = {"permission_rule_set_code": "artist"}
headers = {}
headers["Authorization"] = "{} {}".format(authorization["token_type"], authorization["access_token"])
response = requests.post(url, headers=headers, json=data)
The authorization works correctly (I get back the expected tokens), but the POST response is an HTML page of javascript dealing with logins. My Chrome browser doesn’t render the page correctly, so I infer that its trying to get me to login.
I’m hoping that the above just needs some tweaks (I’m not a web dev), but I’m open to other programmatic tools and techniques too. I don’t need to re-upload changes to permissions, only to readout the current values, via a cron job, say.
Any advice? How can I get the permissions tables data?
Backstory: A version of something went missing, even though the local databases and filesystems indicate it was published correctly. After some consternation, the item was found in the SG trash and un-retired, and so production tranquility was restored. A ticket has come down to alter delete permissions so that this can be avoided in the future. I would like to capture the current state of permissions to track changes, the introduction server-side of new permissions with advancing versions of SG, etc. etc.