-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatabricks_test.py
66 lines (58 loc) · 1.92 KB
/
databricks_test.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import asyncio
from policyweaver.models.common import SourceMap
from policyweaver.policyweaver import Weaver
from policyweaver.sources.databricksclient import DatabricksPolicyWeaver
from dotenv import load_dotenv
import os
load_dotenv()
workspace_id=os.getenv('FABRIC_WORKSPACE_ID')
print(f"Workspace: {workspace_id}")
def create_config():
from policyweaver.models.common import (
SourceMap,
Source,
SourceSchema,
SourceMapItem,
ServicePrincipalConfig,
FabricConfig,
PolicyWeaverConnectorType,
)
return SourceMap(
type=PolicyWeaverConnectorType.UNITY_CATALOG,
source=Source(
name="bluewater_dw",
schemas=[
SourceSchema(name="taxi", tables=["nyctaxi_yellow"]),
SourceSchema(name="wwi"),
],
),
service_principal=ServicePrincipalConfig(
client_id=os.getenv('SERVICE_PRINCIPAL_CLIENT_ID'),
client_secret=os.getenv('SERVICE_PRINCIPAL_CLIENT_SECRET'),
tenant_id=os.getenv('SERVICE_PRINCIPAL_TENANT_ID'),
),
fabric=FabricConfig(
api_token=os.getenv('FABRIC_API_TOKEN'),
workspace_id=os.getenv('FABRIC_WORKSPACE_ID'),
lakehouse_name="mirrored",
),
mapped_items=[
SourceMapItem(
catalog="bluewater_dw",
catalog_schema="taxi",
table="nyctaxi_yellow",
lakehouse_table_name="nyctaxi_yellow",
)
],
)
async def weaver_run(config: SourceMap, dbx_token, dbx_workspace):
# Create Databricks Policy
dbx_policy_weaver = DatabricksPolicyWeaver(workspace=dbx_workspace, token=dbx_token)
# Extract Databricks Policy
dbx_policy_export = dbx_policy_weaver.map_policy(config.source)
# Create Policy Weaver
weaver = Weaver(config)
# Run Policy Weaver
await weaver.run(dbx_policy_export)
asyncio.run(weaver_run(create_config(), os.getenv('DBX_TOKEN'), os.getenv('DBX_WORKSPACE')))
print("Done")