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:
agobrech
2022-08-23 19:02:32 +02:00
committed by GitHub
parent a85d565ffc
commit 5285fc1de6
10 changed files with 196 additions and 231 deletions

View File

@@ -38,7 +38,6 @@ export class AwsTextract implements INodeType {
{
name: 'aws',
required: true,
testedBy: 'awsTextractApiCredentialTest',
},
],
properties: [

View File

@@ -16,6 +16,7 @@ import {
import {
ICredentialDataDecryptedObject,
ICredentialTestFunctions,
IHttpRequestOptions,
NodeApiError,
NodeOperationError,
} from 'n8n-workflow';
@@ -46,30 +47,20 @@ export async function awsApiRequest(
): Promise<any> {
const credentials = await this.getCredentials('aws');
// Concatenate path and instantiate URL object so it parses correctly query strings
const endpoint = new URL(getEndpointForService(service, credentials) + 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,
};
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) {
if (error?.response?.data || error?.response?.body) {
const errorMessage = error?.response?.data || error?.response?.body;