Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/components/credentials/JiraApiBearerToken.credential.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { INodeParams, INodeCredential } from '../src/Interface'

class JiraApiBearerToken implements INodeCredential {
label: string
name: string
version: number
description: string
inputs: INodeParams[]

constructor() {
this.label = 'Jira API (Bearer Token)'
this.name = 'jiraApiBearerToken'
this.version = 1.0
this.description =
'Use Personal Access Token (PAT) for Jira Server/Data Center. Refer to <a target="_blank" href="https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html">official guide</a> on how to create a PAT.'
this.inputs = [
{
label: 'Bearer Token',
name: 'bearerToken',
type: 'password',
placeholder: '<JIRA_PERSONAL_ACCESS_TOKEN>'
}
]
}
}

module.exports = { credClass: JiraApiBearerToken }
81 changes: 67 additions & 14 deletions packages/components/nodes/tools/Jira/Jira.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { convertMultiOptionsToStringArray, getCredentialData, getCredentialParam } from '../../../src/utils'
import { getFileFromStorage } from '../../../src'
import { createJiraTools } from './core'
import type { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'

Expand All @@ -17,7 +18,7 @@ class Jira_Tools implements INode {
constructor() {
this.label = 'Jira'
this.name = 'jiraTool'
this.version = 1.0
this.version = 2.0
this.type = 'Jira'
this.icon = 'jira.svg'
this.category = 'Tools'
Expand All @@ -27,7 +28,7 @@ class Jira_Tools implements INode {
label: 'Connect Credential',
name: 'credential',
type: 'credential',
credentialNames: ['jiraApi']
credentialNames: ['jiraApi', 'jiraApiBearerToken']
}
this.inputs = [
{
Expand All @@ -36,6 +37,25 @@ class Jira_Tools implements INode {
type: 'string',
placeholder: 'https://example.atlassian.net'
},
{
label: 'Enable SSL Certificate',
name: 'enableSSL',
type: 'boolean',
description: 'Enable if your JIRA Server/DC uses an SSL certificate',
optional: true,
default: false
},
{
label: 'SSL Certificate',
description: 'Upload SSL certificate (.pem or .crt) for JIRA Server/DC',
name: 'caFile',
type: 'file',
fileType: '.pem, .crt',
show: {
enableSSL: true
},
optional: true
},
{
label: 'Type',
name: 'jiraType',
Expand Down Expand Up @@ -372,20 +392,42 @@ class Jira_Tools implements INode {

async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
let credentialData = await getCredentialData(nodeData.credential ?? '', options)
const username = getCredentialParam('username', credentialData, nodeData)
const accessToken = getCredentialParam('accessToken', credentialData, nodeData)
const jiraHost = nodeData.inputs?.jiraHost as string

if (!username) {
throw new Error('No username found in credential')
if (!jiraHost) {
throw new Error('No Jira host provided')
}

if (!accessToken) {
throw new Error('No access token found in credential')
const bearerToken = getCredentialParam('bearerToken', credentialData, nodeData)
const username = getCredentialParam('username', credentialData, nodeData)
const accessToken = getCredentialParam('accessToken', credentialData, nodeData)

let authType: 'basic' | 'bearer'
if (bearerToken) {
authType = 'bearer'
} else if (username && accessToken) {
authType = 'basic'
} else {
throw new Error('Invalid credentials: provide either Bearer Token or Username + Access Token')
}

if (!jiraHost) {
throw new Error('No Jira host provided')
// Read SSL certificate from tool inputs if provided
let sslCertificate: string | undefined
const caFileBase64 = nodeData.inputs?.caFile as string
if (caFileBase64) {
if (caFileBase64.startsWith('FILE-STORAGE::')) {
let file = caFileBase64.replace('FILE-STORAGE::', '')
file = file.replace('[', '').replace(']', '')
Comment thread
chiragjagga marked this conversation as resolved.
const orgId = options.orgId
const chatflowid = options.chatflowid
const fileData = await getFileFromStorage(file, orgId, chatflowid)
sslCertificate = fileData.toString()
} else {
const splitDataURI = caFileBase64.split(',')
splitDataURI.pop()
const bf = Buffer.from(splitDataURI.pop() || '', 'base64')
sslCertificate = bf.toString('utf-8')
Comment thread
chiragjagga marked this conversation as resolved.
}
}

// Get all actions based on type
Expand All @@ -402,13 +444,24 @@ class Jira_Tools implements INode {

const defaultParams = this.transformNodeInputsToToolArgs(nodeData)

// Create and return tools based on selected actions
const tools = createJiraTools({
actions,
// Basic Auth (username + API token) = Jira Cloud = API v3
// Bearer Token (PAT) = Jira Server/DC = API v2
const apiVersion = authType === 'bearer' ? '2' : '3'

const authConfig = {
authType,
username,
accessToken,
bearerToken,
sslCertificate
}

const tools = createJiraTools({
actions,
jiraHost,
defaultParams
defaultParams,
apiVersion,
authConfig
})

return tools
Expand Down
Loading