Skip to content

Commit

Permalink
Merge branch 'datahub-project:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
anshbansal authored Jun 12, 2024
2 parents 14890e0 + 22fac3a commit cb7cef8
Showing 1 changed file with 43 additions and 16 deletions.
59 changes: 43 additions & 16 deletions metadata-ingestion/src/datahub/api/entities/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from datahub.emitter.mcp import MetadataChangeProposalWrapper
from datahub.ingestion.graph.client import DataHubGraph, get_default_graph
from datahub.metadata.schema_classes import (
FormActorAssignmentClass,
FormInfoClass,
FormPromptClass,
OwnerClass,
Expand Down Expand Up @@ -82,6 +83,12 @@ class Entities(ConfigModel):
filters: Optional[Filters] = None


class Actors(ConfigModel):
owners: Optional[bool] = None
users: Optional[List[str]] = None # can be user IDs or urns
groups: Optional[List[str]] = None # can be group IDs or urns


class Forms(ConfigModel):
id: Optional[str] = None
urn: Optional[str] = None
Expand All @@ -93,6 +100,7 @@ class Forms(ConfigModel):
entities: Optional[Entities] = None
owners: Optional[List[str]] = None # can be user IDs or urns
group_owners: Optional[List[str]] = None # can be group IDs or urns
actors: Optional[Actors] = None

@validator("urn", pre=True, always=True)
def urn_must_be_present(cls, v, values):
Expand Down Expand Up @@ -124,6 +132,7 @@ def create(file: str) -> None:
description=form.description,
prompts=form.validate_prompts(emitter),
type=form.type,
actors=form.create_form_actors(form.actors),
),
)
emitter.emit_mcp(mcp)
Expand Down Expand Up @@ -201,6 +210,24 @@ def validate_prompts(self, emitter: DataHubGraph) -> List[FormPromptClass]:

return prompts

def create_form_actors(
self, actors: Optional[Actors] = None
) -> Union[None, FormActorAssignmentClass]:
if actors is None:
return None

users = None
if actors.users is not None:
users = Forms.format_users(actors.users)

groups = None
if actors.groups is not None:
groups = Forms.format_groups(actors.groups)

return FormActorAssignmentClass(
owners=actors.owners, users=users, groups=groups
)

def upload_entities_for_form(self, emitter: DataHubGraph) -> Union[None, Exception]:
if self.entities and self.entities.urns:
formatted_entity_urns = ", ".join(
Expand Down Expand Up @@ -260,9 +287,9 @@ def create_form_filters(self, emitter: DataHubGraph) -> Union[None, Exception]:
def add_owners(self, emitter: DataHubGraph) -> Union[None, Exception]:
owner_urns: List[str] = []
if self.owners:
owner_urns += Forms.format_owners(self.owners)
owner_urns += Forms.format_users(self.owners)
if self.group_owners:
owner_urns += Forms.format_group_owners(self.group_owners)
owner_urns += Forms.format_groups(self.group_owners)

ownership = OwnershipClass(
owners=[
Expand Down Expand Up @@ -326,28 +353,28 @@ def from_datahub(graph: DataHubGraph, urn: str) -> "Forms":
)

@staticmethod
def format_owners(owners: List[str]) -> List[str]:
formatted_owners: List[str] = []
def format_users(users: List[str]) -> List[str]:
formatted_users: List[str] = []

for owner in owners:
if owner.startswith("urn:li:"):
formatted_owners.append(owner)
for user in users:
if user.startswith("urn:li:"):
formatted_users.append(user)
else:
formatted_owners.append(make_user_urn(owner))
formatted_users.append(make_user_urn(user))

return formatted_owners
return formatted_users

@staticmethod
def format_group_owners(owners: List[str]) -> List[str]:
formatted_owners: List[str] = []
def format_groups(groups: List[str]) -> List[str]:
formatted_groups: List[str] = []

for owner in owners:
if owner.startswith("urn:li:"):
formatted_owners.append(owner)
for group in groups:
if group.startswith("urn:li:"):
formatted_groups.append(group)
else:
formatted_owners.append(make_group_urn(owner))
formatted_groups.append(make_group_urn(group))

return formatted_owners
return formatted_groups

def to_yaml(
self,
Expand Down

0 comments on commit cb7cef8

Please sign in to comment.