fix(HTTP Request Node): Fix AWS credentials to automatically deconstruct the url (#5751)

Workaround to use decompose uri whe OptionsUri is being used
This commit is contained in:
agobrech 2023-03-22 22:04:25 +01:00 committed by GitHub
parent 02810a9ba3
commit d30b892395
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,6 +9,7 @@ import type {
IHttpRequestOptions,
INodeProperties,
} from 'n8n-workflow';
import type { OptionsWithUri } from 'request';
export const regions = [
{
@ -285,6 +286,24 @@ export class Aws implements ICredentialType {
let body = requestOptions.body;
let region = credentials.region;
const query = requestOptions.qs?.query as IDataObject;
// ! Workaround as we still use the OptionsWithUri interface which uses uri instead of url
// ! To change when we replace the interface with IHttpRequestOptions
const requestWithUri = requestOptions as unknown as OptionsWithUri;
if (requestWithUri.uri) {
requestOptions.url = requestWithUri.uri as string;
endpoint = new URL(requestOptions.url);
if (service === 'sts') {
try {
endpoint.searchParams.set('Action', 'GetCallerIdentity');
endpoint.searchParams.set('Version', '2011-06-15');
} catch (err) {
console.log(err);
}
}
service = endpoint.hostname.split('.')[0];
region = endpoint.hostname.split('.')[1];
} else {
if (!requestOptions.baseURL && !requestOptions.url) {
let endpointString: string;
if (service === 'lambda' && credentials.lambdaEndpoint) {
@ -322,7 +341,7 @@ export class Aws implements ICredentialType {
}
endpoint = customUrl;
}
}
if (query && Object.keys(query).length !== 0) {
Object.keys(query).forEach((key) => {
endpoint.searchParams.append(key, query[key] as string);