-
Notifications
You must be signed in to change notification settings - Fork 35
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 client cert support and new action #39
base: master
Are you sure you want to change the base?
Changes from all commits
75d9ea5
49cb1c3
7351498
e39c968
6059581
c7dc409
17e3cc4
5f35b43
cbb9cf3
1f84b00
55c3cd9
ccba2ec
3938171
243a1c4
d08bc9b
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,8 @@ | ||
from lib.base import BaseJiraAction | ||
|
||
__all__ = ["JiraIssueAddWatcherAction"] | ||
|
||
|
||
class JiraIssueAddWatcherAction(BaseJiraAction): | ||
def run(self, issue_key, username): | ||
return self._client.add_watcher(issue_key, username) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
name: add_watcher | ||
runner_type: python-script | ||
description: Add a watcher on a JIRA issue / ticket. | ||
enabled: true | ||
entry_point: add_watcher.py | ||
parameters: | ||
username: | ||
type: string | ||
description: User to add as a watcher. | ||
required: true | ||
issue_key: | ||
type: string | ||
description: Issue key (e.g. PROJECT-1000). | ||
required: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from lib.base import BaseJiraAction | ||
|
||
__all__ = [ | ||
'UpdateReporterValue' | ||
] | ||
|
||
|
||
class UpdateReporterValue(BaseJiraAction): | ||
def run(self, issue_key, username, notify): | ||
issue = self._client.issue(issue_key) | ||
issue.update(reporter={'name': username}, notify=notify) | ||
result = issue.fields.labels | ||
return result |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
name: update_reporter | ||
runner_type: python-script | ||
description: Update the reporter of a particular JIRA issue. | ||
enabled: true | ||
entry_point: update_reporter.py | ||
parameters: | ||
issue_key: | ||
type: string | ||
description: Issue key (e.g. PROJECT-1000). | ||
required: true | ||
username: | ||
type: string | ||
description: the reporter name. | ||
required: true | ||
notify: | ||
type: boolean | ||
description: jira will send notifications (default is true) | ||
default: true | ||
required: false |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,13 +11,14 @@ class JIRASensor(PollingSensor): | |
Sensor will monitor for any new projects created in JIRA and | ||
emit trigger instance when one is created. | ||
''' | ||
|
||
def __init__(self, sensor_service, config=None, poll_interval=5): | ||
super(JIRASensor, self).__init__(sensor_service=sensor_service, | ||
config=config, | ||
poll_interval=poll_interval) | ||
super(JIRASensor, self).__init__(sensor_service=sensor_service, | ||
config=config, | ||
poll_interval=poll_interval) | ||
|
||
self._jira_url = None | ||
# The Consumer Key created while setting up the "Incoming Authentication" in | ||
# The Consumer Key created while setting up the 'Incoming Authentication' in | ||
# JIRA for the Application Link. | ||
self._consumer_key = u'' | ||
self._rsa_key = None | ||
|
@@ -41,29 +42,39 @@ def setup(self): | |
self._jira_url = self._config['url'] | ||
auth_method = self._config['auth_method'] | ||
|
||
options = {'server': self._config['url'], | ||
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. Would like to see unit tests for these new options. 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. I have already added these configurations in test fixtures which is being used my tests to run the test. |
||
'verify': self._config['verify']} | ||
# Getting client cert configuration | ||
cert_file_path = self._config['client_cert_file'] | ||
key_file_path = self._config['client_key_file'] | ||
if cert_file_path and key_file_path: | ||
options['client_cert'] = (cert_file_path, key_file_path) | ||
|
||
if auth_method == 'oauth': | ||
rsa_cert_file = self._config['rsa_cert_file'] | ||
if not os.path.exists(rsa_cert_file): | ||
raise Exception('Cert file for JIRA OAuth not found at %s.' % rsa_cert_file) | ||
raise Exception( | ||
'Cert file for JIRA OAuth not found at %s.' % rsa_cert_file | ||
) | ||
self._rsa_key = self._read_cert(rsa_cert_file) | ||
self._poll_interval = self._config.get('poll_interval', self._poll_interval) | ||
self._poll_interval = self._config.get( | ||
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. More cosmetic changes |
||
'poll_interval', self._poll_interval) | ||
oauth_creds = { | ||
'access_token': self._config['oauth_token'], | ||
'access_token_secret': self._config['oauth_secret'], | ||
'consumer_key': self._config['consumer_key'], | ||
'key_cert': self._rsa_key | ||
'key_cert': self._rsa_key, | ||
} | ||
|
||
self._jira_client = JIRA(options={'server': self._jira_url}, | ||
oauth=oauth_creds) | ||
self._jira_client = JIRA(options=options, oauth=oauth_creds) | ||
elif auth_method == 'basic': | ||
basic_creds = (self._config['username'], self._config['password']) | ||
self._jira_client = JIRA(options={'server': self._jira_url}, | ||
basic_auth=basic_creds) | ||
self._jira_client = JIRA(options=options, basic_auth=basic_creds) | ||
|
||
else: | ||
msg = ('You must set auth_method to either "oauth"', | ||
'or "basic" your jira.yaml config file.') | ||
'or "basic" your jira.yaml config file.', | ||
) | ||
raise Exception(msg) | ||
|
||
if self._projects_available is None: | ||
|
@@ -74,7 +85,8 @@ def setup(self): | |
if not self._project or self._project not in self._projects_available: | ||
raise Exception('Invalid project (%s) to track.' % self._project) | ||
self._jql_query = 'project=%s' % self._project | ||
all_issues = self._jira_client.search_issues(self._jql_query, maxResults=None) | ||
all_issues = self._jira_client.search_issues( | ||
self._jql_query, maxResults=None) | ||
self._issues_in_project = {issue.key: issue for issue in all_issues} | ||
|
||
def poll(self): | ||
|
@@ -93,7 +105,9 @@ def remove_trigger(self, trigger): | |
pass | ||
|
||
def _detect_new_issues(self): | ||
new_issues = self._jira_client.search_issues(self._jql_query, maxResults=50, startAt=0) | ||
new_issues = self._jira_client.search_issues( | ||
self._jql_query, maxResults=50, startAt=0 | ||
) | ||
|
||
for issue in new_issues: | ||
if issue.key not in self._issues_in_project: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ | |
poll_interval: 30 | ||
project: "MY_PROJECT" | ||
verify: True | ||
|
||
client_cert_file: "" | ||
client_key_file: "" |
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.
Would like to see unit tests for these new actions.
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 don't see unit tests for individual action that are already existing. could you please help me understanding, what are you expecting from those unit tests, since most of these actions are connecting to JIRA API and returning result ?