Skip to content

Commit 6734dbd

Browse files
Cr 17130 jira pat 2 (#567)
1 parent d1c5c38 commit 6734dbd

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

incubating/jira-issue-manager/script/jira_issue_manager.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
from requests.auth import HTTPBasicAuth
1111

1212
class Environment:
13-
def __init__(self, jira_base_url, jira_username, jira_api_key, action,
13+
def __init__(self, jira_base_url, jira_username, jira_api_key, jira_server_pat, action,
1414
issue, issue_project, issue_summary, issue_description, issue_type, issue_components, issue_customfields,
1515
existing_comment_id, comment_body, status, jql_query, jql_query_max_results,
1616
verbose):
1717
self.jira_base_url = jira_base_url
1818
self.jira_username = jira_username
1919
self.jira_api_key = jira_api_key
20+
self.jira_server_pat = jira_server_pat
2021
self.action = action
2122
self.issue = issue
2223
self.issue_project = issue_project
@@ -32,9 +33,23 @@ def __init__(self, jira_base_url, jira_username, jira_api_key, action,
3233
self.jql_query_max_results = jql_query_max_results
3334
self.verbose = verbose
3435

36+
def valudate_input(current_environment):
37+
if not current_environment.jira_api_key and current_environment.jira_username:
38+
raise Exception('JIRA_API_KEY required for basic authentication')
39+
40+
if current_environment.jira_api_key and not current_environment.jira_username:
41+
raise Exception('JIRA_USERNAME required for basic authentication')
42+
43+
if not current_environment.jira_api_key and not current_environment.jira_server_pat:
44+
raise Exception('Credentials not provided')
45+
46+
if current_environment.jira_api_key and current_environment.jira_server_pat:
47+
raise Exception('Only one of JIRA_API_KEY and JIRA_SERVER_PAT allowed')
48+
3549

3650
def main():
3751
current_environment = environment_setup()
52+
valudate_input(current_environment)
3853
authenticated_jira = authentication(current_environment)
3954
step_action(current_environment.action, authenticated_jira, current_environment)
4055

@@ -45,6 +60,7 @@ def environment_setup():
4560
jira_base_url = StepUtility.getEnvironmentVariable('JIRA_BASE_URL', env)
4661
jira_username = StepUtility.getEnvironmentVariable('JIRA_USERNAME', env)
4762
jira_api_key = StepUtility.getEnvironmentVariable('JIRA_API_KEY', env)
63+
jira_server_pat = StepUtility.getEnvironmentVariable('JIRA_SERVER_PAT', env)
4864
action = StepUtility.getEnvironmentVariable('ACTION', env)
4965

5066
# Logic here to use the regex to grab the jira issue key and assign it to issue
@@ -100,6 +116,7 @@ def environment_setup():
100116
jira_base_url,
101117
jira_username,
102118
jira_api_key,
119+
jira_server_pat,
103120
action,
104121
issue,
105122
issue_project,
@@ -118,6 +135,14 @@ def environment_setup():
118135

119136

120137
def authentication(current_environment):
138+
if current_environment.jira_server_pat:
139+
# Jira Server authentication with a PAT
140+
jira = JIRA(
141+
current_environment.jira_base_url,
142+
token_auth=current_environment.jira_server_pat
143+
)
144+
return jira
145+
121146
# Basic authentication with an API Token
122147
jira = JIRA(
123148
current_environment.jira_base_url,

incubating/jira-issue-manager/step.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ kind: step-type
22
version: '1.0'
33
metadata:
44
name: jira-issue-manager
5-
version: 1.0.10
5+
version: 1.0.11
66
title: Jira Issue Manager
77
isPublic: true
88
description: Create, Update, & Validate Jira Issues
@@ -158,9 +158,7 @@ spec:
158158
"additionalProperties": false,
159159
"patterns": [],
160160
"required": [
161-
"JIRA_BASE_URL",
162-
"JIRA_USERNAME",
163-
"JIRA_API_KEY"
161+
"JIRA_BASE_URL"
164162
],
165163
"properties": {
166164
"JIRA_BASE_URL": {
@@ -175,6 +173,10 @@ spec:
175173
"type": "string",
176174
"description": "Jira API key"
177175
},
176+
"JIRA_SERVER_PAT": {
177+
"type": "string",
178+
"description": "Jira Personal Access Token for Jira Server"
179+
},
178180
"ACTION": {
179181
"type": "string",
180182
"description": "Specifies the type of action to perform against your Jira instance - please see the examples and readme"
@@ -243,7 +245,7 @@ spec:
243245
stepsTemplate: |-
244246
main:
245247
name: jira-issue-manager
246-
image: quay.io/codefreshplugins/jira-issue-manager:1.0.10
248+
image: quay.io/codefreshplugins/jira-issue-manager:1.0.11
247249
environment:
248250
[[ range $key, $val := .Arguments ]]
249251
- '[[ $key ]]=[[ $val ]]'

0 commit comments

Comments
 (0)