Fix an issue with S3-Node

This commit is contained in:
Jan Oberhauser 2020-04-20 20:44:22 +02:00
parent aa949dd11f
commit fa8c7787a0
4 changed files with 40 additions and 33 deletions

View file

@ -28,7 +28,7 @@ export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | I
uri: `https://${endpoint}${signOpts.path}`, uri: `https://${endpoint}${signOpts.path}`,
body: signOpts.body, body: signOpts.body,
}; };
console.log('aja')
try { try {
return await this.helpers.request!(options); return await this.helpers.request!(options);
} catch (error) { } catch (error) {

View file

@ -1,7 +1,21 @@
import {
snakeCase,
paramCase,
} from 'change-case';
import {
createHash,
} from 'crypto';
import {
Builder,
} from 'xml2js';
import { import {
IExecuteFunctions,
BINARY_ENCODING, BINARY_ENCODING,
} from 'n8n-core'; IExecuteFunctions,
} from 'n8n-core';
import { import {
IBinaryKeyData, IBinaryKeyData,
@ -17,13 +31,13 @@ import {
} from './BucketDescription'; } from './BucketDescription';
import { import {
folderOperations, folderFields,
folderFields, folderOperations,
} from './FolderDescription'; } from './FolderDescription';
import { import {
fileOperations,
fileFields, fileFields,
fileOperations,
} from './FileDescription'; } from './FileDescription';
import { import {
@ -32,19 +46,6 @@ import {
awsApiRequestSOAPAllItems, awsApiRequestSOAPAllItems,
} from './GenericFunctions'; } from './GenericFunctions';
import {
snakeCase,
paramCase,
} from 'change-case';
import {
createHash,
} from 'crypto';
import {
Builder,
} from 'xml2js';
export class AwsS3 implements INodeType { export class AwsS3 implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
displayName: 'AWS S3', displayName: 'AWS S3',
@ -76,16 +77,16 @@ export class AwsS3 implements INodeType {
name: 'Bucket', name: 'Bucket',
value: 'bucket', value: 'bucket',
}, },
{
name: 'Folder',
value: 'folder',
},
{ {
name: 'File', name: 'File',
value: 'file', value: 'file',
}, },
{
name: 'Folder',
value: 'folder',
},
], ],
default: 'bucket', default: 'file',
description: 'The operation to perform.', description: 'The operation to perform.',
}, },
// BUCKET // BUCKET
@ -142,10 +143,16 @@ export class AwsS3 implements INodeType {
'$': { '$': {
xmlns: 'http://s3.amazonaws.com/doc/2006-03-01/', xmlns: 'http://s3.amazonaws.com/doc/2006-03-01/',
}, },
LocationConstraint: [credentials!.region],
} }
}; };
// For some reasons does AWS not allow to supply "us-east-1" if you want to
// create it there it has to be empty?!?!
if (credentials!.region !== 'us-east-1') {
// @ts-ignore
body.CreateBucketConfiguration.LocationConstraint = [credentials!.region];
}
const builder = new Builder(); const builder = new Builder();
const data = builder.buildObject(body); const data = builder.buildObject(body);

View file

@ -41,7 +41,7 @@ export const fileOperations = [
description: 'Upload a file', description: 'Upload a file',
}, },
], ],
default: 'copy', default: 'download',
description: 'The operation to perform.', description: 'The operation to perform.',
}, },
] as INodeProperties[]; ] as INodeProperties[];

View file

@ -1,14 +1,18 @@
import { import {
sign, sign,
} from 'aws4'; } from 'aws4';
import {
get,
} from 'lodash';
import { import {
OptionsWithUri, OptionsWithUri,
} from 'request'; } from 'request';
import { import {
parseString, parseString,
} from 'xml2js'; } from 'xml2js';
import { import {
IExecuteFunctions, IExecuteFunctions,
@ -21,10 +25,6 @@ import {
IDataObject, IDataObject,
} from 'n8n-workflow'; } from 'n8n-workflow';
import {
get,
} from 'lodash';
export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions, service: string, method: string, path: string, body?: string | Buffer, query: IDataObject = {}, headers?: object, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions, service: string, method: string, path: string, body?: string | Buffer, query: IDataObject = {}, headers?: object, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const credentials = this.getCredentials('aws'); const credentials = this.getCredentials('aws');
if (credentials === undefined) { if (credentials === undefined) {