-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 23 additions & 19 deletions
42
metadata-ingestion/src/datahub/ingestion/source/tableau/tableau_server_wrapper.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
from dataclasses import dataclass | ||
|
||
from tableauserverclient import Server, UserItem | ||
|
||
from datahub.ingestion.source.tableau import tableau_constant as c | ||
|
||
|
||
@dataclass | ||
class LoggedInUser: | ||
user: UserItem | ||
_site_id: str | ||
|
||
def __init__(self, site_id: str, user_item: UserItem): | ||
self.user = user_item | ||
self._site_id = site_id | ||
|
||
def site_role(self) -> str: | ||
assert self.user.site_role, "site_role is not available" # to silent the lint | ||
return self.user.site_role | ||
|
||
def user_name(self) -> str: | ||
assert self.user.name, "user name is not available" # to silent the lint | ||
return self.user.name | ||
|
||
def site_id(self) -> str: | ||
return self._site_id | ||
user_name: str | ||
site_role: str | ||
site_id: str | ||
|
||
def is_site_administrator_explorer(self): | ||
return self.user.site_role == c.SITE_ROLE | ||
return self.site_role == c.SITE_ROLE | ||
|
||
|
||
class UserSiteInfo: | ||
@staticmethod | ||
def from_server(server: Server) -> "LoggedInUser": | ||
assert server.user_id, "make the connection with tableau" | ||
return LoggedInUser(server.site_id, server.users.get_by_id(server.user_id)) | ||
|
||
user: UserItem = server.users.get_by_id(server.user_id) | ||
|
||
assert user.site_role, "site_role is not available" # to silent the lint | ||
|
||
assert user.name, "user name is not available" # to silent the lint | ||
|
||
assert server.site_id, "site identifier is not available" # to silent the lint | ||
|
||
return LoggedInUser( | ||
user_name=user.name, | ||
site_role=user.site_role, | ||
site_id=server.site_id, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters