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
Add connection credentials #80
Changes from 4 commits
f140f8a
6544117
b6121d1
c4f2ebc
c2f697b
011a73a
be85635
8d13cf4
5f25ef9
82e84a3
c4d6cee
ab478dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ConnectionCredentials(object): | ||
def __init__(self, name, password, embed=True): | ||
self.password = password | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Reorder these to match the order in the function signature There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if I fix order of property set in credentials do you want me to fix auth while I am doing it as I copied the code for this class from auth. New code would be
|
||
self.embed = embed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make this an explicit property and add the property_is_boolean decorator |
||
self.name = name |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,12 +30,17 @@ def signin_req(self, auth_item): | |
|
||
|
||
class DatasourceRequest(object): | ||
def _generate_xml(self, datasource_item): | ||
def _generate_xml(self, datasource_item, connection_credentials=None): | ||
xml_request = ET.Element('tsRequest') | ||
datasource_element = ET.SubElement(xml_request, 'datasource') | ||
datasource_element.attrib['name'] = datasource_item.name | ||
project_element = ET.SubElement(datasource_element, 'project') | ||
project_element.attrib['id'] = datasource_item.project_id | ||
if connection_credentials: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (not a shipblocker) |
||
credentials_element = ET.SubElement(datasource_element, 'connectionCredentials') | ||
credentials_element.attrib['name'] = connection_credentials.name | ||
credentials_element.attrib['password'] = connection_credentials.password | ||
credentials_element.attrib['embed'] = str(connection_credentials.embed).lower() | ||
return ET.tostring(xml_request) | ||
|
||
def update_req(self, datasource_item): | ||
|
@@ -49,15 +54,15 @@ def update_req(self, datasource_item): | |
owner_element.attrib['id'] = datasource_item.owner_id | ||
return ET.tostring(xml_request) | ||
|
||
def publish_req(self, datasource_item, filename, file_contents): | ||
xml_request = self._generate_xml(datasource_item) | ||
def publish_req(self, datasource_item, filename, file_contents, connection_credentials=None): | ||
xml_request = self._generate_xml(datasource_item, connection_credentials) | ||
|
||
parts = {'request_payload': ('', xml_request, 'text/xml'), | ||
'tableau_datasource': (filename, file_contents, 'application/octet-stream')} | ||
return _add_multipart(parts) | ||
|
||
def publish_req_chunked(self, datasource_item): | ||
xml_request = self._generate_xml(datasource_item) | ||
def publish_req_chunked(self, datasource_item, connection_credentials=None): | ||
xml_request = self._generate_xml(datasource_item, connection_credentials) | ||
|
||
parts = {'request_payload': ('', xml_request, 'text/xml')} | ||
return _add_multipart(parts) | ||
|
@@ -260,14 +265,19 @@ def add_req(self, user_item): | |
|
||
|
||
class WorkbookRequest(object): | ||
def _generate_xml(self, workbook_item): | ||
def _generate_xml(self, workbook_item, connection_credentials=None): | ||
xml_request = ET.Element('tsRequest') | ||
workbook_element = ET.SubElement(xml_request, 'workbook') | ||
workbook_element.attrib['name'] = workbook_item.name | ||
if workbook_item.show_tabs: | ||
workbook_element.attrib['showTabs'] = str(workbook_item.show_tabs).lower() | ||
project_element = ET.SubElement(workbook_element, 'project') | ||
project_element.attrib['id'] = workbook_item.project_id | ||
if connection_credentials: | ||
credentials_element = ET.SubElement(workbook_element, 'connectionCredentials') | ||
credentials_element.attrib['name'] = connection_credentials.name | ||
credentials_element.attrib['password'] = connection_credentials.password | ||
credentials_element.attrib['embed'] = str(connection_credentials.embed).lower() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you do a more explicit assignment instead of relying on str(True).lower() == 'true'? credentials_element.attrib['embed'] = 'true' if connection_credentials.embed else 'false' Or even more explicit if connection_credentials.embed:
credentials_element.attrib['embed'] = 'true'
else:
credentials_element.attrib['embed'] = 'false' |
||
return ET.tostring(xml_request) | ||
|
||
def update_req(self, workbook_item): | ||
|
@@ -283,15 +293,15 @@ def update_req(self, workbook_item): | |
owner_element.attrib['id'] = workbook_item.owner_id | ||
return ET.tostring(xml_request) | ||
|
||
def publish_req(self, workbook_item, filename, file_contents): | ||
xml_request = self._generate_xml(workbook_item) | ||
def publish_req(self, workbook_item, filename, file_contents, connection_credentials=None): | ||
xml_request = self._generate_xml(workbook_item, connection_credentials) | ||
|
||
parts = {'request_payload': ('', xml_request, 'text/xml'), | ||
'tableau_workbook': (filename, file_contents, 'application/octet-stream')} | ||
return _add_multipart(parts) | ||
|
||
def publish_req_chunked(self, workbook_item): | ||
xml_request = self._generate_xml(workbook_item) | ||
def publish_req_chunked(self, workbook_item, connection_credentials=None): | ||
xml_request = self._generate_xml(workbook_item, connection_credentials) | ||
|
||
parts = {'request_payload': ('', xml_request, 'text/xml')} | ||
return _add_multipart(parts) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a docstring on this class that tells users they should delete this object when they're done using it?