10
10
from requests .auth import HTTPBasicAuth
11
11
12
12
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 ,
14
14
issue , issue_project , issue_summary , issue_description , issue_type , issue_components , issue_customfields ,
15
15
existing_comment_id , comment_body , status , jql_query , jql_query_max_results ,
16
16
verbose ):
17
17
self .jira_base_url = jira_base_url
18
18
self .jira_username = jira_username
19
19
self .jira_api_key = jira_api_key
20
+ self .jira_server_pat = jira_server_pat
20
21
self .action = action
21
22
self .issue = issue
22
23
self .issue_project = issue_project
@@ -32,9 +33,23 @@ def __init__(self, jira_base_url, jira_username, jira_api_key, action,
32
33
self .jql_query_max_results = jql_query_max_results
33
34
self .verbose = verbose
34
35
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
+
35
49
36
50
def main ():
37
51
current_environment = environment_setup ()
52
+ valudate_input (current_environment )
38
53
authenticated_jira = authentication (current_environment )
39
54
step_action (current_environment .action , authenticated_jira , current_environment )
40
55
@@ -45,6 +60,7 @@ def environment_setup():
45
60
jira_base_url = StepUtility .getEnvironmentVariable ('JIRA_BASE_URL' , env )
46
61
jira_username = StepUtility .getEnvironmentVariable ('JIRA_USERNAME' , env )
47
62
jira_api_key = StepUtility .getEnvironmentVariable ('JIRA_API_KEY' , env )
63
+ jira_server_pat = StepUtility .getEnvironmentVariable ('JIRA_SERVER_PAT' , env )
48
64
action = StepUtility .getEnvironmentVariable ('ACTION' , env )
49
65
50
66
# Logic here to use the regex to grab the jira issue key and assign it to issue
@@ -100,6 +116,7 @@ def environment_setup():
100
116
jira_base_url ,
101
117
jira_username ,
102
118
jira_api_key ,
119
+ jira_server_pat ,
103
120
action ,
104
121
issue ,
105
122
issue_project ,
@@ -118,6 +135,14 @@ def environment_setup():
118
135
119
136
120
137
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
+
121
146
# Basic authentication with an API Token
122
147
jira = JIRA (
123
148
current_environment .jira_base_url ,
0 commit comments