Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticate tableau with personal access token #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
TABLEAU_URL=https://mytableauserver.company.com # without a trailling slash
TABLEAU_USERNAME=some_username
TABLEAU_PASSWORD=some_password
TABLEAU_PASSWORD=some_password
TABLEAU_TOKEN_NAME=your_pat_name
TABLEAU_TOKEN_VALUE=tokens_private_value
19 changes: 13 additions & 6 deletions src/exposurescrawler/crawlers/tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _should_ignore_workbook(workbook, projects_to_ignore: Collection[str]) -> bo
# by workbooks under projects without a name.
if not workbook.project_name:
return True

return workbook.project_name in projects_to_ignore


Expand Down Expand Up @@ -87,11 +87,18 @@ def tableau_crawler(
models = manifest.retrieve_models_and_sources()

# Configure the Tableau REST client
tableau_client = TableauRestClient(
os.environ['TABLEAU_URL'],
os.environ['TABLEAU_USERNAME'],
os.environ['TABLEAU_PASSWORD'],
)
if 'TABLEAU_USERNAME' in os.environ and 'TABLEAU_PASSWORD' in os.environ:
tableau_client = TableauRestClient.config_user_and_password(
os.environ['TABLEAU_URL'],
os.environ['TABLEAU_USERNAME'],
os.environ['TABLEAU_PASSWORD'],
)
else:
tableau_client = TableauRestClient.config_token(
os.environ['TABLEAU_URL'],
os.environ['TABLEAU_TOKEN_NAME'],
os.environ['TABLEAU_TOKEN_VALUE'],
)

# Retrieve custom SQLs and find model references
workbooks_custom_sqls = retrieve_custom_sql(tableau_client, 'snowflake')
Expand Down
21 changes: 19 additions & 2 deletions src/exposurescrawler/tableau/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,29 @@
class TableauRestClient:
"""
Thin wrapper around the official Tableau Server client.
Initialized with user+passw or access token
"""

def __init__(self, url: str, username: str, password: str):
self.tableau_auth = TSC.TableauAuth(username, password)
def __init__(self, url: str):
self.url = url
self.server = TSC.Server(url, use_server_version=True)

@classmethod
def config_user_and_password(cls, url: str, username: str, password: str):
# Specific initialization to tableau server via user and password
tableau_cls = cls(url=url)
tableau_cls.tableau_auth = TSC.TableauAuth(username, password)

return tableau_cls

@classmethod
def config_token(cls, url: str, token_name: str, token_value: str):
# Specific initialization to tableau server via access token
tableau_cls = cls(url=url)
tableau_cls.tableau_auth = TSC.PersonalAccessTokenAuth(token_name, token_value)

return tableau_cls

@lru_cache(maxsize=None)
def retrieve_workbook(self, workbook_id: str):
with self.server.auth.sign_in(self.tableau_auth):
Expand Down