-
Notifications
You must be signed in to change notification settings - Fork 284
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 support for jira authentication via Personal Access Token #750
Conversation
Thanks for your contribution. The existing unit tests are failing due to these changes so I cannot merge this PR as-is. |
I need to change the test code |
thanks for chiming in. Unfortunately, my knowledge about python mock tests is next to zero. I don't even know if my change broke existing functionality, or only the tests would need to be adapted. thanks, |
I'm worried that I'm getting an error even though I haven't changed the jira test. |
Do not allow the merge. |
I think that it is not the problem that the test of api_key is not added, but the problem that the test without api_key is failed. |
Hey @buzzdeee - you have two problems with your change which are making the unit tests fail. The first is that the logic of your conditional is incorrect. Let's assume I defined my Jira account file as Looking at your conditional in this case, we have:
so now we have I'll leave it to you to work out what the correct conditional format should be. There's another error after that: Overall, regarding your PR I think you should reimplement the |
Hi @ferozsalam thanks for the explanations of my logic error. I only could test the api_key version, as that's the type of Jira server I've around, and that case just worked for me. Also thanks for the suggestion regarding overriding get_account in jira.py, I'll look into that. |
97286dc
to
4a211e2
Compare
Nicely done on getting the tests to work 👍 Are you able to add a unit test to check that if an API key alone is defined, things work as expected? This would be very similar to the existing Jira tests. |
Hi, updated version now with tests passing:
Additionally, I tested with a config file:
As I understand my code, the apikey takes precedence. So if apikey is combined with user or password or both in the authentication file, it will try to use the apikey, without falling back to user/password in case that doesn't work. hope that's fine/fair enough ;) |
fc896c1
to
337b28e
Compare
337b28e
to
fb6b082
Compare
now there should be a test at the end of jira_test.py. |
elastalert/alerters/jira.py
Outdated
@@ -103,7 +103,10 @@ def __init__(self, rule): | |||
self.reset_jira_args() | |||
|
|||
try: | |||
self.client = JIRA(self.server, basic_auth=(self.user, self.password)) | |||
if self.apikey: |
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.
If user and password are specified, the value of self.apiKey will not be set, so if you pass "if self.apiKey:" in that state, an error will occur. I think that will happen. I thought it would be better to do "self.apikey = None" before calling the overridden get_account.
Description
For Jira instances, that have basic-auth disabled, a Personal Access Token can be used.
This change allows to make use of such PAT.
Checklist
make test-docker
with my changes.Questions or Comments
The reading of the jira_account.yaml file seems to be shared with the smtp alerter, but the change shouldn't affect it. I'm not good with writing python tests, therefore no tests added.