Create generic S3 node

This commit is contained in:
Denis Palashevskii
2020-08-18 16:56:53 +04:00
parent a3c5a971e5
commit 77eb0f4955
9 changed files with 2325 additions and 60 deletions

View File

@@ -31,14 +31,8 @@ export async function s3ApiRequest(this: IHookFunctions | IExecuteFunctions | IL
let credentials;
const endpointType = this.getNodeParameter('endpoint', 0);
try {
if (endpointType === 'aws') {
credentials = this.getCredentials('aws');
} else {
credentials = this.getCredentials('customS3Endpoint');
}
} catch (error) {
throw new Error(error);
}
@@ -47,19 +41,8 @@ export async function s3ApiRequest(this: IHookFunctions | IExecuteFunctions | IL
throw new Error('No credentials got returned!');
}
if (endpointType === "customS3Endpoint" && !(credentials.endpoint as string).startsWith('http')) {
throw new Error('HTTP(S) Scheme is required in endpoint definition');
}
const endpoint = new URL(endpointType === 'aws' ? `https://${bucket}.s3.${region || credentials.region}.amazonaws.com` : credentials.endpoint as string);
if (bucket && endpointType === 'customS3Endpoint') {
if (credentials.forcePathStyle) {
path = `/${bucket}${path}`;
} else {
endpoint.host = `${bucket}.${endpoint.host}`;
}
}
const endpoint = new URL(`https://${bucket}.s3.${region || credentials.region}.amazonaws.com`);
endpoint.pathname = path;