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
- 2K Product Ideas
- 2K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 311 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 3.8K Transform
- 656 Datasets
- 115 SQL DataFlows
- 2.2K Magic ETL
- 811 Beast Mode
- 3.3K Visualize
- 2.5K Charting
- 80 App Studio
- 45 Variables
- 771 Automate
- 190 Apps
- 481 APIs & Domo Developer
- 77 Workflows
- 23 Code Engine
- 36 AI and Machine Learning
- 19 AI Chat
- AI Playground
- AI Projects and Models
- 17 Jupyter Workspaces
- 410 Distribute
- 120 Domo Everywhere
- 280 Scheduled Reports
- 10 Software Integrations
- 142 Manage
- 138 Governance & Security
- 8 Domo Community Gallery
- 48 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 114 Community Announcements
- 4.8K Archive