-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAssetCount.py
More file actions
47 lines (37 loc) · 1.72 KB
/
AssetCount.py
File metadata and controls
47 lines (37 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
purview_account_name = "PURVIEW_ACCOUNT_NAME"
client_id = "SERVICE_PRINCIPAL_ID"
client_secret = "SERVICE_PRINCIPAL_SECRET"
resource = "https://purview.azure.net"
tenant_id = "TENANT_ID"
synapse_workspace_name = "SYNAPSE_WORKSPACE_NAME"
# oauth2 login
url = "https://login.microsoftonline.com/" + tenant_id + "/oauth2/token"
# Login and get token
payload='grant_type=client_credentials&client_id=' + client_id + '&client_secret=' + client_secret + '&resource=' + resource
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
# Get & set the access token
response = json.loads(requests.request("POST", url, headers=headers, data=payload).content)
access_token = response['access_token']
purview_endpoint = "https://"+purview_account_name+".catalog.purview.azure.com"
url = purview_endpoint + "/api/search/query?api-version=2021-05-01-preview"
headers = {
'Authorization': 'Bearer ' + access_token,
'Content-Type': 'application/json'
}
#Search for assets based on keyword and entity type.
#Tables
payload = json.dumps({
"keywords": "mssql://"+synapse_workspace_name+"-ondemand.sql.azuresynapse.net/*",
"filter": {"entityType": "azure_synapse_serverless_sql_table"}
})
response = json.loads(requests.request("POST", url, headers=headers, data=payload).content)
print('Number of Synapse SQL Tables: ' + str(response['@search.count']))
#Views
payload = json.dumps({
"keywords": "mssql://"+synapse_workspace_name+"-ondemand.sql.azuresynapse.net/*",
"filter": {"entityType": "azure_synapse_serverless_sql_view"}
})
response = json.loads(requests.request("POST", url, headers=headers, data=payload).content)
print('Number of Synapse SQL Views: ' + str(response['@search.count']))