本文整理汇总了Python中jira.JIRA属性的典型用法代码示例。如果您正苦于以下问题:Python jira.JIRA属性的具体用法?Python jira.JIRA怎么用?Python jira.JIRA使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类jira
的用法示例。
在下文中一共展示了jira.JIRA属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def connect(self, params={}):
self.url = params.get(Input.URL)
self.username = params.get(Input.USER)
self.password = params.get(Input.API_KEY).get("secretKey")
if ".atlassian.net" in self.url or ".jira.com" in self.url:
self.is_cloud = True
test_passed = self.test()
if test_passed:
client = JIRA(
options={"server": self.url},
basic_auth=(
self.username,
self.password
)
)
self.client = client
self.rest_client = JiraApi(self.client, self.is_cloud, self.logger)
示例2: jira_listener
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def jira_listener(message):
"""
JIRAのissue idっぽいものを取得したら、そのissueの情報を返す
"""
# botメッセージの場合は無視する
if message.body.get('subtype', '') == 'bot_message':
return
text = message.body['text'].upper()
# JIRAのissue idっぽい文字列を取得
for issue_id in re.findall(r'[A-Z]{3,5}-[\d]+', text):
# issue_id から issue 情報の attachments を取得
attachments = create_attachments(issue_id)
if attachments:
# issue 情報を送信する
botwebapi(message, attachments)
示例3: _build_jql
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def _build_jql(args, jql_base=''):
"""
引数から JIRA を検索するための JQL を生成する
"""
jql = jql_base
jql += 'project = {}'.format(args.project)
if args.component:
component = COMPONENT.get(args.component, args.component)
jql += ' AND component = {}'.format(component)
if args.label:
jql += ' AND labels = {}'.format(args.label)
if args.keywords:
target = 'text'
if args.summary:
# 要約を検索対象にする
target = 'summary'
jql += ' AND {} ~ "{}"'.format(target, ' '.join(args.keywords))
return jql
示例4: jira_search
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def jira_search(message, keywords):
"""
JIRAをキーワード検索した結果を返す(オープン状態のみ)
"""
# 引数を処理する
try:
args, argv = parser.parse_known_args(keywords.split())
except SystemExit:
botsend(message, '引数の形式が正しくありません')
_drive_help(message, 'search', '検索')
return
# 引数から query を生成
jql = _build_jql(args, 'status in (Open, "In Progress", Reopened) AND ')
title = '「{}」の検索結果(オープンのみ)'.format(keywords)
_send_jira_search_responce(message, jql, title)
示例5: get_jira_client
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def get_jira_client(connection):
"""Create a JIRA client with the given connection options
"""
url = connection['domain']
username = connection['username']
password = connection['password']
jira_client_options = connection['jira_client_options']
jira_server_version_check = connection['jira_server_version_check']
jira_options = {'server': url}
jira_options.update(jira_client_options)
try:
return JIRA(jira_options, basic_auth=(username, password), get_server_info=jira_server_version_check)
except Exception as e:
if e.status_code == 401:
raise ConfigError("JIRA authentication failed. Check URL and credentials, and ensure the account is not locked.") from None
else:
raise
示例6: _send_jira_search_responce
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def _send_jira_search_responce(message, query, title):
"""
JIRAをqueryで検索した結果を返すメソッド
"""
pretext = title
pretext += '(<{}/issues/?jql={}|JIRAで見る>)'.format(CLEAN_JIRA_URL, quote(query))
text = ''
try:
issues = jira.search_issues(query)
except JIRAError as err:
# なんらかのエラーが発生
botsend(message, 'JIRAError: `{}`'.format(err.text))
return
if issues:
for issue in issues:
summary = issue.fields.summary
key = issue.key
url = issue.permalink()
status = issue.fields.status.name
text += '- <{}|{}> {}({})\n'.format(url, key, summary, status)
else:
text += '該当するJIRA issueは見つかりませんでした'
attachments = [{
'fallback': title,
'pretext': pretext,
'text': text,
}]
botwebapi(message, attachments)
示例7: _create_client
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def _create_client(self):
"""Return a client object for querying the issue tracker."""
config = db_config.get()
credentials = json.loads(config.jira_credentials)
jira_url = config.jira_url
jira_client = jira.JIRA(
jira_url, auth=(credentials['username'], credentials['password']))
return jira_client
示例8: get_jira_client
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def get_jira_client(connection):
url = connection['domain']
token = connection['token']
try:
verify = connection['verify']
except KeyError: #Not found in yaml configuration file
verify = True # Default should be to verify the certificates to Jira server
if token:
username, password = base64.b64decode(token).decode('utf-8').split(':')
else:
username = connection['username']
password = connection['password']
print("Connecting to ", url)
if username is None:
# Fix Python 2.x. raw_input replaced by input in Python 3.x
try:
username = raw_input("Enter Username: ")
except NameError:
username = input("Enter username: ")
except:
username = getpass.getuser() #Get OS username as as fallback
print('No username provided, using username: ' + username)
if password is None:
password = getpass.getpass("Enter Password: ")
if (len(username + password) > 1):
jiraconnection = JIRA(options={'server': url,'verify': verify}, basic_auth=(username, password))
else:
jiraconnection = JIRA(options={'server': url,'verify': verify})
return jiraconnection
示例9: resolve_fields
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def resolve_fields(self):
fields = self.jira.fields()
for name, field in self.settings['fields'].items():
try:
self.fields[name] = next((f['id'] for f in fields if f['name'].lower() == field.lower()))
except StopIteration:
raise Exception("JIRA field with name `%s` does not exist (did you try to use the field id instead?)" % field)
示例10: __init__
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def __init__(self, hostname=None, username=None, password=None, path="", debug=False, clean_obsolete=True, max_time_window=12, decommission_time_window=3):
self.logger = logging.getLogger('JiraAPI')
if debug:
self.logger.setLevel(logging.DEBUG)
if "https://" not in hostname:
hostname = "https://{}".format(hostname)
self.username = username
self.password = password
self.jira = JIRA(options={'server': hostname}, basic_auth=(self.username, self.password))
self.logger.info("Created vjira service for {}".format(hostname))
self.all_tickets = []
self.excluded_tickets = []
self.JIRA_REOPEN_ISSUE = "Reopen Issue"
self.JIRA_CLOSE_ISSUE = "Close Issue"
self.JIRA_RESOLUTION_OBSOLETE = "Obsolete"
self.JIRA_RESOLUTION_FIXED = "Fixed"
self.template_path = 'vulnwhisp/reporting/resources/ticket.tpl'
self.max_ips_ticket = 30
self.attachment_filename = "vulnerable_assets.txt"
self.max_time_tracking = max_time_window #in months
if path:
self.download_tickets(path)
else:
self.logger.warn("No local path specified, skipping Jira ticket download.")
self.max_decommission_time = decommission_time_window #in months
# [HIGIENE] close tickets older than 12 months as obsolete (max_time_window defined)
if clean_obsolete:
self.close_obsolete_tickets()
# deletes the tag "server_decommission" from those tickets closed <=3 months ago
self.decommission_cleanup()
self.jira_still_vulnerable_comment = '''This ticket has been reopened due to the vulnerability not having been fixed (if multiple assets are affected, all need to be fixed; if the server is down, lastest known vulnerability might be the one reported).
- In the case of the team accepting the risk and wanting to close the ticket, please add the label "*risk_accepted*" to the ticket before closing it.
- If server has been decommissioned, please add the label "*server_decommission*" to the ticket before closing it.
- If when checking the vulnerability it looks like a false positive, _+please elaborate in a comment+_ and add the label "*false_positive*" before closing it; we will review it and report it to the vendor.
If you have further doubts, please contact the Security Team.'''
示例11: create_ticket
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def create_ticket(self, title, desc, project="IS", components=[], tags=[], attachment_contents = []):
labels = ['vulnerability_management']
for tag in tags:
labels.append(str(tag))
self.logger.info("Creating ticket for project {} title: {}".format(project, title[:20]))
self.logger.debug("project {} has a component requirement: {}".format(project, components))
project_obj = self.jira.project(project)
components_ticket = []
for component in components:
exists = False
for c in project_obj.components:
if component == c.name:
self.logger.debug("resolved component name {} to id {}".format(c.name, c.id))
components_ticket.append({ "id": c.id })
exists=True
if not exists:
self.logger.error("Error creating Ticket: component {} not found".format(component))
return 0
try:
new_issue = self.jira.create_issue(project=project,
summary=title,
description=desc,
issuetype={'name': 'Bug'},
labels=labels,
components=components_ticket)
self.logger.info("Ticket {} created successfully".format(new_issue))
if attachment_contents:
self.add_content_as_attachment(new_issue, attachment_contents)
except Exception as e:
self.logger.error("Failed to create ticket on Jira Project '{}'. Error: {}".format(project, e))
new_issue = False
return new_issue
#Basic JIRA Metrics
示例12: exclude_accepted_assets
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def exclude_accepted_assets(self, vuln):
# we want to check JIRA tickets with risk_accepted/server_decommission or false_positive labels sharing the same source
# will exclude tickets older than 12 months, old tickets will get closed for higiene and recreated if still vulnerable
labels = [vuln['source'], vuln['scan_name'], 'vulnerability_management', 'vulnerability']
if not self.excluded_tickets:
jql = "{} AND labels in (risk_accepted,server_decommission, false_positive) AND NOT labels=advisory AND created >=startOfMonth(-{})".format(" AND ".join(["labels={}".format(label) for label in labels]), self.max_time_tracking)
self.excluded_tickets = self.jira.search_issues(jql, maxResults=0)
title = vuln['title']
#WARNING: function IGNORES DUPLICATES, after finding a "duplicate" will just return it exists
#it wont iterate over the rest of tickets looking for other possible duplicates/similar issues
self.logger.info("Comparing vulnerability to risk_accepted tickets")
assets_to_exclude = []
tickets_excluded_assets = []
for index in range(len(self.excluded_tickets)):
checking_ticketid, checking_title, checking_assets = self.ticket_get_unique_fields(self.excluded_tickets[index])
if title.encode('ascii') == checking_title.encode('ascii'):
if checking_assets:
#checking_assets is a list, we add to our full list for later delete all assets
assets_to_exclude+=checking_assets
tickets_excluded_assets.append(checking_ticketid)
if assets_to_exclude:
assets_to_remove = []
self.logger.warn("Vulnerable Assets seen on an already existing risk_accepted Jira ticket: {}".format(', '.join(tickets_excluded_assets)))
self.logger.debug("Original assets: {}".format(vuln['ips']))
#assets in vulnerability have the structure "ip - hostname - port", so we need to match by partial
for exclusion in assets_to_exclude:
# for efficiency, we walk the backwards the array of ips from the scanners, as we will be popping out the matches
# and we don't want it to affect the rest of the processing (otherwise, it would miss the asset right after the removed one)
for index in range(len(vuln['ips']))[::-1]:
if exclusion == vuln['ips'][index].split(" - ")[0]:
self.logger.debug("Deleting asset {} from vulnerability {}, seen in risk_accepted.".format(vuln['ips'][index], title))
vuln['ips'].pop(index)
self.logger.debug("Modified assets: {}".format(vuln['ips']))
return vuln
示例13: check_vuln_already_exists
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def check_vuln_already_exists(self, vuln):
'''
This function compares a vulnerability with a collection of tickets.
Returns [exists (bool), is equal (bool), ticketid (str), assets (array)]
'''
# we need to return if the vulnerability has already been reported and the ID of the ticket for further processing
#function returns array [duplicated(bool), update(bool), ticketid, ticket_assets]
title = vuln['title']
labels = [vuln['source'], vuln['scan_name'], 'vulnerability_management', 'vulnerability']
#list(set()) to remove duplicates
assets = list(set(re.findall(r"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b", ",".join(vuln['ips']))))
if not self.all_tickets:
self.logger.info("Retrieving all JIRA tickets with the following tags {}".format(labels))
# we want to check all JIRA tickets, to include tickets moved to other queues
# will exclude tickets older than 12 months, old tickets will get closed for higiene and recreated if still vulnerable
jql = "{} AND NOT labels=advisory AND created >=startOfMonth(-{})".format(" AND ".join(["labels={}".format(label) for label in labels]), self.max_time_tracking)
self.all_tickets = self.jira.search_issues(jql, maxResults=0)
#WARNING: function IGNORES DUPLICATES, after finding a "duplicate" will just return it exists
#it wont iterate over the rest of tickets looking for other possible duplicates/similar issues
self.logger.info("Comparing Vulnerabilities to created tickets")
for index in range(len(self.all_tickets)):
checking_ticketid, checking_title, checking_assets = self.ticket_get_unique_fields(self.all_tickets[index])
# added "not risk_accepted", as if it is risk_accepted, we will create a new ticket excluding the accepted assets
if title.encode('ascii') == checking_title.encode('ascii') and not self.is_risk_accepted(self.jira.issue(checking_ticketid)):
difference = list(set(assets).symmetric_difference(checking_assets))
#to check intersection - set(assets) & set(checking_assets)
if difference:
self.logger.info("Asset mismatch, ticket to update. Ticket ID: {}".format(checking_ticketid))
return False, True, checking_ticketid, checking_assets #this will automatically validate
else:
self.logger.info("Confirmed duplicated. TickedID: {}".format(checking_ticketid))
return True, False, checking_ticketid, [] #this will automatically validate
return False, False, "", []
示例14: jira_login
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def jira_login():
jira_server = {'server': config.jira_server}
return JIRA(options=jira_server, basic_auth=(config.jira_user, config.jira_pass))
示例15: get_transition
# 需要导入模块: import jira [as 别名]
# 或者: from jira import JIRA [as 别名]
def get_transition(issue_key):
jira_server = {'server': config.jira_server}
jira = JIRA(options=jira_server, basic_auth=(config.jira_user, config.jira_pass))
issue = jira.issue(issue_key)
transitions = jira.transitions(issue)
for t in transitions:
if t['name'] == config.jira_transition:
return t['id']