🔀 Merge branch 'jira-auth-test' of https://github.com/pemontto/n8n into pemontto-jira-auth-test

This commit is contained in:
Jan Oberhauser 2021-10-20 22:16:23 -05:00
commit db3e0fb422

View file

@ -1,3 +1,7 @@
import {
OptionsWithUri,
} from 'request';
import {
IExecuteFunctions,
} from 'n8n-core';
@ -5,12 +9,15 @@ import {
import {
IBinaryData,
IBinaryKeyData,
ICredentialsDecrypted,
ICredentialTestFunctions,
IDataObject,
ILoadOptionsFunctions,
INodeExecutionData,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
NodeCredentialTestResult,
NodeOperationError,
} from 'n8n-workflow';
@ -74,6 +81,7 @@ export class Jira implements INodeType {
],
},
},
testedBy: 'jiraSoftwareApiTest',
},
{
name: 'jiraSoftwareServerApi',
@ -85,6 +93,7 @@ export class Jira implements INodeType {
],
},
},
testedBy: 'jiraSoftwareApiTest',
},
],
properties: [
@ -145,6 +154,44 @@ export class Jira implements INodeType {
};
methods = {
credentialTest: {
async jiraSoftwareApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise<NodeCredentialTestResult> {
let data; let domain;
const credentials = credential.data;
domain = credentials!.domain;
data = Buffer.from(`${credentials!.email}:${credentials!.password || credentials!.apiToken}`).toString('base64');
const endpoint = '/api/2/project';
const options: OptionsWithUri = {
headers: {
Authorization: `Basic ${data}`,
Accept: 'application/json',
'Content-Type': 'application/json',
'X-Atlassian-Token': 'no-check',
},
method: 'GET',
uri: `${domain}/rest${endpoint}`,
qs: {
recent: 0,
},
json: true,
timeout: 5000,
};
try {
const response = await this.helpers.request!(options);
} catch (err) {
return {
status: 'Error',
message: `Connection details not valid; ${err.message}`,
};
}
return {
status: 'OK',
message: 'Authentication successful!',
};
},
},
loadOptions: {
// Get all the projects to display them to user so that he can
// select them easily