mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 04:47:29 -08:00
Remove aws-sdk dependency
This commit is contained in:
parent
39c0b08d9d
commit
0fcbe409b6
|
@ -8,9 +8,7 @@ import {
|
|||
IDataObject
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { awsApiRequest } from './GenericFunctions';
|
||||
|
||||
import { Lambda } from 'aws-sdk';
|
||||
import { awsApiRequestREST } from './GenericFunctions';
|
||||
|
||||
export class AwsLambda implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
|
@ -91,7 +89,7 @@ export class AwsLambda implements INodeType {
|
|||
async getFunctions(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
try {
|
||||
var data = await awsApiRequest.call(this, 'lambda', 'GET', '/2015-03-31/functions/');
|
||||
var data = await awsApiRequestREST.call(this, 'lambda', 'GET', '/2015-03-31/functions/');
|
||||
} catch (err) {
|
||||
throw new Error(`AWS Error: ${err}`);
|
||||
}
|
||||
|
@ -121,8 +119,7 @@ export class AwsLambda implements INodeType {
|
|||
};
|
||||
|
||||
try {
|
||||
|
||||
var responseData = await awsApiRequest.call(
|
||||
var responseData = await awsApiRequestREST.call(
|
||||
this,
|
||||
'lambda',
|
||||
'POST',
|
||||
|
|
|
@ -8,9 +8,7 @@ import {
|
|||
IDataObject
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { awsConfigCredentials } from './GenericFunctions';
|
||||
|
||||
import { SNS } from 'aws-sdk';
|
||||
import { awsApiRequestSOAP } from './GenericFunctions';
|
||||
|
||||
export class AwsSns implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
|
@ -51,6 +49,7 @@ export class AwsSns implements INodeType {
|
|||
name: 'subject',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
description: 'Subject when the message is delivered to email endpoints',
|
||||
},
|
||||
{
|
||||
|
@ -72,18 +71,15 @@ export class AwsSns implements INodeType {
|
|||
// Get all the available topics to display them to user so that he can
|
||||
// select them easily
|
||||
async getTopics(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
await awsConfigCredentials.call(this);
|
||||
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
|
||||
let sns = new SNS();
|
||||
try {
|
||||
var data = await sns.listTopics({}).promise();
|
||||
var data = await awsApiRequestSOAP.call(this, 'sns', 'GET', '/?Action=ListTopics');
|
||||
} catch (err) {
|
||||
throw new Error(`AWS Error: ${err}`);
|
||||
}
|
||||
|
||||
for (let topic of data.Topics!) {
|
||||
const topics = data.ListTopicsResponse.ListTopicsResult.Topics.member;
|
||||
for (let topic of topics) {
|
||||
let topicArn = topic.TopicArn as string;
|
||||
let topicName = topicArn.split(':')[5];
|
||||
|
||||
|
@ -102,22 +98,19 @@ export class AwsSns implements INodeType {
|
|||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
await awsConfigCredentials.call(this);
|
||||
const sns = new SNS();
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const params = {
|
||||
TopicArn: this.getNodeParameter('topic', i) as string,
|
||||
Subject: this.getNodeParameter('subject', i) as string,
|
||||
Message: this.getNodeParameter('message', i) as string,
|
||||
};
|
||||
const params = [
|
||||
'TopicArn=' + this.getNodeParameter('topic', i) as string,
|
||||
'Subject=' + this.getNodeParameter('subject', i) as string,
|
||||
'Message=' + this.getNodeParameter('message', i) as string,
|
||||
];
|
||||
|
||||
try {
|
||||
var responseData = await sns.publish(params).promise();
|
||||
var responseData = await awsApiRequestSOAP.call(this, 'sns', 'GET', '/?Action=Publish&' + params.join('&'));
|
||||
} catch (err) {
|
||||
throw new Error(`AWS Error: ${err}`);
|
||||
}
|
||||
returnData.push({MessageId: responseData.MessageId} as IDataObject);
|
||||
returnData.push({MessageId: responseData.PublishResponse.PublishResult.MessageId} as IDataObject);
|
||||
}
|
||||
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
|
|
|
@ -4,27 +4,12 @@ import {
|
|||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import { config } from 'aws-sdk';
|
||||
import { OptionsWithUri } from 'request';
|
||||
import { sign } from 'aws4';
|
||||
|
||||
export async function awsConfigCredentials(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions): Promise<void> {
|
||||
const credentials = this.getCredentials('aws');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
config.update({
|
||||
region: `${credentials.region}`,
|
||||
accessKeyId: `${credentials.accessKeyId}`,
|
||||
secretAccessKey: `${credentials.secretAccessKey}`,
|
||||
});
|
||||
}
|
||||
import { parseString } from 'xml2js';
|
||||
|
||||
export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, service: string, method: string, path: string, body?: string, headers?: object): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('aws');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
@ -42,9 +27,8 @@ export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | I
|
|||
body: signOpts.body,
|
||||
};
|
||||
|
||||
let response: string
|
||||
try {
|
||||
response = await this.helpers.request!(options);
|
||||
return await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
|
@ -57,12 +41,35 @@ export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | I
|
|||
}
|
||||
}
|
||||
|
||||
throw errorMessage;
|
||||
if (errorMessage !== undefined) {
|
||||
throw errorMessage;
|
||||
}
|
||||
throw error.response.body;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function awsApiRequestREST(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, service: string, method: string, path: string, body?: string, headers?: object): Promise<any> { // tslint:disable-line:no-any
|
||||
const response = await awsApiRequest.call(this, service, method, path, body, headers);
|
||||
try {
|
||||
return JSON.parse(response);
|
||||
} catch (e) {
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
export async function awsApiRequestSOAP(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, service: string, method: string, path: string, body?: string, headers?: object): Promise<any> { // tslint:disable-line:no-any
|
||||
const response = await awsApiRequest.call(this, service, method, path, body, headers);
|
||||
try {
|
||||
return await new Promise((resolve, reject) => {
|
||||
parseString(response, { explicitArray: false }, (err, data) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,7 +128,6 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"aws4": "^1.8.0",
|
||||
"aws-sdk": "^2.543.0",
|
||||
"basic-auth": "^2.0.1",
|
||||
"cron": "^1.6.0",
|
||||
"glob-promise": "^3.4.0",
|
||||
|
|
Loading…
Reference in a new issue