Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 62 additions & 44 deletions packages/nodes-base/nodes/Aws/S3/V2/AwsS3V2.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html
if (operation === 'search') {
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 additionalFields = this.getNodeParameter('additionalFields', 0);

Expand Down Expand Up @@ -243,8 +245,7 @@ export class AwsS3V2 implements INodeType {
}

qs['list-type'] = 2;

responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', {
responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '',
});

Expand All @@ -254,9 +255,9 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestRESTAllItems.call(
this,
'ListBucketResult.Contents',
`${bucketName}.s3`,
servicePath,
'GET',
'',
basePath,
'',
qs,
{},
Expand All @@ -267,9 +268,9 @@ export class AwsS3V2 implements INodeType {
qs['max-keys'] = this.getNodeParameter('limit', 0);
responseData = await awsApiRequestREST.call(
this,
`${bucketName}.s3`,
servicePath,
'GET',
'',
basePath,
'',
qs,
{},
Expand All @@ -282,16 +283,19 @@ export class AwsS3V2 implements INodeType {
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: i } },
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
returnData.push(...executionData);
}
}
if (resource === 'folder') {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html
if (operation === 'create') {
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 additionalFields = this.getNodeParameter('additionalFields', i);
let path = `/${folderName}/`;
let path = `${basePath}/${folderName}/`;

if (additionalFields.requesterPays) {
headers['x-amz-request-payer'] = 'requester';
Expand All @@ -304,15 +308,15 @@ export class AwsS3V2 implements INodeType {
additionalFields.storageClass as string,
).toUpperCase();
}
responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', {
responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '',
});

const region = responseData.LocationConstraint._;

responseData = await awsApiRequestREST.call(
this,
`${bucketName}.s3`,
servicePath,
'PUT',
path,
'',
Expand All @@ -330,9 +334,11 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html
if (operation === 'delete') {
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;

responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', {
responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '',
});

Expand All @@ -341,9 +347,9 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestRESTAllItems.call(
this,
'ListBucketResult.Contents',
`${bucketName}.s3`,
servicePath,
'GET',
'/',
basePath,
'',
{ 'list-type': 2, prefix: folderKey },
{},
Expand All @@ -355,9 +361,9 @@ export class AwsS3V2 implements INodeType {
if (responseData.length === 0) {
responseData = await awsApiRequestREST.call(
this,
`${bucketName}.s3`,
servicePath,
'DELETE',
`/${folderKey}`,
`${basePath}/${folderKey}`,
'',
qs,
{},
Expand Down Expand Up @@ -393,9 +399,9 @@ export class AwsS3V2 implements INodeType {

responseData = await awsApiRequestREST.call(
this,
`${bucketName}.s3`,
servicePath,
'POST',
'/',
`${basePath}/`,
data,
{ delete: '' },
headers,
Expand All @@ -414,6 +420,8 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html
if (operation === 'getAll') {
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 options = this.getNodeParameter('options', 0);

Expand All @@ -427,7 +435,7 @@ export class AwsS3V2 implements INodeType {

qs['list-type'] = 2;

responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', {
responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '',
});

Expand All @@ -437,9 +445,9 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestRESTAllItems.call(
this,
'ListBucketResult.Contents',
`${bucketName}.s3`,
servicePath,
'GET',
'',
basePath,
'',
qs,
{},
Expand All @@ -451,9 +459,9 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestRESTAllItems.call(
this,
'ListBucketResult.Contents',
`${bucketName}.s3`,
servicePath,
'GET',
'',
basePath,
'',
qs,
{},
Expand Down Expand Up @@ -561,18 +569,20 @@ export class AwsS3V2 implements INodeType {
const destinationParts = destinationPath.split('/');

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: '',
});

const region = responseData.LocationConstraint._;

responseData = await awsApiRequestREST.call(
this,
`${bucketName}.s3`,
servicePath,
'PUT',
destination,
'',
Expand All @@ -590,6 +600,8 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html
if (operation === 'download') {
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;

Expand All @@ -602,17 +614,17 @@ export class AwsS3V2 implements INodeType {
);
}

let region = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', {
let region = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '',
});

region = region.LocationConstraint._;

const response = await awsApiRequestREST.call(
this,
`${bucketName}.s3`,
servicePath,
'GET',
`/${fileKey}`,
`${basePath}/${fileKey}`,
'',
qs,
{},
Expand Down Expand Up @@ -652,6 +664,8 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObject.html
if (operation === 'delete') {
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;

Expand All @@ -661,17 +675,17 @@ export class AwsS3V2 implements INodeType {
qs.versionId = options.versionId as string;
}

responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', {
responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '',
});

const region = responseData.LocationConstraint._;

responseData = await awsApiRequestREST.call(
this,
`${bucketName}.s3`,
servicePath,
'DELETE',
`/${fileKey}`,
`${basePath}/${fileKey}`,
'',
qs,
{},
Expand All @@ -687,6 +701,8 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html
if (operation === 'getAll') {
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 options = this.getNodeParameter('options', 0);

Expand All @@ -702,7 +718,7 @@ export class AwsS3V2 implements INodeType {

qs['list-type'] = 2;

responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', {
responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '',
});

Expand All @@ -712,9 +728,9 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestRESTAllItems.call(
this,
'ListBucketResult.Contents',
`${bucketName}.s3`,
servicePath,
'GET',
'',
basePath,
'',
qs,
{},
Expand All @@ -726,9 +742,9 @@ export class AwsS3V2 implements INodeType {
responseData = await awsApiRequestRESTAllItems.call(
this,
'ListBucketResult.Contents',
`${bucketName}.s3`,
servicePath,
'GET',
'',
basePath,
'',
qs,
{},
Expand All @@ -754,12 +770,14 @@ export class AwsS3V2 implements INodeType {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html
if (operation === 'upload') {
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 isBinaryData = this.getNodeParameter('binaryData', i);
const additionalFields = this.getNodeParameter('additionalFields', i);
const tagsValues = (this.getNodeParameter('tagsUi', i) as IDataObject)
.tagsValues as IDataObject[];
let path = '';
let path = `${basePath}/`;
let body;

const multipartHeaders: IDataObject = {};
Expand Down Expand Up @@ -839,7 +857,7 @@ export class AwsS3V2 implements INodeType {
multipartHeaders['x-amz-tagging'] = tags.join('&');
}
// Get the region of the bucket
responseData = await awsApiRequestREST.call(this, `${bucketName}.s3`, 'GET', '', '', {
responseData = await awsApiRequestREST.call(this, servicePath, 'GET', basePath, '', {
location: '',
});
const region = responseData.LocationConstraint._;
Expand All @@ -853,7 +871,7 @@ export class AwsS3V2 implements INodeType {
uploadData = this.helpers.getBinaryStream(binaryPropertyData.id, UPLOAD_CHUNK_SIZE);
const createMultiPartUpload = await awsApiRequestREST.call(
this,
`${bucketName}.s3`,
servicePath,
'POST',
`/${path}?uploads`,
body,
Expand All @@ -875,7 +893,7 @@ export class AwsS3V2 implements INodeType {
try {
await awsApiRequestREST.call(
this,
`${bucketName}.s3`,
servicePath,
'PUT',
`/${path}?partNumber=${part}&uploadId=${uploadId}`,
chunk,
Expand All @@ -889,7 +907,7 @@ export class AwsS3V2 implements INodeType {
try {
await awsApiRequestREST.call(
this,
`${bucketName}.s3`,
servicePath,
'DELETE',
`/${path}?uploadId=${uploadId}`,
);
Expand All @@ -902,7 +920,7 @@ export class AwsS3V2 implements INodeType {

const listParts = (await awsApiRequestREST.call(
this,
`${bucketName}.s3`,
servicePath,
'GET',
`/${path}?max-parts=${900}&part-number-marker=0&uploadId=${uploadId}`,
'',
Expand Down Expand Up @@ -954,7 +972,7 @@ export class AwsS3V2 implements INodeType {
const data = builder.buildObject(body);
const completeUpload = (await awsApiRequestREST.call(
this,
`${bucketName}.s3`,
servicePath,
'POST',
`/${path}?uploadId=${uploadId}`,
data,
Expand Down Expand Up @@ -991,7 +1009,7 @@ export class AwsS3V2 implements INodeType {

responseData = await awsApiRequestREST.call(
this,
`${bucketName}.s3`,
servicePath,
'PUT',
`/${path || binaryPropertyData.fileName}`,
body,
Expand Down Expand Up @@ -1019,7 +1037,7 @@ export class AwsS3V2 implements INodeType {

responseData = await awsApiRequestREST.call(
this,
`${bucketName}.s3`,
servicePath,
'PUT',
`/${path}`,
body,
Expand Down