fix(AwsS3 Node): Fix issue if bucket name contains a '.' (#6542)

This commit is contained in:
Jordan Hall 2023-07-24 11:35:05 +01:00 committed by GitHub
parent a62d00a479
commit 540d32dee4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -215,6 +215,8 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html //https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html
if (operation === 'search') { if (operation === 'search') {
const bucketName = this.getNodeParameter('bucketName', i) as string; const bucketName = this.getNodeParameter('bucketName', i) as string;
const servicePath = bucketName.includes('.') ? 's3' : `${bucketName}.s3`;
const basePath = bucketName.includes('.') ? `/${bucketName}` : '';
const returnAll = this.getNodeParameter('returnAll', 0); const returnAll = this.getNodeParameter('returnAll', 0);
const additionalFields = this.getNodeParameter('additionalFields', 0); const additionalFields = this.getNodeParameter('additionalFields', 0);
@ -243,8 +245,7 @@ export class AwsS3V2 implements INodeType {
} }
qs['list-type'] = 2; qs['list-type'] = 2;
responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', {
location: '', location: '',
}); });
@ -254,9 +255,9 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestRESTAllItems.call( responseData = await awsApiRequestRESTAllItems.call(
this, this,
'ListBucketResult.Contents', 'ListBucketResult.Contents',
`${bucketName}.s3`, servicePath,
'GET', 'GET',
'', basePath,
'', '',
qs, qs,
{}, {},
@ -267,9 +268,9 @@ export class AwsS3V2 implements INodeType {
qs['max-keys'] = this.getNodeParameter('limit', 0); qs['max-keys'] = this.getNodeParameter('limit', 0);
responseData = await awsApiRequestREST.call( responseData = await awsApiRequestREST.call(
this, this,
`${bucketName}.s3`, servicePath,
'GET', 'GET',
'', basePath,
'', '',
qs, qs,
{}, {},
@ -282,6 +283,7 @@ export class AwsS3V2 implements INodeType {
this.helpers.returnJsonArray(responseData as IDataObject[]), this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: i } }, { itemData: { item: i } },
); );
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
returnData.push(...executionData); returnData.push(...executionData);
} }
} }
@ -289,9 +291,11 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html //https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html
if (operation === 'create') { if (operation === 'create') {
const bucketName = this.getNodeParameter('bucketName', i) as string; const bucketName = this.getNodeParameter('bucketName', i) as string;
const servicePath = bucketName.includes('.') ? 's3' : `${bucketName}.s3`;
const basePath = bucketName.includes('.') ? `/${bucketName}` : '';
const folderName = this.getNodeParameter('folderName', i) as string; const folderName = this.getNodeParameter('folderName', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i); const additionalFields = this.getNodeParameter('additionalFields', i);
let path = `/${folderName}/`; let path = `${basePath}/${folderName}/`;
if (additionalFields.requesterPays) { if (additionalFields.requesterPays) {
headers['x-amz-request-payer'] = 'requester'; headers['x-amz-request-payer'] = 'requester';
@ -304,7 +308,7 @@ export class AwsS3V2 implements INodeType {
additionalFields.storageClass as string, additionalFields.storageClass as string,
).toUpperCase(); ).toUpperCase();
} }
responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', { responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '', location: '',
}); });
@ -312,7 +316,7 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestREST.call( responseData = await awsApiRequestREST.call(
this, this,
`${bucketName}.s3`, servicePath,
'PUT', 'PUT',
path, path,
'', '',
@ -330,9 +334,11 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html //https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html
if (operation === 'delete') { if (operation === 'delete') {
const bucketName = this.getNodeParameter('bucketName', i) as string; const bucketName = this.getNodeParameter('bucketName', i) as string;
const servicePath = bucketName.includes('.') ? 's3' : `${bucketName}.s3`;
const basePath = bucketName.includes('.') ? `/${bucketName}` : '';
const folderKey = this.getNodeParameter('folderKey', i) as string; const folderKey = this.getNodeParameter('folderKey', i) as string;
responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', { responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '', location: '',
}); });
@ -341,9 +347,9 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestRESTAllItems.call( responseData = await awsApiRequestRESTAllItems.call(
this, this,
'ListBucketResult.Contents', 'ListBucketResult.Contents',
`${bucketName}.s3`, servicePath,
'GET', 'GET',
'/', basePath,
'', '',
{ 'list-type': 2, prefix: folderKey }, { 'list-type': 2, prefix: folderKey },
{}, {},
@ -355,9 +361,9 @@ export class AwsS3V2 implements INodeType {
if (responseData.length === 0) { if (responseData.length === 0) {
responseData = await awsApiRequestREST.call( responseData = await awsApiRequestREST.call(
this, this,
`${bucketName}.s3`, servicePath,
'DELETE', 'DELETE',
`/${folderKey}`, `${basePath}/${folderKey}`,
'', '',
qs, qs,
{}, {},
@ -393,9 +399,9 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestREST.call( responseData = await awsApiRequestREST.call(
this, this,
`${bucketName}.s3`, servicePath,
'POST', 'POST',
'/', `${basePath}/`,
data, data,
{ delete: '' }, { delete: '' },
headers, headers,
@ -414,6 +420,8 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html //https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html
if (operation === 'getAll') { if (operation === 'getAll') {
const bucketName = this.getNodeParameter('bucketName', i) as string; const bucketName = this.getNodeParameter('bucketName', i) as string;
const servicePath = bucketName.includes('.') ? 's3' : `${bucketName}.s3`;
const basePath = bucketName.includes('.') ? `/${bucketName}` : '';
const returnAll = this.getNodeParameter('returnAll', 0); const returnAll = this.getNodeParameter('returnAll', 0);
const options = this.getNodeParameter('options', 0); const options = this.getNodeParameter('options', 0);
@ -427,7 +435,7 @@ export class AwsS3V2 implements INodeType {
qs['list-type'] = 2; qs['list-type'] = 2;
responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', { responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '', location: '',
}); });
@ -437,9 +445,9 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestRESTAllItems.call( responseData = await awsApiRequestRESTAllItems.call(
this, this,
'ListBucketResult.Contents', 'ListBucketResult.Contents',
`${bucketName}.s3`, servicePath,
'GET', 'GET',
'', basePath,
'', '',
qs, qs,
{}, {},
@ -451,9 +459,9 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestRESTAllItems.call( responseData = await awsApiRequestRESTAllItems.call(
this, this,
'ListBucketResult.Contents', 'ListBucketResult.Contents',
`${bucketName}.s3`, servicePath,
'GET', 'GET',
'', basePath,
'', '',
qs, qs,
{}, {},
@ -561,10 +569,12 @@ export class AwsS3V2 implements INodeType {
const destinationParts = destinationPath.split('/'); const destinationParts = destinationPath.split('/');
const bucketName = destinationParts[1]; const bucketName = destinationParts[1];
const servicePath = bucketName.includes('.') ? 's3' : `${bucketName}.s3`;
const basePath = bucketName.includes('.') ? `/${bucketName}` : '';
const destination = `/${destinationParts.slice(2, destinationParts.length).join('/')}`; const destination = `${basePath}/${destinationParts.slice(2, destinationParts.length).join('/')}`;
responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', { responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '', location: '',
}); });
@ -572,7 +582,7 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestREST.call( responseData = await awsApiRequestREST.call(
this, this,
`${bucketName}.s3`, servicePath,
'PUT', 'PUT',
destination, destination,
'', '',
@ -590,6 +600,8 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html //https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html
if (operation === 'download') { if (operation === 'download') {
const bucketName = this.getNodeParameter('bucketName', i) as string; const bucketName = this.getNodeParameter('bucketName', i) as string;
const servicePath = bucketName.includes('.') ? 's3' : `${bucketName}.s3`;
const basePath = bucketName.includes('.') ? `/${bucketName}` : '';
const fileKey = this.getNodeParameter('fileKey', i) as string; const fileKey = this.getNodeParameter('fileKey', i) as string;
@ -602,7 +614,7 @@ export class AwsS3V2 implements INodeType {
); );
} }
let region = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', { let region = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '', location: '',
}); });
@ -610,9 +622,9 @@ export class AwsS3V2 implements INodeType {
const response = await awsApiRequestREST.call( const response = await awsApiRequestREST.call(
this, this,
`${bucketName}.s3`, servicePath,
'GET', 'GET',
`/${fileKey}`, `${basePath}/${fileKey}`,
'', '',
qs, qs,
{}, {},
@ -652,6 +664,8 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObject.html //https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObject.html
if (operation === 'delete') { if (operation === 'delete') {
const bucketName = this.getNodeParameter('bucketName', i) as string; const bucketName = this.getNodeParameter('bucketName', i) as string;
const servicePath = bucketName.includes('.') ? 's3' : `${bucketName}.s3`;
const basePath = bucketName.includes('.') ? `/${bucketName}` : '';
const fileKey = this.getNodeParameter('fileKey', i) as string; const fileKey = this.getNodeParameter('fileKey', i) as string;
@ -661,7 +675,7 @@ export class AwsS3V2 implements INodeType {
qs.versionId = options.versionId as string; qs.versionId = options.versionId as string;
} }
responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', { responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '', location: '',
}); });
@ -669,9 +683,9 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestREST.call( responseData = await awsApiRequestREST.call(
this, this,
`${bucketName}.s3`, servicePath,
'DELETE', 'DELETE',
`/${fileKey}`, `${basePath}/${fileKey}`,
'', '',
qs, qs,
{}, {},
@ -687,6 +701,8 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html //https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html
if (operation === 'getAll') { if (operation === 'getAll') {
const bucketName = this.getNodeParameter('bucketName', i) as string; const bucketName = this.getNodeParameter('bucketName', i) as string;
const servicePath = bucketName.includes('.') ? 's3' : `${bucketName}.s3`;
const basePath = bucketName.includes('.') ? `/${bucketName}` : '';
const returnAll = this.getNodeParameter('returnAll', 0); const returnAll = this.getNodeParameter('returnAll', 0);
const options = this.getNodeParameter('options', 0); const options = this.getNodeParameter('options', 0);
@ -702,7 +718,7 @@ export class AwsS3V2 implements INodeType {
qs['list-type'] = 2; qs['list-type'] = 2;
responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', { responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '', location: '',
}); });
@ -712,9 +728,9 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestRESTAllItems.call( responseData = await awsApiRequestRESTAllItems.call(
this, this,
'ListBucketResult.Contents', 'ListBucketResult.Contents',
`${bucketName}.s3`, servicePath,
'GET', 'GET',
'', basePath,
'', '',
qs, qs,
{}, {},
@ -726,9 +742,9 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestRESTAllItems.call( responseData = await awsApiRequestRESTAllItems.call(
this, this,
'ListBucketResult.Contents', 'ListBucketResult.Contents',
`${bucketName}.s3`, servicePath,
'GET', 'GET',
'', basePath,
'', '',
qs, qs,
{}, {},
@ -754,12 +770,14 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html //https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html
if (operation === 'upload') { if (operation === 'upload') {
const bucketName = this.getNodeParameter('bucketName', i) as string; const bucketName = this.getNodeParameter('bucketName', i) as string;
const servicePath = bucketName.includes('.') ? 's3' : `${bucketName}.s3`;
const basePath = bucketName.includes('.') ? `/${bucketName}` : '';
const fileName = this.getNodeParameter('fileName', i) as string; const fileName = this.getNodeParameter('fileName', i) as string;
const isBinaryData = this.getNodeParameter('binaryData', i); const isBinaryData = this.getNodeParameter('binaryData', i);
const additionalFields = this.getNodeParameter('additionalFields', i); const additionalFields = this.getNodeParameter('additionalFields', i);
const tagsValues = (this.getNodeParameter('tagsUi', i) as IDataObject) const tagsValues = (this.getNodeParameter('tagsUi', i) as IDataObject)
.tagsValues as IDataObject[]; .tagsValues as IDataObject[];
let path = ''; let path = `${basePath}/`;
let body; let body;
const multipartHeaders: IDataObject = {}; const multipartHeaders: IDataObject = {};
@ -839,7 +857,7 @@ export class AwsS3V2 implements INodeType {
multipartHeaders['x-amz-tagging'] = tags.join('&'); multipartHeaders['x-amz-tagging'] = tags.join('&');
} }
// Get the region of the bucket // Get the region of the bucket
responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', { responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '', location: '',
}); });
const region = responseData.LocationConstraint._; const region = responseData.LocationConstraint._;
@ -853,7 +871,7 @@ export class AwsS3V2 implements INodeType {
uploadData = this.helpers.getBinaryStream(binaryPropertyData.id, UPLOAD_CHUNK_SIZE); uploadData = this.helpers.getBinaryStream(binaryPropertyData.id, UPLOAD_CHUNK_SIZE);
const createMultiPartUpload = await awsApiRequestREST.call( const createMultiPartUpload = await awsApiRequestREST.call(
this, this,
`${bucketName}.s3`, servicePath,
'POST', 'POST',
`/${path}?uploads`, `/${path}?uploads`,
body, body,
@ -875,7 +893,7 @@ export class AwsS3V2 implements INodeType {
try { try {
await awsApiRequestREST.call( await awsApiRequestREST.call(
this, this,
`${bucketName}.s3`, servicePath,
'PUT', 'PUT',
`/${path}?partNumber=${part}&uploadId=${uploadId}`, `/${path}?partNumber=${part}&uploadId=${uploadId}`,
chunk, chunk,
@ -889,7 +907,7 @@ export class AwsS3V2 implements INodeType {
try { try {
await awsApiRequestREST.call( await awsApiRequestREST.call(
this, this,
`${bucketName}.s3`, servicePath,
'DELETE', 'DELETE',
`/${path}?uploadId=${uploadId}`, `/${path}?uploadId=${uploadId}`,
); );
@ -902,7 +920,7 @@ export class AwsS3V2 implements INodeType {
const listParts = (await awsApiRequestREST.call( const listParts = (await awsApiRequestREST.call(
this, this,
`${bucketName}.s3`, servicePath,
'GET', 'GET',
`/${path}?max-parts=${900}&part-number-marker=0&uploadId=${uploadId}`, `/${path}?max-parts=${900}&part-number-marker=0&uploadId=${uploadId}`,
'', '',
@ -954,7 +972,7 @@ export class AwsS3V2 implements INodeType {
const data = builder.buildObject(body); const data = builder.buildObject(body);
const completeUpload = (await awsApiRequestREST.call( const completeUpload = (await awsApiRequestREST.call(
this, this,
`${bucketName}.s3`, servicePath,
'POST', 'POST',
`/${path}?uploadId=${uploadId}`, `/${path}?uploadId=${uploadId}`,
data, data,
@ -991,7 +1009,7 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestREST.call( responseData = await awsApiRequestREST.call(
this, this,
`${bucketName}.s3`, servicePath,
'PUT', 'PUT',
`/${path || binaryPropertyData.fileName}`, `/${path || binaryPropertyData.fileName}`,
body, body,
@ -1019,7 +1037,7 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestREST.call( responseData = await awsApiRequestREST.call(
this, this,
`${bucketName}.s3`, servicePath,
'PUT', 'PUT',
`/${path}`, `/${path}`,
body, body,