mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
N8N-4134 Add AWS cred testing and http custom calls with credentials (#3924)
* ✨ Add Aws testing and http custom api
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
||||
IWebhookFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import { IDataObject, NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||
import { IDataObject, IHttpRequestOptions, NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { get } from 'lodash';
|
||||
|
||||
@@ -28,35 +28,20 @@ export async function awsApiRequest(
|
||||
): Promise<any> {
|
||||
const credentials = await this.getCredentials('aws');
|
||||
|
||||
const endpoint = new URL(
|
||||
(((credentials.sesEndpoint as string) || '').replace(
|
||||
'{region}',
|
||||
credentials.region as string,
|
||||
) || `https://${service}.${credentials.region}.amazonaws.com`) + path,
|
||||
);
|
||||
|
||||
// Sign AWS API request with the user credentials
|
||||
|
||||
const signOpts = { headers: headers || {}, host: endpoint.host, method, path, body } as Request;
|
||||
const securityHeaders = {
|
||||
accessKeyId: `${credentials.accessKeyId}`.trim(),
|
||||
secretAccessKey: `${credentials.secretAccessKey}`.trim(),
|
||||
sessionToken: credentials.temporaryCredentials
|
||||
? `${credentials.sessionToken}`.trim()
|
||||
: undefined,
|
||||
};
|
||||
|
||||
sign(signOpts, securityHeaders);
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
headers: signOpts.headers,
|
||||
const requestOptions = {
|
||||
qs: {
|
||||
service,
|
||||
path,
|
||||
},
|
||||
method,
|
||||
uri: endpoint.href,
|
||||
body: signOpts.body as string,
|
||||
};
|
||||
body: JSON.stringify(body),
|
||||
url: '',
|
||||
headers,
|
||||
region: credentials?.region as string,
|
||||
} as IHttpRequestOptions;
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
return await this.helpers.requestWithAuthentication.call(this,'aws', requestOptions);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error, { parseXml: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user