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

@@ -65,44 +65,9 @@ export class AwsS3 implements INodeType {
{
name: 'aws',
required: true,
displayOptions: {
show: {
endpoint: [
'aws',
],
},
},
},
{
name: 'customS3Endpoint',
required: true,
displayOptions: {
show: {
endpoint: [
'customS3Endpoint',
],
},
},
},
],
properties: [
{
displayName: 'Endpoint',
name: 'endpoint',
type: 'options',
options: [
{
name: 'AWS',
value: 'aws',
},
{
name: 'Custom S3 endpoint',
value: 'customS3Endpoint',
},
],
default: 'aws',
description: 'The endpoint of S3 compatible service.',
},
{
displayName: 'Resource',
name: 'resource',
@@ -151,14 +116,8 @@ export class AwsS3 implements INodeType {
let credentials;
const endpointType = this.getNodeParameter('endpoint', 0);
try {
if (endpointType === 'aws') {
credentials = this.getCredentials('aws');
} else {
credentials = this.getCredentials('customS3Endpoint');
}
credentials = this.getCredentials('aws');
} catch (error) {
throw new Error(error);
}

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;