mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
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:
parent
02810a9ba3
commit
d30b892395
|
@ -9,6 +9,7 @@ import type {
|
||||||
IHttpRequestOptions,
|
IHttpRequestOptions,
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
import type { OptionsWithUri } from 'request';
|
||||||
|
|
||||||
export const regions = [
|
export const regions = [
|
||||||
{
|
{
|
||||||
|
@ -285,44 +286,62 @@ export class Aws implements ICredentialType {
|
||||||
let body = requestOptions.body;
|
let body = requestOptions.body;
|
||||||
let region = credentials.region;
|
let region = credentials.region;
|
||||||
const query = requestOptions.qs?.query as IDataObject;
|
const query = requestOptions.qs?.query as IDataObject;
|
||||||
if (!requestOptions.baseURL && !requestOptions.url) {
|
|
||||||
let endpointString: string;
|
// ! Workaround as we still use the OptionsWithUri interface which uses uri instead of url
|
||||||
if (service === 'lambda' && credentials.lambdaEndpoint) {
|
// ! To change when we replace the interface with IHttpRequestOptions
|
||||||
endpointString = credentials.lambdaEndpoint as string;
|
const requestWithUri = requestOptions as unknown as OptionsWithUri;
|
||||||
} else if (service === 'sns' && credentials.snsEndpoint) {
|
if (requestWithUri.uri) {
|
||||||
endpointString = credentials.snsEndpoint as string;
|
requestOptions.url = requestWithUri.uri as string;
|
||||||
} else if (service === 'sqs' && credentials.sqsEndpoint) {
|
endpoint = new URL(requestOptions.url);
|
||||||
endpointString = credentials.sqsEndpoint as string;
|
|
||||||
} else if (service === 's3' && credentials.s3Endpoint) {
|
|
||||||
endpointString = credentials.s3Endpoint as string;
|
|
||||||
} else if (service === 'ses' && credentials.sesEndpoint) {
|
|
||||||
endpointString = credentials.sesEndpoint as string;
|
|
||||||
} else if (service === 'rekognition' && credentials.rekognitionEndpoint) {
|
|
||||||
endpointString = credentials.rekognitionEndpoint as string;
|
|
||||||
} else if (service === 'sqs' && credentials.sqsEndpoint) {
|
|
||||||
endpointString = credentials.sqsEndpoint as string;
|
|
||||||
} else if (service) {
|
|
||||||
endpointString = `https://${service}.${credentials.region}.amazonaws.com`;
|
|
||||||
}
|
|
||||||
endpoint = new URL(
|
|
||||||
endpointString!.replace('{region}', credentials.region as string) + (path as string),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// If no endpoint is set, we try to decompose the path and use the default endpoint
|
|
||||||
const customUrl = new URL(`${requestOptions.baseURL!}${requestOptions.url}${path ?? ''}`);
|
|
||||||
service = customUrl.hostname.split('.')[0];
|
|
||||||
region = customUrl.hostname.split('.')[1];
|
|
||||||
if (service === 'sts') {
|
if (service === 'sts') {
|
||||||
try {
|
try {
|
||||||
customUrl.searchParams.set('Action', 'GetCallerIdentity');
|
endpoint.searchParams.set('Action', 'GetCallerIdentity');
|
||||||
customUrl.searchParams.set('Version', '2011-06-15');
|
endpoint.searchParams.set('Version', '2011-06-15');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
endpoint = customUrl;
|
service = endpoint.hostname.split('.')[0];
|
||||||
|
region = endpoint.hostname.split('.')[1];
|
||||||
|
} else {
|
||||||
|
if (!requestOptions.baseURL && !requestOptions.url) {
|
||||||
|
let endpointString: string;
|
||||||
|
if (service === 'lambda' && credentials.lambdaEndpoint) {
|
||||||
|
endpointString = credentials.lambdaEndpoint as string;
|
||||||
|
} else if (service === 'sns' && credentials.snsEndpoint) {
|
||||||
|
endpointString = credentials.snsEndpoint as string;
|
||||||
|
} else if (service === 'sqs' && credentials.sqsEndpoint) {
|
||||||
|
endpointString = credentials.sqsEndpoint as string;
|
||||||
|
} else if (service === 's3' && credentials.s3Endpoint) {
|
||||||
|
endpointString = credentials.s3Endpoint as string;
|
||||||
|
} else if (service === 'ses' && credentials.sesEndpoint) {
|
||||||
|
endpointString = credentials.sesEndpoint as string;
|
||||||
|
} else if (service === 'rekognition' && credentials.rekognitionEndpoint) {
|
||||||
|
endpointString = credentials.rekognitionEndpoint as string;
|
||||||
|
} else if (service === 'sqs' && credentials.sqsEndpoint) {
|
||||||
|
endpointString = credentials.sqsEndpoint as string;
|
||||||
|
} else if (service) {
|
||||||
|
endpointString = `https://${service}.${credentials.region}.amazonaws.com`;
|
||||||
|
}
|
||||||
|
endpoint = new URL(
|
||||||
|
endpointString!.replace('{region}', credentials.region as string) + (path as string),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// If no endpoint is set, we try to decompose the path and use the default endpoint
|
||||||
|
const customUrl = new URL(`${requestOptions.baseURL!}${requestOptions.url}${path ?? ''}`);
|
||||||
|
service = customUrl.hostname.split('.')[0];
|
||||||
|
region = customUrl.hostname.split('.')[1];
|
||||||
|
if (service === 'sts') {
|
||||||
|
try {
|
||||||
|
customUrl.searchParams.set('Action', 'GetCallerIdentity');
|
||||||
|
customUrl.searchParams.set('Version', '2011-06-15');
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endpoint = customUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query && Object.keys(query).length !== 0) {
|
if (query && Object.keys(query).length !== 0) {
|
||||||
Object.keys(query).forEach((key) => {
|
Object.keys(query).forEach((key) => {
|
||||||
endpoint.searchParams.append(key, query[key] as string);
|
endpoint.searchParams.append(key, query[key] as string);
|
||||||
|
|
Loading…
Reference in a new issue