From da7273a19043e6b309d5384c1cbaedde47b050ce Mon Sep 17 00:00:00 2001 From: pdenning Date: Thu, 13 Dec 2018 10:19:22 +1100 Subject: [PATCH 01/15] adding multi Jira profiles --- actions/lib/base.py | 67 ++++++++++++++++++++++++++----- actions/search_issues.py | 5 ++- actions/search_issues.yaml | 4 ++ config.schema.yaml | 81 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 10 deletions(-) diff --git a/actions/lib/base.py b/actions/lib/base.py index f04de4a..043b018 100755 --- a/actions/lib/base.py +++ b/actions/lib/base.py @@ -14,30 +14,42 @@ def __init__(self, config): class BaseJiraAction(Action): def __init__(self, config): super(BaseJiraAction, self).__init__(config=config) - self._client = self._get_client() + #self._client = self._get_client() - def _get_client(self): + def _get_client(self,profile=None): config = self.config + profile_name = profile + default_profile = config.get('default_profile', None) - options = {'server': config['url'], 'verify': config['verify']} + if profile_name is None and default_profile is None: + profile_name = "inline" + elif profile_name is None and len(default_profile) > 0: + profile_name = default_profile + else + profile_name = profile - auth_method = config['auth_method'] + profile = self._build_profile(profile_name) + + + options = {'server': profile['url'], 'verify': profile['verify']} + + auth_method = profile['auth_method'] if auth_method == 'oauth': - rsa_cert_file = config['rsa_cert_file'] + rsa_cert_file = profile['rsa_cert_file'] rsa_key_content = self._get_file_content(file_path=rsa_cert_file) oauth_creds = { - 'access_token': config['oauth_token'], - 'access_token_secret': config['oauth_secret'], - 'consumer_key': config['consumer_key'], + 'access_token': profile['oauth_token'], + 'access_token_secret': profile['oauth_secret'], + 'consumer_key': profile['consumer_key'], 'key_cert': rsa_key_content } client = JIRA(options=options, oauth=oauth_creds) elif auth_method == 'basic': - basic_creds = (config['username'], config['password']) + basic_creds = (profile['username'], profile['password']) client = JIRA(options=options, basic_auth=basic_creds) else: @@ -47,6 +59,43 @@ def _get_client(self): return client + def _build_profile(self, profile) + conf = self.config + profile = {} + + if profile == "inline".lower(): + profile['server'] = config['server'] + profile['verify'] = config['verify'] + profile['auth_method'] = config['auth_method'] + profile['rsa_cert_file'] = config['rsa_cert_file'] + profile['oauth_token'] = config['oauth_token'] + profile['oauth_secret'] = config['oauth_secret'] + profile['consumer_key'] = config['consumer_key'] + profile['username'] = config['username'] + profile['password'] = config['password'] + else: + if 'profiles' in config and len(config['profiles']) > 0: + for profile_cfg in config['profiles']: + if profile_cfg['name'].lower() == profile.lower(): + profile['server'] = profile_cfg['server'] + profile['verify'] = profile_cfg['verify'] + profile['auth_method'] = profile_cfg['auth_method'] + profile['rsa_cert_file'] = profile_cfg['rsa_cert_file'] + profile['oauth_token'] = profile_cfg['oauth_token'] + profile['oauth_secret'] = profile_cfg['oauth_secret'] + profile['consumer_key'] = profile_cfg['consumer_key'] + profile['username'] = profile_cfg['username'] + profile['password'] = profile_cfg['password'] + break + else: + msg = ('No configuration file called: %s found. Please check your config file' % profile) + + if len(profile.items()) == 0: + msg = ('No configuration profile found. Please check your config file for the profile you have specified.') + raise Exception(msg) + + return profile + def _get_file_content(self, file_path): with open(file_path, 'r') as fp: content = fp.read() diff --git a/actions/search_issues.py b/actions/search_issues.py index 668377e..4eb6bf1 100755 --- a/actions/search_issues.py +++ b/actions/search_issues.py @@ -9,7 +9,10 @@ class SearchJiraIssuesAction(BaseJiraAction): def run(self, query, start_at=0, max_results=50, include_comments=False, include_attachments=False, - include_customfields=False): + include_customfields=False, config_profile=None): + + self._client = self._get_client(config_profile) + issues = self._client.search_issues(query, startAt=start_at, maxResults=max_results) results = [] diff --git a/actions/search_issues.yaml b/actions/search_issues.yaml index 4e46d93..3b3aa41 100755 --- a/actions/search_issues.yaml +++ b/actions/search_issues.yaml @@ -34,3 +34,7 @@ parameters: description: True to include custom fields. required: true default: false + config_profile: + type: string + description: Select which jira config profile to use. + required: false diff --git a/config.schema.yaml b/config.schema.yaml index 27c9748..4052d28 100755 --- a/config.schema.yaml +++ b/config.schema.yaml @@ -58,3 +58,84 @@ type: "string" secret: false required: true + default_profile: + description: "Select which profile will be default. If left blank will use the standard Jira connection details" + type: "string" + secret: false + required: false + profiles: + description: "Jira Connection profile." + type: "array" + required: false + items: + type: "object" + required: false + additionalProperties: false + properties: + name: + description: "Name of the profile" + type: "string" + secret: false + reqiured: true + url: + description: "URL of the JIRA instance (e.g. ``https://myproject.atlassian.net``)" + type: "string" + secret: false + required: true + verify: + description: "Verify SSL certificate. Set to False to disable verification. Default True" + type: boolean + default: True + auth_method: + description: "Authentication method to use - oauth or basic" + type: "string" + secret: false + required: true + default: "oauth" + enum: + - oauth + - basic + username: + description: "Username if using the basic auth_method" + type: "string" + secret: false + required: false + password: + description: "Password if using the basic auth_method" + type: "string" + secret: true + required: false + rsa_cert_file: + description: "Path to a private key file, e.g. /home/vagrant/jira.pem" + type: "string" + secret: false + required: false + oauth_token: + description: "OAuth token" + type: "string" + secret: true + required: false + oauth_secret: + description: "OAuth secret" + type: "string" + secret: true + required: false + consumer_key: + description: "Consumer key" + type: "string" + secret: true + required: false + poll_interval: + description: "Polling interval - default 30s" + type: "integer" + secret: false + required: false + default: 30 + project: + description: "Project to be used as default for actions that don't require or allow a project" + type: "string" + secret: false + required: true + + + From a0c8d49cbda92ee508242275d12155132762888a Mon Sep 17 00:00:00 2001 From: pdenning Date: Thu, 13 Dec 2018 10:40:46 +1100 Subject: [PATCH 02/15] fixed issues with default profile --- actions/lib/base.py | 49 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/actions/lib/base.py b/actions/lib/base.py index 043b018..759f720 100755 --- a/actions/lib/base.py +++ b/actions/lib/base.py @@ -19,13 +19,14 @@ def __init__(self, config): def _get_client(self,profile=None): config = self.config profile_name = profile + default_profile = config.get('default_profile', None) if profile_name is None and default_profile is None: profile_name = "inline" elif profile_name is None and len(default_profile) > 0: profile_name = default_profile - else + else: profile_name = profile profile = self._build_profile(profile_name) @@ -59,37 +60,37 @@ def _get_client(self,profile=None): return client - def _build_profile(self, profile) - conf = self.config + def _build_profile(self, profile_name): + config = self.config profile = {} - if profile == "inline".lower(): - profile['server'] = config['server'] - profile['verify'] = config['verify'] - profile['auth_method'] = config['auth_method'] - profile['rsa_cert_file'] = config['rsa_cert_file'] - profile['oauth_token'] = config['oauth_token'] - profile['oauth_secret'] = config['oauth_secret'] - profile['consumer_key'] = config['consumer_key'] - profile['username'] = config['username'] - profile['password'] = config['password'] + if profile_name == "inline".lower(): + profile['url'] = config.get('url') + profile['verify'] = config.get('verify') + profile['auth_method'] = config.get('auth_method') + profile['rsa_cert_file'] = config.get('rsa_cert_file') + profile['oauth_token'] = config.get('oauth_token') + profile['oauth_secret'] = config.get('oauth_secret') + profile['consumer_key'] = config.get('consumer_key') + profile['username'] = config.get('username') + profile['password'] = config.get('password') else: if 'profiles' in config and len(config['profiles']) > 0: for profile_cfg in config['profiles']: - if profile_cfg['name'].lower() == profile.lower(): - profile['server'] = profile_cfg['server'] - profile['verify'] = profile_cfg['verify'] - profile['auth_method'] = profile_cfg['auth_method'] - profile['rsa_cert_file'] = profile_cfg['rsa_cert_file'] - profile['oauth_token'] = profile_cfg['oauth_token'] - profile['oauth_secret'] = profile_cfg['oauth_secret'] - profile['consumer_key'] = profile_cfg['consumer_key'] - profile['username'] = profile_cfg['username'] - profile['password'] = profile_cfg['password'] + if profile_cfg['name'].lower() == profile_name.lower(): + profile['url'] = profile_cfg.get('url') + profile['verify'] = profile_cfg.get('verify') + profile['auth_method'] = profile_cfg.get('auth_method') + profile['rsa_cert_file'] = profile_cfg.get('rsa_cert_file') + profile['oauth_token'] = profile_cfg.get('oauth_token') + profile['oauth_secret'] = profile_cfg.get('oauth_secret') + profile['consumer_key'] = profile_cfg.get('consumer_key') + profile['username'] = profile_cfg.get('username') + profile['password'] = profile_cfg.get('password') break else: msg = ('No configuration file called: %s found. Please check your config file' % profile) - + if len(profile.items()) == 0: msg = ('No configuration profile found. Please check your config file for the profile you have specified.') raise Exception(msg) From 536e08d085db36bf5d3f8f001b437def9d31a06a Mon Sep 17 00:00:00 2001 From: pdenning Date: Thu, 13 Dec 2018 11:29:08 +1100 Subject: [PATCH 03/15] Added profiles to all actions --- actions/attach_file_to_issue.py | 6 +++++- actions/attach_file_to_issue.yaml | 4 ++++ actions/attach_files_to_issue.py | 5 ++++- actions/attach_files_to_issue.yaml | 4 ++++ actions/comment_issue.py | 6 +++++- actions/comment_issue.yaml | 4 ++++ actions/create_issue.py | 6 +++++- actions/create_issue.yaml | 4 ++++ actions/get_issue.py | 6 +++++- actions/get_issue.yaml | 4 ++++ actions/get_issue_attachments.py | 6 +++++- actions/get_issue_attachments.yaml | 5 +++++ actions/get_issue_comments.py | 6 +++++- actions/get_issue_comments.yaml | 4 ++++ actions/lib/base.py | 7 +++++-- actions/search_issues.py | 3 ++- actions/transition_issue.py | 6 +++++- actions/transition_issue.yaml | 4 ++++ config.schema.yaml | 6 +++--- 19 files changed, 82 insertions(+), 14 deletions(-) diff --git a/actions/attach_file_to_issue.py b/actions/attach_file_to_issue.py index f3158f4..7d173ec 100644 --- a/actions/attach_file_to_issue.py +++ b/actions/attach_file_to_issue.py @@ -7,7 +7,11 @@ class AttachFileToJiraIssueAction(BaseJiraAction): - def run(self, issue_key, file_path, file_name=None): + def run(self, issue_key, file_path, file_name=None, config_profile=None): + + if config_profile: + self._client = self._get_client(config_profile) + if not file_name: file_name = None diff --git a/actions/attach_file_to_issue.yaml b/actions/attach_file_to_issue.yaml index 1292338..471c9e2 100644 --- a/actions/attach_file_to_issue.yaml +++ b/actions/attach_file_to_issue.yaml @@ -17,3 +17,7 @@ parameters: type: string description: Issue key (e.g. PROJECT-1000). required: true + config_profile: + type: string + description: Select which jira config profile to use. + required: false diff --git a/actions/attach_files_to_issue.py b/actions/attach_files_to_issue.py index 9bed646..cf158f7 100644 --- a/actions/attach_files_to_issue.py +++ b/actions/attach_files_to_issue.py @@ -7,9 +7,12 @@ class AttachFilesToJiraIssueAction(BaseJiraAction): - def run(self, issue_key, file_paths): + def run(self, issue_key, file_paths,config_profile=None): result = [] + if config_profile: + self._client = self._get_client(config_profile) + for file_path in file_paths: with open(file_path, 'rb') as fp: attachment = self._client.add_attachment( diff --git a/actions/attach_files_to_issue.yaml b/actions/attach_files_to_issue.yaml index ce03189..da390d3 100644 --- a/actions/attach_files_to_issue.yaml +++ b/actions/attach_files_to_issue.yaml @@ -15,3 +15,7 @@ parameters: type: string description: Issue key (e.g. PROJECT-1000). required: true + config_profile: + type: string + description: Select which jira config profile to use. + required: false diff --git a/actions/comment_issue.py b/actions/comment_issue.py index ff8d7ee..2d87ed3 100755 --- a/actions/comment_issue.py +++ b/actions/comment_issue.py @@ -8,7 +8,11 @@ class CommentJiraIssueAction(BaseJiraAction): - def run(self, issue_key, comment_text): + def run(self, issue_key, comment_text, config_profile=None): + + if config_profile: + self._client = self._get_client(config_profile) + comment = self._client.add_comment(issue_key, comment_text) result = to_comment_dict(comment) return result diff --git a/actions/comment_issue.yaml b/actions/comment_issue.yaml index a56d19b..9aa55ea 100755 --- a/actions/comment_issue.yaml +++ b/actions/comment_issue.yaml @@ -13,3 +13,7 @@ parameters: type: string description: Issue key (e.g. PROJECT-1000). required: true + config_profile: + type: string + description: Select which jira config profile to use. + required: false \ No newline at end of file diff --git a/actions/create_issue.py b/actions/create_issue.py index 94d1f3c..b420d04 100755 --- a/actions/create_issue.py +++ b/actions/create_issue.py @@ -9,7 +9,11 @@ class CreateJiraIssueAction(BaseJiraAction): def run(self, summary, type, description=None, - project=None, extra_fields=None): + project=None, extra_fields=None,config_profile=None): + + if config_profile: + self._client = self._get_client(config_profile) + project = project or self.config['project'] data = { 'project': {'key': project}, diff --git a/actions/create_issue.yaml b/actions/create_issue.yaml index 5b9a505..051cd16 100755 --- a/actions/create_issue.yaml +++ b/actions/create_issue.yaml @@ -26,3 +26,7 @@ parameters: type: object description: "extra fields like priority, labels, custom fields, etc" required: false + config_profile: + type: string + description: Select which jira config profile to use. + required: false diff --git a/actions/get_issue.py b/actions/get_issue.py index b2a2091..d7d37f3 100755 --- a/actions/get_issue.py +++ b/actions/get_issue.py @@ -8,7 +8,11 @@ class GetJiraIssueAction(BaseJiraAction): def run(self, issue_key, include_comments=False, include_attachments=False, - include_customfields=False): + include_customfields=False, config_profile=None): + + if config_profile: + self._client = self._get_client(config_profile) + issue = self._client.issue(issue_key) result = to_issue_dict(issue=issue, include_comments=include_comments, include_attachments=include_attachments, diff --git a/actions/get_issue.yaml b/actions/get_issue.yaml index f227d51..edefe38 100755 --- a/actions/get_issue.yaml +++ b/actions/get_issue.yaml @@ -24,3 +24,7 @@ parameters: description: True to include custom fields. required: true default: false + config_profile: + type: string + description: Select which jira config profile to use. + required: false diff --git a/actions/get_issue_attachments.py b/actions/get_issue_attachments.py index d0011b6..b35b4c7 100644 --- a/actions/get_issue_attachments.py +++ b/actions/get_issue_attachments.py @@ -7,7 +7,11 @@ class GetJiraIssueAttachmentsAction(BaseJiraAction): - def run(self, issue_key): + def run(self, issue_key,config_profile=None): + + if config_profile: + self._client = self._get_client(config_profile) + issue = self._client.issue(issue_key) result = [] diff --git a/actions/get_issue_attachments.yaml b/actions/get_issue_attachments.yaml index e54a63b..b1c8ac1 100644 --- a/actions/get_issue_attachments.yaml +++ b/actions/get_issue_attachments.yaml @@ -9,3 +9,8 @@ parameters: type: string description: Issue key (e.g. PROJECT-1000). required: true + config_profile: + type: string + description: Select which jira config profile to use. + required: false + diff --git a/actions/get_issue_comments.py b/actions/get_issue_comments.py index 0e2df8a..9b101e4 100644 --- a/actions/get_issue_comments.py +++ b/actions/get_issue_comments.py @@ -7,7 +7,11 @@ class GetJiraIssueCommentsAction(BaseJiraAction): - def run(self, issue_key): + def run(self, issue_key, config_profile=None): + + if config_profile: + self._client = self._get_client(config_profile) + issue = self._client.issue(issue_key) result = [] diff --git a/actions/get_issue_comments.yaml b/actions/get_issue_comments.yaml index abff9e4..b0d0d1a 100644 --- a/actions/get_issue_comments.yaml +++ b/actions/get_issue_comments.yaml @@ -9,3 +9,7 @@ parameters: type: string description: Issue key (e.g. PROJECT-1000). required: true + config_profile: + type: string + description: Select which jira config profile to use. + required: false diff --git a/actions/lib/base.py b/actions/lib/base.py index 759f720..d5865d1 100755 --- a/actions/lib/base.py +++ b/actions/lib/base.py @@ -14,7 +14,8 @@ def __init__(self, config): class BaseJiraAction(Action): def __init__(self, config): super(BaseJiraAction, self).__init__(config=config) - #self._client = self._get_client() + self._client = self._get_client() + self.project = "" def _get_client(self,profile=None): config = self.config @@ -74,6 +75,7 @@ def _build_profile(self, profile_name): profile['consumer_key'] = config.get('consumer_key') profile['username'] = config.get('username') profile['password'] = config.get('password') + self.project = config.get("project") else: if 'profiles' in config and len(config['profiles']) > 0: for profile_cfg in config['profiles']: @@ -87,10 +89,11 @@ def _build_profile(self, profile_name): profile['consumer_key'] = profile_cfg.get('consumer_key') profile['username'] = profile_cfg.get('username') profile['password'] = profile_cfg.get('password') + self.project = config.get("project") break else: msg = ('No configuration file called: %s found. Please check your config file' % profile) - + if len(profile.items()) == 0: msg = ('No configuration profile found. Please check your config file for the profile you have specified.') raise Exception(msg) diff --git a/actions/search_issues.py b/actions/search_issues.py index 4eb6bf1..bde2abe 100755 --- a/actions/search_issues.py +++ b/actions/search_issues.py @@ -11,7 +11,8 @@ def run(self, query, start_at=0, max_results=50, include_comments=False, include_attachments=False, include_customfields=False, config_profile=None): - self._client = self._get_client(config_profile) + if config_profile: + self._client = self._get_client(config_profile) issues = self._client.search_issues(query, startAt=start_at, maxResults=max_results) diff --git a/actions/transition_issue.py b/actions/transition_issue.py index 55ab10d..e4eb7ad 100755 --- a/actions/transition_issue.py +++ b/actions/transition_issue.py @@ -7,6 +7,10 @@ class TransitionJiraIssueAction(BaseJiraAction): - def run(self, issue_key, transition): + def run(self, issue_key, transition,config_profile=None): + + if config_profile: + self._client = self._get_client(config_profile) + result = self._client.transition_issue(issue_key, transition) return result diff --git a/actions/transition_issue.yaml b/actions/transition_issue.yaml index 3b8a8bd..8c30f19 100755 --- a/actions/transition_issue.yaml +++ b/actions/transition_issue.yaml @@ -13,3 +13,7 @@ parameters: type: string description: Name of transition (e.g. Close, Start Progress, etc). required: true + config_profile: + type: string + description: Select which jira config profile to use. + required: false diff --git a/config.schema.yaml b/config.schema.yaml index 4052d28..1f7f4dc 100755 --- a/config.schema.yaml +++ b/config.schema.yaml @@ -3,7 +3,7 @@ description: "URL of the JIRA instance (e.g. ``https://myproject.atlassian.net``)" type: "string" secret: false - required: true + required: false verify: description: "Verify SSL certificate. Set to False to disable verification. Default True" type: boolean @@ -12,7 +12,7 @@ description: "Authentication method to use - oauth or basic" type: "string" secret: false - required: true + required: false default: "oauth" enum: - oauth @@ -57,7 +57,7 @@ description: "Project to be used as default for actions that don't require or allow a project" type: "string" secret: false - required: true + required: false default_profile: description: "Select which profile will be default. If left blank will use the standard Jira connection details" type: "string" From e382643b5ff89428e7fb88cd1190d25e98b97fab Mon Sep 17 00:00:00 2001 From: pdenning Date: Thu, 13 Dec 2018 12:08:35 +1100 Subject: [PATCH 04/15] added profile section to readme and add changes to changes.md and bumped version to 0.9.0 --- CHANGES.md | 8 ++++++++ README.md | 27 +++++++++++++++++++++++++++ actions/create_issue.py | 3 ++- jira-profiles.yaml.example | 29 +++++++++++++++++++++++++++++ pack.yaml | 2 +- 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 jira-profiles.yaml.example diff --git a/CHANGES.md b/CHANGES.md index a06e993..597e25b 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,13 @@ # Change Log +## 0.9.0 + +- Added config profile support for actions. See profile section in readme. +- Add new config option ``profiles`` this mimicks the jira configuration options to allow for multi jira connections. +- Add new config option ``default_profile`` sets a default profile. If left blank will use the current config method +- Add new action option ``config_profile`` to all actions. This will tell the action to use a different config profile then the default profile. + + ## 0.8.0 - Adding support for BASIC authentication diff --git a/README.md b/README.md index 41c4fd0..d0bc7b4 100755 --- a/README.md +++ b/README.md @@ -40,6 +40,33 @@ You can also use dynamic values from the datastore. See the remember to tell StackStorm to load these new values by running `st2ctl reload --register-configs` +### Config Profiles +The configuration allows for multi jira definitions. This will allow for the automation to multiple Jira instances from a single stackstorm instance. + +Profiles are defined within the ``profile`` section of the configuration and they accept the same parameters as the inline options. +This option takes in an array of profile options. + +This being: + - ``url`` + - ``verify`` + - ``auth_method`` + - ``rsa_cert_file`` + - ``oauth_token`` + - ``oauth_secret`` + - ``consumer_key`` + - ``username`` + - ``password`` + +An additional parameter is ``name`` this defines the name of the profile. + +To define a default profile you can use a config option of ``config_profile``. If set to ``inline`` or not defined it will use the standard configuration options. + +See [jira-profiles.yaml.example] for an example of how to use profiles. + +To enable the the use of a profile within an action use the ``config_profile`` action option and set it to the same name as the profile you wish to use. + +**Note** : Sensors still use the main config profile. Therefore it will still need to be fined. + ### OAuth ### Disclaimer diff --git a/actions/create_issue.py b/actions/create_issue.py index b420d04..813ae81 100755 --- a/actions/create_issue.py +++ b/actions/create_issue.py @@ -14,7 +14,8 @@ def run(self, summary, type, description=None, if config_profile: self._client = self._get_client(config_profile) - project = project or self.config['project'] + #project = project or self.config['project'] + project = project or self.project data = { 'project': {'key': project}, 'summary': summary, diff --git a/jira-profiles.yaml.example b/jira-profiles.yaml.example new file mode 100644 index 0000000..144d599 --- /dev/null +++ b/jira-profiles.yaml.example @@ -0,0 +1,29 @@ +--- + url: "https://company.atlassian.net" + rsa_cert_file: "/home/vagrant/jira.pem" + auth_method: "oauth" + oauth_token: "" + oauth_secret: "" + consumer_key: "" + poll_interval: 30 + project: "MY_PROJECT" + verify: True + default_profile: "dev" + profiles: + - name: "dev" + url: "https://dev.atlassian.net" + rsa_cert_file: "/home/vagrant/jira.pem" + auth_method: "basic" + username: "dev-user" + password: "mypas" + project: "MY_PROJECT" + verify: True + - name: "prod" + url: "https://prod.atlassian.net" + rsa_cert_file: "/home/vagrant/jira.pem" + auth_method: "oauth" + oauth_token: "" + oauth_secret: "" + consumer_key: "" + project: "MY_PROJECT" + verify: True diff --git a/pack.yaml b/pack.yaml index b2fefb3..727f381 100755 --- a/pack.yaml +++ b/pack.yaml @@ -6,6 +6,6 @@ keywords: - issues - ticket management - project management -version: 0.8.0 +version: 0.9.0 author : StackStorm, Inc. email : info@stackstorm.com From 272123e2a7044f0d4f28940876f0eb777490ee65 Mon Sep 17 00:00:00 2001 From: pdenning Date: Thu, 13 Dec 2018 12:13:39 +1100 Subject: [PATCH 05/15] fixed readme --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d0bc7b4..0d79191 100755 --- a/README.md +++ b/README.md @@ -46,22 +46,28 @@ The configuration allows for multi jira definitions. This will allow for the aut Profiles are defined within the ``profile`` section of the configuration and they accept the same parameters as the inline options. This option takes in an array of profile options. -This being: +General Options + - ``name`` - ``url`` - ``verify`` + - ``project`` - ``auth_method`` + +OAuth Options - ``rsa_cert_file`` - ``oauth_token`` - ``oauth_secret`` - ``consumer_key`` + +Basic Auth Options - ``username`` - ``password`` -An additional parameter is ``name`` this defines the name of the profile. +The ``name`` defines the name of the profile. This option is used to define the default profile and used within actions to define with config profile to use. -To define a default profile you can use a config option of ``config_profile``. If set to ``inline`` or not defined it will use the standard configuration options. +To define a default profile you can use a config option of ``default_profile``. If set to ``inline`` or not defined it will use the standard configuration options. -See [jira-profiles.yaml.example] for an example of how to use profiles. +See [jira-profiles.yaml.example](./jira-profiles.yaml.example) for an example of how to use profiles. To enable the the use of a profile within an action use the ``config_profile`` action option and set it to the same name as the profile you wish to use. From 6d7bff3e6b49e86ac34fbab407bffdde37ff01d2 Mon Sep 17 00:00:00 2001 From: pdenning Date: Thu, 13 Dec 2018 12:23:57 +1100 Subject: [PATCH 06/15] fixed whitespace issue --- actions/attach_files_to_issue.py | 2 +- actions/create_issue.py | 2 +- actions/get_issue_attachments.py | 2 +- actions/lib/base.py | 2 +- actions/transition_issue.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/actions/attach_files_to_issue.py b/actions/attach_files_to_issue.py index cf158f7..914d3ed 100644 --- a/actions/attach_files_to_issue.py +++ b/actions/attach_files_to_issue.py @@ -7,7 +7,7 @@ class AttachFilesToJiraIssueAction(BaseJiraAction): - def run(self, issue_key, file_paths,config_profile=None): + def run(self, issue_key, file_paths, config_profile=None): result = [] if config_profile: diff --git a/actions/create_issue.py b/actions/create_issue.py index 813ae81..9fdf1c4 100755 --- a/actions/create_issue.py +++ b/actions/create_issue.py @@ -9,7 +9,7 @@ class CreateJiraIssueAction(BaseJiraAction): def run(self, summary, type, description=None, - project=None, extra_fields=None,config_profile=None): + project=None, extra_fields=None, config_profile=None): if config_profile: self._client = self._get_client(config_profile) diff --git a/actions/get_issue_attachments.py b/actions/get_issue_attachments.py index b35b4c7..17dd83a 100644 --- a/actions/get_issue_attachments.py +++ b/actions/get_issue_attachments.py @@ -7,7 +7,7 @@ class GetJiraIssueAttachmentsAction(BaseJiraAction): - def run(self, issue_key,config_profile=None): + def run(self, issue_key, config_profile=None): if config_profile: self._client = self._get_client(config_profile) diff --git a/actions/lib/base.py b/actions/lib/base.py index d5865d1..147aa73 100755 --- a/actions/lib/base.py +++ b/actions/lib/base.py @@ -17,7 +17,7 @@ def __init__(self, config): self._client = self._get_client() self.project = "" - def _get_client(self,profile=None): + def _get_client(self, profile=None): config = self.config profile_name = profile diff --git a/actions/transition_issue.py b/actions/transition_issue.py index e4eb7ad..1a34558 100755 --- a/actions/transition_issue.py +++ b/actions/transition_issue.py @@ -7,7 +7,7 @@ class TransitionJiraIssueAction(BaseJiraAction): - def run(self, issue_key, transition,config_profile=None): + def run(self, issue_key, transition, config_profile=None): if config_profile: self._client = self._get_client(config_profile) From 4a85140c18bc8a0da32f279b68d4883a346f85c9 Mon Sep 17 00:00:00 2001 From: pdenning Date: Thu, 13 Dec 2018 12:27:48 +1100 Subject: [PATCH 07/15] fixed readme --- actions/create_issue.py | 4 ++-- actions/lib/base.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/actions/create_issue.py b/actions/create_issue.py index 9fdf1c4..1e9a268 100755 --- a/actions/create_issue.py +++ b/actions/create_issue.py @@ -13,8 +13,8 @@ def run(self, summary, type, description=None, if config_profile: self._client = self._get_client(config_profile) - - #project = project or self.config['project'] + + # project = project or self.config['project'] project = project or self.project data = { 'project': {'key': project}, diff --git a/actions/lib/base.py b/actions/lib/base.py index 147aa73..19cbefe 100755 --- a/actions/lib/base.py +++ b/actions/lib/base.py @@ -32,7 +32,6 @@ def _get_client(self, profile=None): profile = self._build_profile(profile_name) - options = {'server': profile['url'], 'verify': profile['verify']} auth_method = profile['auth_method'] From b4c58033abd55cc2a38677bd54fb5932737754ad Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 13 Dec 2018 20:08:40 +1100 Subject: [PATCH 08/15] fixed whitepsaces on blank lines --- actions/create_issue.py | 2 +- actions/transition_issue.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/actions/create_issue.py b/actions/create_issue.py index 1e9a268..ec3909b 100755 --- a/actions/create_issue.py +++ b/actions/create_issue.py @@ -13,7 +13,7 @@ def run(self, summary, type, description=None, if config_profile: self._client = self._get_client(config_profile) - + # project = project or self.config['project'] project = project or self.project data = { diff --git a/actions/transition_issue.py b/actions/transition_issue.py index 1a34558..2251919 100755 --- a/actions/transition_issue.py +++ b/actions/transition_issue.py @@ -8,7 +8,7 @@ class TransitionJiraIssueAction(BaseJiraAction): def run(self, issue_key, transition, config_profile=None): - + if config_profile: self._client = self._get_client(config_profile) From 3078b8511a63bb0a8246bc68b6ff45da59e71881 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 13 Dec 2018 20:32:13 +1100 Subject: [PATCH 09/15] fixed liniting --- actions/lib/base.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/actions/lib/base.py b/actions/lib/base.py index 19cbefe..7768cb7 100755 --- a/actions/lib/base.py +++ b/actions/lib/base.py @@ -69,7 +69,7 @@ def _build_profile(self, profile_name): profile['verify'] = config.get('verify') profile['auth_method'] = config.get('auth_method') profile['rsa_cert_file'] = config.get('rsa_cert_file') - profile['oauth_token'] = config.get('oauth_token') + profile['oauth_token'] = config.get('oauth_token') profile['oauth_secret'] = config.get('oauth_secret') profile['consumer_key'] = config.get('consumer_key') profile['username'] = config.get('username') @@ -83,7 +83,7 @@ def _build_profile(self, profile_name): profile['verify'] = profile_cfg.get('verify') profile['auth_method'] = profile_cfg.get('auth_method') profile['rsa_cert_file'] = profile_cfg.get('rsa_cert_file') - profile['oauth_token'] = profile_cfg.get('oauth_token') + profile['oauth_token'] = profile_cfg.get('oauth_token') profile['oauth_secret'] = profile_cfg.get('oauth_secret') profile['consumer_key'] = profile_cfg.get('consumer_key') profile['username'] = profile_cfg.get('username') @@ -91,10 +91,12 @@ def _build_profile(self, profile_name): self.project = config.get("project") break else: - msg = ('No configuration file called: %s found. Please check your config file' % profile) + msg = ('No configuration file called: %s found. Please check', + 'your config file' % profile) if len(profile.items()) == 0: - msg = ('No configuration profile found. Please check your config file for the profile you have specified.') + msg = ('No configuration profile found. Please check your config', + 'file for the profile you have specified.') raise Exception(msg) return profile From bda123350a72b360102d0c4ef41d905a3839163c Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 13 Dec 2018 20:43:30 +1100 Subject: [PATCH 10/15] fixed up example to include new config options --- jira.yaml.example | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/jira.yaml.example b/jira.yaml.example index 60d0e4a..387ad93 100755 --- a/jira.yaml.example +++ b/jira.yaml.example @@ -1,10 +1,29 @@ --- - url: "https://company.atlassian.net" - rsa_cert_file: "/home/vagrant/jira.pem" - auth_method: "oauth" - oauth_token: "" - oauth_secret: "" - consumer_key: "" - poll_interval: 30 - project: "MY_PROJECT" - verify: True +url: "https://company.atlassian.net" +rsa_cert_file: "/home/vagrant/jira.pem" +auth_method: "oauth" +oauth_token: "" +oauth_secret: "" +consumer_key: "" +poll_interval: 30 +project: "MY_PROJECT" +verify: True +default_profile: "dev" +profiles: + - name: "dev" + url: "https://dev.atlassian.net" + rsa_cert_file: "/home/vagrant/jira.pem" + auth_method: "basic" + username: "dev-user" + password: "mypas" + project: "MY_PROJECT" + verify: True + - name: "prod" + url: "https://prod.atlassian.net" + rsa_cert_file: "/home/vagrant/jira.pem" + auth_method: "oauth" + oauth_token: "" + oauth_secret: "" + consumer_key: "" + project: "MY_PROJECT" + verify: True \ No newline at end of file From 3a6897ec45812493fecbc387b11c4d284549dfbe Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 13 Dec 2018 20:47:12 +1100 Subject: [PATCH 11/15] removed unrequired second config example file --- README.md | 2 +- jira-profiles.yaml.example | 29 ----------------------------- 2 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 jira-profiles.yaml.example diff --git a/README.md b/README.md index 0d79191..75f7408 100755 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ The ``name`` defines the name of the profile. This option is used to define the To define a default profile you can use a config option of ``default_profile``. If set to ``inline`` or not defined it will use the standard configuration options. -See [jira-profiles.yaml.example](./jira-profiles.yaml.example) for an example of how to use profiles. +See [jira.yaml.example](./jira.yaml.example) for an example of how to use profiles. To enable the the use of a profile within an action use the ``config_profile`` action option and set it to the same name as the profile you wish to use. diff --git a/jira-profiles.yaml.example b/jira-profiles.yaml.example deleted file mode 100644 index 144d599..0000000 --- a/jira-profiles.yaml.example +++ /dev/null @@ -1,29 +0,0 @@ ---- - url: "https://company.atlassian.net" - rsa_cert_file: "/home/vagrant/jira.pem" - auth_method: "oauth" - oauth_token: "" - oauth_secret: "" - consumer_key: "" - poll_interval: 30 - project: "MY_PROJECT" - verify: True - default_profile: "dev" - profiles: - - name: "dev" - url: "https://dev.atlassian.net" - rsa_cert_file: "/home/vagrant/jira.pem" - auth_method: "basic" - username: "dev-user" - password: "mypas" - project: "MY_PROJECT" - verify: True - - name: "prod" - url: "https://prod.atlassian.net" - rsa_cert_file: "/home/vagrant/jira.pem" - auth_method: "oauth" - oauth_token: "" - oauth_secret: "" - consumer_key: "" - project: "MY_PROJECT" - verify: True From 5ef48cb51afa7015e699cefc1e2fb1b597f75d65 Mon Sep 17 00:00:00 2001 From: pdenning Date: Mon, 17 Dec 2018 13:00:01 +1100 Subject: [PATCH 12/15] suggest changes from pull request --- README.md | 6 +-- actions/attach_file_to_issue.py | 3 +- actions/attach_files_to_issue.py | 3 +- actions/comment_issue.py | 3 +- actions/create_issue.py | 3 +- actions/get_issue.py | 3 +- actions/get_issue_attachments.py | 3 +- actions/get_issue_comments.py | 3 +- actions/lib/base.py | 54 +++---------------- actions/search_issues.py | 3 +- actions/transition_issue.py | 3 +- config.schema.yaml | 93 +++++--------------------------- 12 files changed, 33 insertions(+), 147 deletions(-) diff --git a/README.md b/README.md index 75f7408..fad3fa2 100755 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ You can also use dynamic values from the datastore. See the ### Config Profiles The configuration allows for multi jira definitions. This will allow for the automation to multiple Jira instances from a single stackstorm instance. -Profiles are defined within the ``profile`` section of the configuration and they accept the same parameters as the inline options. +Profiles are defined within the ``profiles`` section of the configuration and they accept the same parameters as the inline options. This option takes in an array of profile options. General Options @@ -65,13 +65,13 @@ Basic Auth Options The ``name`` defines the name of the profile. This option is used to define the default profile and used within actions to define with config profile to use. -To define a default profile you can use a config option of ``default_profile``. If set to ``inline`` or not defined it will use the standard configuration options. +By default it will use the settings outside of the ``profiles`` section. See [jira.yaml.example](./jira.yaml.example) for an example of how to use profiles. To enable the the use of a profile within an action use the ``config_profile`` action option and set it to the same name as the profile you wish to use. -**Note** : Sensors still use the main config profile. Therefore it will still need to be fined. +**Note** : Sensors still use the main config profile. Therefore it will still need to be defined. ### OAuth diff --git a/actions/attach_file_to_issue.py b/actions/attach_file_to_issue.py index 7d173ec..bb1e145 100644 --- a/actions/attach_file_to_issue.py +++ b/actions/attach_file_to_issue.py @@ -9,8 +9,7 @@ class AttachFileToJiraIssueAction(BaseJiraAction): def run(self, issue_key, file_path, file_name=None, config_profile=None): - if config_profile: - self._client = self._get_client(config_profile) + super(AttachFileToJiraIssueAction, self)._run(config_profile) if not file_name: file_name = None diff --git a/actions/attach_files_to_issue.py b/actions/attach_files_to_issue.py index 914d3ed..5355c97 100644 --- a/actions/attach_files_to_issue.py +++ b/actions/attach_files_to_issue.py @@ -10,8 +10,7 @@ class AttachFilesToJiraIssueAction(BaseJiraAction): def run(self, issue_key, file_paths, config_profile=None): result = [] - if config_profile: - self._client = self._get_client(config_profile) + super(AttachFilesToJiraIssueAction, self)._run(config_profile) for file_path in file_paths: with open(file_path, 'rb') as fp: diff --git a/actions/comment_issue.py b/actions/comment_issue.py index 2d87ed3..ee9c376 100755 --- a/actions/comment_issue.py +++ b/actions/comment_issue.py @@ -10,8 +10,7 @@ class CommentJiraIssueAction(BaseJiraAction): def run(self, issue_key, comment_text, config_profile=None): - if config_profile: - self._client = self._get_client(config_profile) + super(CommentJiraIssueAction, self)._run(config_profile) comment = self._client.add_comment(issue_key, comment_text) result = to_comment_dict(comment) diff --git a/actions/create_issue.py b/actions/create_issue.py index ec3909b..2b0c5c1 100755 --- a/actions/create_issue.py +++ b/actions/create_issue.py @@ -11,8 +11,7 @@ class CreateJiraIssueAction(BaseJiraAction): def run(self, summary, type, description=None, project=None, extra_fields=None, config_profile=None): - if config_profile: - self._client = self._get_client(config_profile) + super(CreateJiraIssueAction, self)._run(config_profile) # project = project or self.config['project'] project = project or self.project diff --git a/actions/get_issue.py b/actions/get_issue.py index d7d37f3..d3336dc 100755 --- a/actions/get_issue.py +++ b/actions/get_issue.py @@ -10,8 +10,7 @@ class GetJiraIssueAction(BaseJiraAction): def run(self, issue_key, include_comments=False, include_attachments=False, include_customfields=False, config_profile=None): - if config_profile: - self._client = self._get_client(config_profile) + super(GetJiraIssueAction, self)._run(config_profile) issue = self._client.issue(issue_key) result = to_issue_dict(issue=issue, include_comments=include_comments, diff --git a/actions/get_issue_attachments.py b/actions/get_issue_attachments.py index 17dd83a..e7d9f7f 100644 --- a/actions/get_issue_attachments.py +++ b/actions/get_issue_attachments.py @@ -9,8 +9,7 @@ class GetJiraIssueAttachmentsAction(BaseJiraAction): def run(self, issue_key, config_profile=None): - if config_profile: - self._client = self._get_client(config_profile) + super(GetJiraIssueAttachmentsAction, self)._run(config_profile) issue = self._client.issue(issue_key) diff --git a/actions/get_issue_comments.py b/actions/get_issue_comments.py index 9b101e4..90bbd5d 100644 --- a/actions/get_issue_comments.py +++ b/actions/get_issue_comments.py @@ -9,8 +9,7 @@ class GetJiraIssueCommentsAction(BaseJiraAction): def run(self, issue_key, config_profile=None): - if config_profile: - self._client = self._get_client(config_profile) + super(GetJiraIssueCommentsAction, self)._run(config_profile) issue = self._client.issue(issue_key) diff --git a/actions/lib/base.py b/actions/lib/base.py index 7768cb7..787f885 100755 --- a/actions/lib/base.py +++ b/actions/lib/base.py @@ -17,20 +17,13 @@ def __init__(self, config): self._client = self._get_client() self.project = "" - def _get_client(self, profile=None): - config = self.config - profile_name = profile + def _run(self, profile=None): + if profile: + self._client = self._get_client(profile) - default_profile = config.get('default_profile', None) - - if profile_name is None and default_profile is None: - profile_name = "inline" - elif profile_name is None and len(default_profile) > 0: - profile_name = default_profile - else: - profile_name = profile + def _get_client(self, profile=None): - profile = self._build_profile(profile_name) + profile = self._build_profile(profile) options = {'server': profile['url'], 'verify': profile['verify']} @@ -64,40 +57,9 @@ def _build_profile(self, profile_name): config = self.config profile = {} - if profile_name == "inline".lower(): - profile['url'] = config.get('url') - profile['verify'] = config.get('verify') - profile['auth_method'] = config.get('auth_method') - profile['rsa_cert_file'] = config.get('rsa_cert_file') - profile['oauth_token'] = config.get('oauth_token') - profile['oauth_secret'] = config.get('oauth_secret') - profile['consumer_key'] = config.get('consumer_key') - profile['username'] = config.get('username') - profile['password'] = config.get('password') - self.project = config.get("project") - else: - if 'profiles' in config and len(config['profiles']) > 0: - for profile_cfg in config['profiles']: - if profile_cfg['name'].lower() == profile_name.lower(): - profile['url'] = profile_cfg.get('url') - profile['verify'] = profile_cfg.get('verify') - profile['auth_method'] = profile_cfg.get('auth_method') - profile['rsa_cert_file'] = profile_cfg.get('rsa_cert_file') - profile['oauth_token'] = profile_cfg.get('oauth_token') - profile['oauth_secret'] = profile_cfg.get('oauth_secret') - profile['consumer_key'] = profile_cfg.get('consumer_key') - profile['username'] = profile_cfg.get('username') - profile['password'] = profile_cfg.get('password') - self.project = config.get("project") - break - else: - msg = ('No configuration file called: %s found. Please check', - 'your config file' % profile) - - if len(profile.items()) == 0: - msg = ('No configuration profile found. Please check your config', - 'file for the profile you have specified.') - raise Exception(msg) + profiles = config.pop('profiles',{}) + override_profile = profiles.get(profile_name,{}) + config.update(override_profile) return profile diff --git a/actions/search_issues.py b/actions/search_issues.py index bde2abe..99d9cce 100755 --- a/actions/search_issues.py +++ b/actions/search_issues.py @@ -11,8 +11,7 @@ def run(self, query, start_at=0, max_results=50, include_comments=False, include_attachments=False, include_customfields=False, config_profile=None): - if config_profile: - self._client = self._get_client(config_profile) + super(SearchJiraIssuesAction, self)._run(config_profile) issues = self._client.search_issues(query, startAt=start_at, maxResults=max_results) diff --git a/actions/transition_issue.py b/actions/transition_issue.py index 2251919..957400a 100755 --- a/actions/transition_issue.py +++ b/actions/transition_issue.py @@ -9,8 +9,7 @@ class TransitionJiraIssueAction(BaseJiraAction): def run(self, issue_key, transition, config_profile=None): - if config_profile: - self._client = self._get_client(config_profile) + super(TransitionJiraIssueAction, self)._run(config_profile) result = self._client.transition_issue(issue_key, transition) return result diff --git a/config.schema.yaml b/config.schema.yaml index 1f7f4dc..e38b1fb 100755 --- a/config.schema.yaml +++ b/config.schema.yaml @@ -1,9 +1,10 @@ --- +<<: &profile_options_anchor url: description: "URL of the JIRA instance (e.g. ``https://myproject.atlassian.net``)" type: "string" secret: false - required: false + required: true verify: description: "Verify SSL certificate. Set to False to disable verification. Default True" type: boolean @@ -12,7 +13,7 @@ description: "Authentication method to use - oauth or basic" type: "string" secret: false - required: false + required: true default: "oauth" enum: - oauth @@ -58,84 +59,16 @@ type: "string" secret: false required: false - default_profile: - description: "Select which profile will be default. If left blank will use the standard Jira connection details" - type: "string" - secret: false - required: false - profiles: - description: "Jira Connection profile." - type: "array" - required: false - items: - type: "object" - required: false - additionalProperties: false - properties: - name: - description: "Name of the profile" - type: "string" - secret: false - reqiured: true - url: - description: "URL of the JIRA instance (e.g. ``https://myproject.atlassian.net``)" - type: "string" - secret: false - required: true - verify: - description: "Verify SSL certificate. Set to False to disable verification. Default True" - type: boolean - default: True - auth_method: - description: "Authentication method to use - oauth or basic" - type: "string" - secret: false - required: true - default: "oauth" - enum: - - oauth - - basic - username: - description: "Username if using the basic auth_method" - type: "string" - secret: false - required: false - password: - description: "Password if using the basic auth_method" - type: "string" - secret: true - required: false - rsa_cert_file: - description: "Path to a private key file, e.g. /home/vagrant/jira.pem" - type: "string" - secret: false - required: false - oauth_token: - description: "OAuth token" - type: "string" - secret: true - required: false - oauth_secret: - description: "OAuth secret" - type: "string" - secret: true - required: false - consumer_key: - description: "Consumer key" - type: "string" - secret: true - required: false - poll_interval: - description: "Polling interval - default 30s" - type: "integer" - secret: false - required: false - default: 30 - project: - description: "Project to be used as default for actions that don't require or allow a project" - type: "string" - secret: false - required: true +profiles: + description: "Jira Connection profile." + type: object + required: false + properties: {} + additionalProperties: + type: object + additionalProperties: false + properties: + <<: *profile_options_anchor From d89c994a042ffb18cd78ac71c5d58440b3c2a321 Mon Sep 17 00:00:00 2001 From: pdenning Date: Tue, 18 Dec 2018 08:23:41 +1100 Subject: [PATCH 13/15] Fixed issues --- actions/lib/base.py | 10 ++++------ config.schema.yaml | 7 ++----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/actions/lib/base.py b/actions/lib/base.py index 787f885..9defe36 100755 --- a/actions/lib/base.py +++ b/actions/lib/base.py @@ -14,12 +14,10 @@ def __init__(self, config): class BaseJiraAction(Action): def __init__(self, config): super(BaseJiraAction, self).__init__(config=config) - self._client = self._get_client() self.project = "" def _run(self, profile=None): - if profile: - self._client = self._get_client(profile) + self._client = self._get_client(profile) def _get_client(self, profile=None): @@ -55,11 +53,11 @@ def _get_client(self, profile=None): def _build_profile(self, profile_name): config = self.config - profile = {} profiles = config.pop('profiles',{}) - override_profile = profiles.get(profile_name,{}) - config.update(override_profile) + profile = profiles.get(profile_name,{}) + if profile.get('url', None) == None: + profile = config return profile diff --git a/config.schema.yaml b/config.schema.yaml index e38b1fb..e8bd5f2 100755 --- a/config.schema.yaml +++ b/config.schema.yaml @@ -1,5 +1,5 @@ --- -<<: &profile_options_anchor +<<: &profile_options url: description: "URL of the JIRA instance (e.g. ``https://myproject.atlassian.net``)" type: "string" @@ -68,7 +68,4 @@ profiles: type: object additionalProperties: false properties: - <<: *profile_options_anchor - - - + <<: *profile_options From 36ca67e53e887c8ef43874c0e487a8351ef0a44a Mon Sep 17 00:00:00 2001 From: pdenning Date: Tue, 18 Dec 2018 08:28:53 +1100 Subject: [PATCH 14/15] Fixed liniting issues --- actions/lib/base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/actions/lib/base.py b/actions/lib/base.py index 9defe36..7b83e17 100755 --- a/actions/lib/base.py +++ b/actions/lib/base.py @@ -54,10 +54,10 @@ def _get_client(self, profile=None): def _build_profile(self, profile_name): config = self.config - profiles = config.pop('profiles',{}) - profile = profiles.get(profile_name,{}) - if profile.get('url', None) == None: - profile = config + profiles = config.pop('profiles', {}) + profile = profiles.get(profile_name, {}) + if profile.get('url', None) is None: + profile = config return profile From 96301b001aaa4a328bfe8bb802974dcf53422843 Mon Sep 17 00:00:00 2001 From: pdenning Date: Tue, 19 Feb 2019 14:25:47 +1100 Subject: [PATCH 15/15] aligned config example with actual config issues? --- .gitignore | 3 +++ jira.yaml.example | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 72364f9..2f7c6cb 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,6 @@ ENV/ # Rope project settings .ropeproject + +# vscode project settings +.vscode diff --git a/jira.yaml.example b/jira.yaml.example index 387ad93..531a47e 100755 --- a/jira.yaml.example +++ b/jira.yaml.example @@ -10,7 +10,7 @@ project: "MY_PROJECT" verify: True default_profile: "dev" profiles: - - name: "dev" + "dev": url: "https://dev.atlassian.net" rsa_cert_file: "/home/vagrant/jira.pem" auth_method: "basic" @@ -18,7 +18,7 @@ profiles: password: "mypas" project: "MY_PROJECT" verify: True - - name: "prod" + "prod": url: "https://prod.atlassian.net" rsa_cert_file: "/home/vagrant/jira.pem" auth_method: "oauth"