Creating PDP Policy using Python
Hi All,
I am having some issue creating PDP policy through Python. The script runs without error and creates the policy but it does not add users into that policy. I wrote this based on the domo github repository. The goal is basically to assign the access to the data based on the office column in master dataset and some users have access to the data of multiple office. I have attached the screenshot of sample Permission dataset id, user dataset id and masterdataset id and sample code in python 3.5.
Dataset Descriptions: These all datasets are in domo.
user dataset has User ID , Name of the user and and their Employee Number [Specific to our company]
Master Dataset is the dataset where PDP Policy is to be created based on the office filter
Permission Dataset has User ID, Name of user and office they should have access to.
PDP policy is the screenshot of the policy that is created on the master dataset.
Any help will be greatly appreciated!
import requests
from requests.auth import HTTPBasicAuth
import json # json is a Python standard package
from pydomo import Domo
# SCRIPT PARAMETERS
apiRoot = "https://api.domo.com"
clientId = "<your client id here>"
clientSecret = "<your client secret here>"
permissionsDatasetId = "<your dataset id here>"
masterDatasetId = "<your dataset id here>"
user_dataset_id = "<your user dataset id>"
offices = ["Austin", "Tempe", "Boston", "New York","West Palm Beach","San Diego","Chicago","Philadelphia"]
# GENERATE ACCESS TOKEN
tokenResponse = requests.get(apiRoot+"/oauth/token?grant_type=client_credentials&scope=user data", auth=HTTPBasicAuth(clientId, clientSecret))
accessToken = tokenResponse.json()["access_token"]
#print (accessToken)
# GET USER LIST (WITH IDS)
#x[1] is username and x[0] is user id
User_dataset = requests.get(apiRoot+"/v1/datasets/"+user_dataset_id+"/data?includeHeader=false", headers={"Authorization": "bearer "+accessToken})
user_permissions = [row.split(",") for row in User_dataset.text.split("\n")][:-1]
users = [[x[1],x[0]] for x in user_permissions]
# GET PERMISSIONS DATASET CONTENT FROM INSTANCE
permissionsResponse = requests.get(apiRoot+"/v1/datasets/"+permissionsDatasetId+"/data?includeHeader=false", headers={"Authorization": "bearer "+accessToken})
permission_list = [row.split(",") for row in permissionsResponse.text.split("\n")][:-1]
permissions = [[x[2],x[0],x[1]] for x in permission_list]
# for permissionRow in permissions:
# print(permissionRow)
# CREATE PDP FILTER CONFIGURATION OBJECTS FOR UPLOAD
def getIdForUser(userName):
return filter(lambda user: user[0] == userName, users)[0][1]
def makeFilterForPDP(region):
return {
"name": region,
"filters": [{
"column": "Office",
"values": [region],
"operator": "EQUALS"
}],
"users": [getIdForUser(user[0]) for user in filter(lambda permissionRow: permissionRow[1] == region, permissions)]
}
filtersForPDP = map(makeFilterForPDP, offices)
# CREATE THE PDP POLICIES
def createPDPPolicy(filter):
creationResponse = requests.post(apiRoot+"/v1/datasets/"+masterDatasetId+"/policies", data=json.dumps(filter), headers={"Authorization": "bearer "+accessToken, "Content-Type": "application/json"})
return creationResponse.text
PDPPolicies = [createPDPPolicy(filter) for filter in filtersForPDP]
# print(PDPPolicies)
Comments
-
Hi,
Is anyone able to help out with this request?
Thanks,0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 57 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive