-
Notifications
You must be signed in to change notification settings - Fork 447
Expand file tree
/
Copy pathtableau_auth.py
More file actions
70 lines (55 loc) · 2.3 KB
/
tableau_auth.py
File metadata and controls
70 lines (55 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class Credentials:
def __init__(self, site_id=None, user_id_to_impersonate=None):
self.site_id = site_id or ""
self.user_id_to_impersonate = user_id_to_impersonate or None
@property
def credentials(self):
credentials = "Credentials can be username/password, Personal Access Token, or JWT"
+"This method returns values to set as an attribute on the credentials element of the request"
def __repr__(self):
return "All Credentials types must have a debug display that does not print secrets"
def deprecate_site_attribute():
import warnings
warnings.warn(
"TableauAuth(..., site=...) is deprecated, " "please use TableauAuth(..., site_id=...) instead.",
DeprecationWarning,
)
# The traditional auth type: username/password
class TableauAuth(Credentials):
def __init__(self, username, password, site=None, site_id=None, user_id_to_impersonate=None):
if site is not None:
deprecate_site_attribute()
site_id = site
super().__init__(site_id, user_id_to_impersonate)
if password is None:
raise TabError("Must provide a password when using traditional authentication")
self.password = password
self.username = username
@property
def credentials(self):
return {"name": self.username, "password": self.password}
def __repr__(self):
return "<Credentials username={} password={}>".format(self.username, "<redacted>")
@property
def site(self):
deprecate_site_attribute()
return self.site_id
@site.setter
def site(self, value):
deprecate_site_attribute()
self.site_id = value
class PersonalAccessTokenAuth(Credentials):
def __init__(self, token_name, personal_access_token, site_id=None):
super().__init__(site_id=site_id)
self.token_name = token_name
self.personal_access_token = personal_access_token
@property
def credentials(self):
return {
"personalAccessTokenName": self.token_name,
"personalAccessTokenSecret": self.personal_access_token,
}
def __repr__(self):
return "<PersonalAccessToken name={} token={} site={}>".format(
self.token_name, self.personal_access_token[:2] + "...", self.site_id
)