-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_jira_oauth.py
35 lines (28 loc) · 1.18 KB
/
test_jira_oauth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from jira import JIRA
from ConfigParser import SafeConfigParser
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("final_oauth_token_file_path", help = "Enter complete file path for final_oauth_token.config")
args = parser.parse_args()
config = SafeConfigParser()
config.read(args.final_oauth_token_file_path)
jira_url = config.get("final_oauth_config", "jira_base_url")
oauth_private_key_file_path = config.get("final_oauth_config", "oauth_private_key_file_path")
oauth_token = config.get("final_oauth_config", "oauth_token")
oauth_token_secret=config.get("final_oauth_config", "oauth_token_secret")
consumer_key = config.get("final_oauth_config", "consumer_key")
if jira_url[-1] == '/':
jira_url = jira_url[0:-1]
key_cert_data = None
with open (oauth_private_key_file_path, 'r') as key_cert_file:
key_cert_data = key_cert_file.read()
oauth_dict = {
'access_token' : oauth_token,
'access_token_secret': oauth_token_secret,
'consumer_key': consumer_key,
'key_cert': key_cert_data
}
ajira = JIRA(oauth=oauth_dict, server = jira_url)
projects = ajira.projects()
keys = sorted([project.key for project in projects])[2:5]
print("First 3 Projects are %s" % keys)