Skip to content

Commit

Permalink
Merge branch 'main' into rbac-domain
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketkatkar97 authored Jul 30, 2024
2 parents d7103d4 + c84baaf commit e82a68a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
MetabaseDashboardList,
MetabaseDatabase,
MetabaseTable,
MetabaseUser,
)
from metadata.utils.constants import AUTHORIZATION_HEADER, NO_ACCESS_TOKEN
from metadata.utils.logger import ingestion_logger
Expand Down Expand Up @@ -194,3 +195,18 @@ def get_table(self, table_id: str) -> Optional[MetabaseTable]:
logger.debug(traceback.format_exc())
logger.warning(f"Failed to fetch the table with id: {table_id}")
return None

def get_user_details(self, user_id: str) -> Optional[MetabaseUser]:
"""
Get User using user ID
"""
if not user_id:
return None # don't call api if table_id is None
try:
resp_table = self.client.get(f"/user/{user_id}")
if resp_table:
return MetabaseUser(**resp_table)
except Exception:
logger.debug(traceback.format_exc())
logger.warning(f"Failed to fetch the user with id: {user_id}")
return None
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
Markdown,
SourceUrl,
)
from metadata.generated.schema.type.entityReferenceList import EntityReferenceList
from metadata.ingestion.api.models import Either
from metadata.ingestion.api.steps import InvalidSourceException
from metadata.ingestion.lineage.models import ConnectionTypeDialectMapper
Expand Down Expand Up @@ -108,7 +109,9 @@ def get_dashboard_name(self, dashboard: MetabaseDashboard) -> str:
"""
return dashboard.name

def get_dashboard_details(self, dashboard: MetabaseDashboard) -> dict:
def get_dashboard_details(
self, dashboard: MetabaseDashboard
) -> Optional[MetabaseDashboardDetails]:
"""
Get Dashboard Details
"""
Expand Down Expand Up @@ -136,6 +139,24 @@ def get_project_name(self, dashboard_details: Any) -> Optional[str]:
)
return None

def get_owner_ref(
self, dashboard_details: MetabaseDashboardDetails
) -> Optional[EntityReferenceList]:
"""
Get dashboard owner from email
"""
try:
if dashboard_details.creator_id:
owner_details = self.client.get_user_details(
dashboard_details.creator_id
)
if owner_details and owner_details.email:
return self.metadata.get_reference_by_email(owner_details.email)
except Exception as err:
logger.debug(traceback.format_exc())
logger.warning(f"Could not fetch owner data due to {err}")
return None

def yield_dashboard(
self, dashboard_details: MetabaseDashboardDetails
) -> Iterable[Either[CreateDashboardRequest]]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@
MetabaseStrId = Annotated[str, BeforeValidator(lambda x: str(x))]


class MetabaseUser(BaseModel):
"""
Metabase user model
"""

id: MetabaseStrId
first_name: Optional[str] = None
last_name: Optional[str] = None
common_name: Optional[str] = None
email: Optional[str] = None
is_superuser: Optional[bool] = False
last_edit_timestamp: Optional[str] = Field(None, alias="timestamp")


class MetabaseDashboard(BaseModel):
"""
Metabase dashboard model
Expand Down Expand Up @@ -83,6 +97,7 @@ class MetabaseDashboardDetails(BaseModel):
dashcards: List[DashCard]
name: Optional[str] = None
id: MetabaseStrId
creator_id: Optional[MetabaseStrId] = None
collection_id: Optional[MetabaseStrId] = None


Expand Down

0 comments on commit e82a68a

Please sign in to comment.