Hi, Is there any way to create a policy (either me...
# all-things-deployment
a
Hi, Is there any way to create a policy (either metadata or platform) via python SDK or rest API in DataHub? Thanks!
c
Hi Jason, yes it is. Via the Python SDK you can make use of
DataHubPolicySnapshotClass
This allows you to define custom policies programmatically. Happy to provide some more details, if needed 🙂
w
Hi @curved-planet-99787 - thanks for sharing this! Would you be able to share how you implemented the creation/update of a policy using
DataHubPolicySnapshotClass
? Did you use the rest emitter to create a metadata change event?
c
Sure, here is the creation of the MCE:
Copy code
mce = MetadataChangeEventClass(
                proposedSnapshot=DataHubPolicySnapshotClass(
                    urn=f"urn:li:dataHubPolicy:{policy.name}",
                    aspects=[
                        DataHubPolicyInfoClass(
                            actors=DataHubActorFilterClass(
                                allGroups=policy.all_groups,
                                allUsers=policy.all_users,
                                resourceOwners=policy.resource_owners,
                                users=policy.users,
                                groups=policy.groups,
                            ),
                            description=policy.description,
                            displayName=policy.display_name,
                            editable=policy.editable,
                            privileges=policy.privileges,
                            state=policy.state,
                            type=policy.type,
                        )
                    ],
                )
            )
The creation of the request is then done via:
emitter.emit(item=mcp)
where
emitter
is an instance of
DatahubRestEmitter
w
Thank you!
h
Is there any link that can view this API's
(DataHubPolicySnapshotClass)
detail infomation? @curved-planet-99787