Skip to content

Commit

Permalink
Jira - Updated normalising user object | Updated SDK to the latest ve…
Browse files Browse the repository at this point in the history
…rsion | Updated plugin description (#3212)
  • Loading branch information
igorski-r7 authored Feb 24, 2025
1 parent 6600598 commit d6c3a14
Show file tree
Hide file tree
Showing 20 changed files with 147 additions and 141 deletions.
6 changes: 3 additions & 3 deletions plugins/jira/.CHECKSUM
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"spec": "6635c0af4e5c44ca8e24acc2d46f3d76",
"manifest": "f6c51b9a5d5afae0b49ca91e095bbfcc",
"setup": "8a1dacc5bb9f8c6dec279269d4b2e0e7",
"spec": "d36415e7f92d206b2aaf9061de1fda37",
"manifest": "dfd52027f652f1e2a0e25a8ceca989a6",
"setup": "4c255a0d4a7f5811424a20ac0f2b8d40",
"schemas": [
{
"identifier": "assign_issue/schema.py",
Expand Down
11 changes: 3 additions & 8 deletions plugins/jira/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
FROM --platform=linux/amd64 rapid7/insightconnect-python-3-slim-plugin:6.1.0
FROM --platform=linux/amd64 rapid7/insightconnect-python-3-slim-plugin:6.2.5

LABEL organization=rapid7
LABEL sdk=python
LABEL type=plugin

ENV SSL_CERT_FILE /etc/ssl/certs/ca-certificates.crt
ENV SSL_CERT_DIR /etc/ssl/certs
ENV REQUESTS_CA_BUNDLE /etc/ssl/certs/ca-certificates.crt
WORKDIR /python/src

ENV CRYPTOGRAPHY_DONT_BUILD_RUST=1

WORKDIR /python/src

ADD ./plugin.spec.yaml /plugin.spec.yaml
ADD ./requirements.txt /python/src/requirements.txt

RUN if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

ADD . /python/src

RUN python setup.py build && python setup.py install
RUN pip install .

# User to run plugin code. The two supported users are: root, nobody
USER nobody
Expand Down
4 changes: 2 additions & 2 deletions plugins/jira/bin/komand_jira
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ from sys import argv

Name = "Jira"
Vendor = "rapid7"
Version = "6.5.0"
Description = "[Jira](https://www.atlassian.com/software/jira) is an issue tracking product developed by Atlassian that allows teams to plan, track, and release great software. This plugin uses the [Jira REST API](https://developer.atlassian.com/cloud/jira/platform/rest/v2/) to programmatically manage and create issues and users. The Jira plugin supports cloud and on-premise versions of Jira Software, Jira Server, and Jira ServiceDesk products from Atlassian. Please note that only JIRA cloud is supported with InsightConnect cloud connections"
Version = "6.5.1"
Description = "[Jira](https://www.atlassian.com/software/jira) is an issue tracking product developed by Atlassian that allows teams to plan, track, and release great software. This plugin uses the [Jira REST API](https://developer.atlassian.com/cloud/jira/platform/rest/v2/) to programmatically manage and create issues and users. The Jira plugin supports cloud (only with InsightConnect cloud connections) and on-premise versions of Jira Software, Jira Server, and Jira ServiceDesk products from Atlassian."


def main():
Expand Down
5 changes: 3 additions & 2 deletions plugins/jira/help.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Description

[Jira](https://www.atlassian.com/software/jira) is an issue tracking product developed by Atlassian that allows teams to plan, track, and release great software. This plugin uses the [Jira REST API](https://developer.atlassian.com/cloud/jira/platform/rest/v2/) to programmatically manage and create issues and users. The Jira plugin supports cloud and on-premise versions of Jira Software, Jira Server, and Jira ServiceDesk products from Atlassian. Please note that only JIRA cloud is supported with InsightConnect cloud connections
[Jira](https://www.atlassian.com/software/jira) is an issue tracking product developed by Atlassian that allows teams to plan, track, and release great software. This plugin uses the [Jira REST API](https://developer.atlassian.com/cloud/jira/platform/rest/v2/) to programmatically manage and create issues and users. The Jira plugin supports cloud (only with InsightConnect cloud connections) and on-premise versions of Jira Software, Jira Server, and Jira ServiceDesk products from Atlassian.

# Key Features

Expand Down Expand Up @@ -726,10 +726,11 @@ Example output:

## Troubleshooting

Please note only Jira cloud is supported with InsightConnect cloud. For JIRA OnPrem, please use an orchestrator for connecting.
* Please note only Jira cloud is supported with InsightConnect cloud. For JIRA OnPrem, please use an orchestrator for connecting.

# Version History

* 6.5.1 - Updated normalizing user object | Updated SDK to the latest version
* 6.5.0 - Cloud enable the plugin | Bump SDK version to 6.1.0 | Added an error message if trying to connect to Jira on-prem for ICON cloud
* 6.4.0 - Fix Issue Where Create Issue failed when multiple versions of the input Issue Type exists in Jira | Fix failed connection test response for PAT based connection | Include Fields input added to New Issue and Monitor Issues triggers, to specify whether to return Issue fields in the output | Removed empty Fields output from returned Issues when not requested or available
* 6.3.0 - Add PAT authentication scheme for Jira on-prem
Expand Down
16 changes: 7 additions & 9 deletions plugins/jira/komand_jira/actions/get_comments/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Custom imports below
from komand_jira.util.util import normalize_comment
from insightconnect_plugin_runtime.exceptions import PluginException
from insightconnect_plugin_runtime.helper import clean


class GetComments(insightconnect_plugin_runtime.Action):
Expand All @@ -16,25 +17,22 @@ def __init__(self):
)

def run(self, params={}):
"""Run action"""
issue = self.connection.client.issue(id=params[Input.ID])
# START INPUT BINDING - DO NOT REMOVE - ANY INPUTS BELOW WILL UPDATE WITH YOUR PLUGIN SPEC AFTER REGENERATION
identifier = params.get(Input.ID)
# END INPUT BINDING - DO NOT REMOVE

issue = self.connection.client.issue(id=identifier)
if not issue:
raise PluginException(
cause=f"No issue found with ID: {params[Input.ID]}.",
cause=f"No issue found with ID: {identifier}.",
assistance="Please provide a valid issue ID.",
)

comments = issue.fields.comment.comments or []

results = list(
map(
lambda comment: normalize_comment(comment, is_cloud=self.connection.is_cloud, logger=self.logger),
comments,
)
)
results = insightconnect_plugin_runtime.helper.clean(results)

count = len(results)

return {Output.COUNT: count, Output.COMMENTS: results}
return {Output.COUNT: len(results), Output.COMMENTS: clean(results)}
21 changes: 10 additions & 11 deletions plugins/jira/komand_jira/connection/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@


class Connection(insightconnect_plugin_runtime.Connection):
def __init__(self):
super(self.__class__, self).__init__(input=ConnectionSchema())
self.client = None
self.url = None
self.username = None
self.password = None
self.is_cloud = False
self.rest_client = None

def _validate_params(self, params={}):
self.url = params.get(Input.URL, "")
self.username = params.get(Input.USER)
Expand All @@ -29,17 +38,6 @@ def _validate_params(self, params={}):
elif not self.username and not self.password and not self.pat:
raise PluginException(cause="No credentials provided at all.", assistance="Please provide some credentials")

def __init__(self):
super(self.__class__, self).__init__(input=ConnectionSchema())
self.client, self.url, self.username, self.password, self.is_cloud = (
None,
None,
None,
None,
False,
)
self.rest_client = None

def connect(self, params={}):
self._validate_params(params)

Expand Down Expand Up @@ -78,6 +76,7 @@ def test(self):
response = self.test_pat()
else:
response = self.test_basic_auth()

# https://developer.atlassian.com/cloud/jira/platform/rest/v2/?utm_source=%2Fcloud%2Fjira%2Fplatform%2Frest%2F&utm_medium=302#error-responses
if response.status_code == 200:
return {"success": True}
Expand Down
20 changes: 10 additions & 10 deletions plugins/jira/komand_jira/util/util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import logging
import base64
from jira import User
from typing import Dict, Any


def normalize_comment(source, is_cloud=False, logger=logging.getLogger()):
def normalize_comment(source, is_cloud: bool = False, logger: logging.Logger = logging.getLogger()):
comment = source.raw
author = normalize_user(source.author, is_cloud, logger)
comment["author"] = author
Expand Down Expand Up @@ -67,19 +69,17 @@ def normalize_issue(issue, get_attachments=False, include_raw_fields=False, logg
return output


def normalize_user(user, is_cloud=False, logger=logging.getLogger()):
def normalize_user(user: User, is_cloud: bool = False, logger: logging.Logger = logging.getLogger()) -> Dict[str, Any]:
output = {
"display_name": user.displayName,
"active": user.active,
"email_address": user.emailAddress,
"display_name": user.raw.get("displayName", ""),
"active": user.raw.get("active", False),
"email_address": user.raw.get("emailAddress", ""),
}
if is_cloud:
output["account_id"] = user.accountId
output["account_id"] = user.raw.get("accountId", "")
else:
output["name"] = user.name

logger.debug("Result user: %s", output)

output["name"] = user.raw.get("name", "")
logger.debug(f"Result user: {output}")
return output


Expand Down
Loading

0 comments on commit d6c3a14

Please sign in to comment.