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

Add API Token authentication #20

Merged
merged 7 commits into from
Oct 2, 2018

Conversation

micaelbergeron
Copy link
Contributor

@micaelbergeron micaelbergeron commented Sep 27, 2018

This PR add the configuration options to either auth using OAuth (current behavior) or API Tokens as Zenpy supports both configurations.

mbergeron and others added 4 commits September 27, 2018 10:18
new configuration options:

  'email': the account's email
  'api_token': the account's api token
Copy link
Contributor

@timvisher timvisher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the overall addition here.

Can you provide some gists of runs with the different configurations and address some of the specific comments I left? Preferably with redacted cats of the config files for each run?

tap_zendesk/__init__.py Outdated Show resolved Hide resolved
tap_zendesk/__init__.py Show resolved Hide resolved
creds.update({
"oauth_token": oauth_args.config['access_token'],
})
except:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this and the other except: handle a more specific error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will do.

@micaelbergeron
Copy link
Contributor Author

Thanks for the comments, I'll fix the issues and provide a sample config/runs for you shortly.

mbergeron added 2 commits October 1, 2018 11:56
  - add INFO log for the used auth
  - fixed bare except: clauses
  - make sure the OAuth has precedence
@micaelbergeron
Copy link
Contributor Author

@timvisher I think I solved most issues, please do another review.

Here's a gist of runs: https://gist.github.com/micaelbergeron/50493d87ba711389143fcda3645ed88a

Copy link
Contributor

@timvisher timvisher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good.

I'd like to see a bit more documentation and slightly different structure to the auth calls. Also I really don't want to catch Exception.

README.md Show resolved Hide resolved
"access_token"
]

API_CONFIG_KEYS = REQUIRED_CONFIG_KEYS + [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a similar comment here about the mutual exclusivity and preference ordering of these two config sections would be nice.

return client
except ZenpyException:
LOGGER.error("OAuth authentication failed.")
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a ValueError or other kind of specific exception? Could we not catch Exception here by just checking if the args contain a particular key?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parse_args will raise an Exception (see https://github.com/singer-io/singer-python/blob/dfad8fc467704900e0f268a05919bd34976aaa0e/singer/utils.py#L150) if the required_keys are not present.

So we can't use parse_args to validate that the config is there without catching an Exception when the config is not there.

I'll do the check manually then.

tap_zendesk/__init__.py Outdated Show resolved Hide resolved
  - add some documentation
  - wording
  - remove dead code, Zenpy doens't raise on failed authentication
@micaelbergeron
Copy link
Contributor Author

micaelbergeron commented Oct 1, 2018

@timvisher I think this is ready for another review. Thanks for your help :D

Here's the new output:

Using OAuth

(tap-zendesk.venv) ❯ tap-zendesk -c tap-zendesk/config.json
INFO Using OAuth authentication.

Using API Token

(tap-zendesk.venv) ❯ tap-zendesk -c tap-zendesk/config.json
INFO Using API Token authentication.

When something is wrong

(tap-zendesk.venv) ❯ tap-zendesk -c tap-zendesk/config.json
ERROR No suitable authentication keys provided.
  OAuth:		access_token
  API Token:		email, api_token

I've removed the ZenpyException because it seems it doesn't raise any of these when the client is constructed anyways.

@nick-mccoy
Copy link
Contributor

👍Merging this -- thanks for contributing @micaelbergeron!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants