Last active
March 18, 2020 01:24
-
-
Save neil90-db/0a182fb06fa1c0bb621a6836fdbe176e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| #variables | |
| job_info = {"jobs_details":[]} | |
| shard = "https://yourshard.cloud.databricks.com" | |
| token = "YOURSECRET" | |
| # Get list of jobs | |
| jobs_list = requests.get(f"{shard}/api/2.0/jobs/list", auth=('token', token)).json()['jobs'] | |
| # Loop through each item(job essentiall) | |
| for job in jobs_list: | |
| # Get job details | |
| job_details = {"job_id":job["job_id"] ,"name": job["settings"]["name"], "creator_user_name": job["creator_user_name"], "job_owner_group":[], "job_owner_user":[]} | |
| print(job_details["job_id"]) | |
| # Get permissions on job | |
| job_permissions = requests.get(f"{shard}/api/2.0/preview/permissions/jobs/" + str(job["job_id"]), auth=('token', token)).json()["access_control_list"] | |
| # For each entity(group/user) with permissions loop through them and see who is 'IS_OWNER' | |
| for permission in job_permissions: | |
| # Admin group just ignore, as they can always manage a job | |
| if permission.get('group_name') == 'admins': | |
| pass | |
| elif permission.get('group_name'): | |
| if permission['all_permissions'][0]['permission_level'] == 'IS_OWNER': | |
| job_details["job_owner_group"].append(permission.get('group_name')) | |
| elif permission.get('user_name'): | |
| if permission['all_permissions'][0]['permission_level'] == 'IS_OWNER': | |
| job_details["job_owner_user"].append(permission.get('user_name')) | |
| job_info["jobs_details"].append(job_details) | |
| # Print the json we built that has the following information | |
| # The Job Id, Creator of the job, Groups that are 'IS_OWNER', Users that are 'IS_OWNER', Name of Job | |
| import pprint | |
| for job in job_info["jobs_details"]: | |
| pprint.pprint(job) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment