-
Notifications
You must be signed in to change notification settings - Fork 446
#1 moved auth parsing to signin method #5
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
Changes from all commits
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 |
|---|---|---|
| @@ -1,19 +1,6 @@ | ||
| import xml.etree.ElementTree as ET | ||
| from .. import NAMESPACE | ||
|
|
||
|
|
||
| class TableauAuth(object): | ||
| def __init__(self, username, password, site='', impersonate_id=None): | ||
| # CHECK FOR USERNAME AND PASSWORD | ||
| def __init__(self, username, password, site='', user_id_to_impersonate=None): | ||
| self.user_id_to_impersonate = user_id_to_impersonate | ||
| self.password = password | ||
| self.username = username | ||
| self.site = site | ||
| self.impersonate_id = impersonate_id | ||
|
|
||
| @staticmethod | ||
| def from_response(parent_srv, resp): | ||
| parsed_response = ET.fromstring(resp) | ||
| parent_srv._site_id = parsed_response.find('.//t:site', namespaces=NAMESPACE).get('id', None) | ||
| parent_srv._user_id = parsed_response.find('.//t:user', namespaces=NAMESPACE).get('id', None) | ||
| auth_token = parsed_response.find('t:credentials', namespaces=NAMESPACE).get('token', None) | ||
| parent_srv._auth_token = auth_token | ||
| self.username = username |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| from endpoint import Endpoint | ||
| from .. import RequestFactory, TableauAuth | ||
| from .. import RequestFactory, NAMESPACE | ||
| import xml.etree.ElementTree as ET | ||
| import logging | ||
|
|
||
| logger = logging.getLogger('tableau.endpoint.auth') | ||
|
|
@@ -27,7 +28,11 @@ def sign_in(self, auth_req): | |
| server_response = self.parent_srv.session.post(url, data=signin_req, | ||
| **self.parent_srv.http_options) | ||
| Endpoint._check_status(server_response) | ||
| TableauAuth.from_response(self.parent_srv, server_response.text) | ||
| parsed_response = ET.fromstring(server_response.text) | ||
| site_id = parsed_response.find('.//t:site', namespaces=NAMESPACE).get('id', None) | ||
| user_id = parsed_response.find('.//t:user', namespaces=NAMESPACE).get('id', None) | ||
| auth_token = parsed_response.find('t:credentials', namespaces=NAMESPACE).get('token', None) | ||
| self.parent_srv._set_auth(site_id, user_id, auth_token) | ||
|
Collaborator
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. Mostly style, but if this is getting called from outside the class/module, maybe it isn't really 'private' and doesn't need the '_' prefix.
Contributor
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. Our convention is any function call that is not intended for users to use should start with
Contributor
Author
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. Users can access the endpoints through the server class. Is that what you're asking?
Collaborator
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. Makes sense -- I do like the convention, wasn't sure if it was supposed to be user-facing or not.
Contributor
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. @shinchris That's exactly what I was asking :) I thought that was the case, but couldn't remember off the top of my head. 🚀 🚀 🚀 |
||
| logger.info('Signed into {0} as {1}'.format(self.parent_srv.server_address, auth_req.username)) | ||
| return Auth.contextmgr(self.sign_out) | ||
|
|
||
|
|
||
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.
I think there might be a subtle unicode bug here?
What happens if Server.text contains Chinese characters (Say as the username or something) -- I can't remember if ET.fromstring is graceful about it. If so, it's good!