Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

n8n-3969 - Fetch all analyzers with Cortex #3606

Merged
merged 4 commits into from
Jun 29, 2022
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
19 changes: 19 additions & 0 deletions packages/nodes-base/credentials/CortexApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand All @@ -24,4 +26,21 @@ export class CortexApi implements ICredentialType {
placeholder: 'https://localhost:9001',
},
];

authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Bearer {{$credentials.cortexApiKey}}',
},
},
};

test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials.host}}',
url: '/api/analyzer',
},
};

}
4 changes: 2 additions & 2 deletions packages/nodes-base/nodes/Cortex/Cortex.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class Cortex implements INodeType {
name: 'cortex',
icon: 'file:cortex.svg',
group: ['transform'],
subtitle: '={{$parameter["resource"]+ ": " + $parameter["operation"]}}',
subtitle: '={{$parameter["operation"]+ ": " + $parameter["resource"]}}',
version: 1,
description: 'Apply the Cortex analyzer/responder on the given entity',
defaults: {
Expand Down Expand Up @@ -112,7 +112,7 @@ export class Cortex implements INodeType {
const requestResult = await cortexApiRequest.call(
this,
'POST',
`/analyzer/_search`,
`/analyzer/_search?range=all`,
);

const returnData: INodePropertyOptions[] = [];
Expand Down
12 changes: 2 additions & 10 deletions packages/nodes-base/nodes/Cortex/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import {
OptionsWithUri,
} from 'request';

import {
IAnalyzer,
IJob,
IResponder,
} from './AnalyzerInterface';

import {
IExecuteFunctions,
IExecuteSingleFunctions,
Expand All @@ -25,10 +19,8 @@ export async function cortexApiRequest(this: IHookFunctions | IExecuteFunctions

const credentials = await this.getCredentials('cortexApi');

const headerWithAuthentication = Object.assign({}, { Authorization: ` Bearer ${credentials.cortexApiKey}` });

let options: OptionsWithUri = {
headers: headerWithAuthentication,
headers: {},
method,
qs: query,
uri: uri || `${credentials.host}/api${resource}`,
Expand All @@ -47,7 +39,7 @@ export async function cortexApiRequest(this: IHookFunctions | IExecuteFunctions
}

try {
return await this.helpers.request!(options);
return await this.helpers.requestWithAuthentication.call(this, 'cortexApi', options);
} catch (error) {
throw new NodeApiError(this.getNode(), error);
}
Expand Down
Loading