2022-10-07 06:07:38 -07:00
|
|
|
import { IExecuteFunctions } from 'n8n-core';
|
|
|
|
|
|
|
|
import {
|
|
|
|
IDataObject,
|
|
|
|
ILoadOptionsFunctions,
|
|
|
|
INodeExecutionData,
|
|
|
|
INodePropertyOptions,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
|
|
|
JsonObject,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
import { awsApiRequestSOAP, awsApiRequestSOAPAllItems } from './GenericFunctions';
|
|
|
|
|
|
|
|
import { loadBalancerFields, loadBalancerOperations } from './LoadBalancerDescription';
|
|
|
|
|
|
|
|
import {
|
|
|
|
listenerCertificateFields,
|
|
|
|
listenerCertificateOperations,
|
|
|
|
} from './ListenerCertificateDescription';
|
|
|
|
|
|
|
|
export class AwsElb implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'AWS ELB',
|
|
|
|
name: 'awsElb',
|
|
|
|
icon: 'file:elb.svg',
|
|
|
|
group: ['output'],
|
|
|
|
version: 1,
|
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
|
|
description: 'Sends data to AWS ELB API',
|
|
|
|
defaults: {
|
|
|
|
name: 'AWS ELB',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'aws',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
|
|
|
noDataExpression: true,
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Listener Certificate',
|
|
|
|
value: 'listenerCertificate',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Load Balancer',
|
|
|
|
value: 'loadBalancer',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'loadBalancer',
|
|
|
|
},
|
|
|
|
...loadBalancerOperations,
|
|
|
|
...loadBalancerFields,
|
|
|
|
|
|
|
|
...listenerCertificateOperations,
|
|
|
|
...listenerCertificateFields,
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
methods = {
|
|
|
|
loadOptions: {
|
|
|
|
async getLoadBalancers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
|
|
|
|
const params = ['Version=2015-12-01'];
|
|
|
|
|
|
|
|
const data = await awsApiRequestSOAP.call(
|
|
|
|
this,
|
|
|
|
'elasticloadbalancing',
|
|
|
|
'GET',
|
|
|
|
'/?Action=DescribeLoadBalancers&' + params.join('&'),
|
|
|
|
);
|
|
|
|
|
|
|
|
let loadBalancers =
|
|
|
|
data.DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member;
|
|
|
|
|
|
|
|
if (!Array.isArray(loadBalancers)) {
|
|
|
|
loadBalancers = [loadBalancers];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const loadBalancer of loadBalancers) {
|
|
|
|
const loadBalancerArn = loadBalancer.LoadBalancerArn as string;
|
|
|
|
|
|
|
|
const loadBalancerName = loadBalancer.LoadBalancerName as string;
|
|
|
|
|
|
|
|
returnData.push({
|
|
|
|
name: loadBalancerName,
|
|
|
|
value: loadBalancerArn,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
|
|
|
|
async getLoadBalancerListeners(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
|
|
|
|
const loadBalancerId = this.getCurrentNodeParameter('loadBalancerId') as string;
|
|
|
|
|
|
|
|
const params = ['Version=2015-12-01', 'LoadBalancerArn=' + loadBalancerId];
|
|
|
|
|
|
|
|
const data = await awsApiRequestSOAP.call(
|
|
|
|
this,
|
|
|
|
'elasticloadbalancing',
|
|
|
|
'GET',
|
|
|
|
'/?Action=DescribeListeners&' + params.join('&'),
|
|
|
|
);
|
|
|
|
|
|
|
|
let listeners = data.DescribeListenersResponse.DescribeListenersResult.Listeners.member;
|
|
|
|
|
|
|
|
if (!Array.isArray(listeners)) {
|
|
|
|
listeners = [listeners];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const listener of listeners) {
|
|
|
|
const listenerArn = listener.ListenerArn as string;
|
|
|
|
|
|
|
|
const listenerName = listener.ListenerArn as string;
|
|
|
|
|
|
|
|
returnData.push({
|
|
|
|
name: listenerArn,
|
|
|
|
value: listenerName,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
|
|
|
|
async getSecurityGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
|
|
|
|
const body = ['Version=2016-11-15', 'Action=DescribeSecurityGroups'].join('&');
|
|
|
|
|
|
|
|
const data = await awsApiRequestSOAP.call(
|
|
|
|
this,
|
|
|
|
'ec2',
|
|
|
|
'POST',
|
|
|
|
'/',
|
|
|
|
body,
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
charset: 'utf-8',
|
|
|
|
'User-Agent': 'aws-cli/1.18.124',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
let securityGroups = data.DescribeSecurityGroupsResponse.securityGroupInfo.item;
|
|
|
|
|
|
|
|
if (!Array.isArray(securityGroups)) {
|
|
|
|
securityGroups = [securityGroups];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const securityGroup of securityGroups) {
|
|
|
|
const securityGroupId = securityGroup.groupId as string;
|
|
|
|
|
|
|
|
const securityGroupName = securityGroup.groupName as string;
|
|
|
|
|
|
|
|
returnData.push({
|
|
|
|
name: securityGroupName,
|
|
|
|
value: securityGroupId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
|
|
|
|
async getSubnets(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
|
|
|
|
const body = ['Version=2016-11-15', 'Action=DescribeSubnets'].join('&');
|
|
|
|
|
|
|
|
const data = await awsApiRequestSOAP.call(
|
|
|
|
this,
|
|
|
|
'ec2',
|
|
|
|
'POST',
|
|
|
|
'/',
|
|
|
|
body,
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
charset: 'utf-8',
|
|
|
|
'User-Agent': 'aws-cli/1.18.124',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
let subnets = data.DescribeSubnetsResponse.subnetSet.item;
|
|
|
|
|
|
|
|
if (!Array.isArray(subnets)) {
|
|
|
|
subnets = [subnets];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const subnet of subnets) {
|
|
|
|
const subnetId = subnet.subnetId as string;
|
|
|
|
|
|
|
|
const subnetName = subnet.subnetId as string;
|
|
|
|
|
|
|
|
returnData.push({
|
|
|
|
name: subnetName,
|
|
|
|
value: subnetId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
|
|
|
const returnData: IDataObject[] = [];
|
|
|
|
let responseData;
|
2022-12-02 03:53:59 -08:00
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2022-10-07 06:07:38 -07:00
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
try {
|
|
|
|
if (resource === 'listenerCertificate') {
|
|
|
|
//https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_AddListenerCertificates.html
|
|
|
|
if (operation === 'add') {
|
|
|
|
const params = ['Version=2015-12-01'];
|
|
|
|
|
|
|
|
params.push(
|
2023-01-13 09:11:56 -08:00
|
|
|
'Certificates.member.1.CertificateArn=' +
|
|
|
|
(this.getNodeParameter('certificateId', i) as string),
|
2022-10-07 06:07:38 -07:00
|
|
|
);
|
|
|
|
|
2023-01-13 09:11:56 -08:00
|
|
|
params.push('ListenerArn=' + (this.getNodeParameter('listenerId', i) as string));
|
2022-10-07 06:07:38 -07:00
|
|
|
|
|
|
|
responseData = await awsApiRequestSOAP.call(
|
|
|
|
this,
|
|
|
|
'elasticloadbalancing',
|
|
|
|
'GET',
|
|
|
|
'/?Action=AddListenerCertificates&' + params.join('&'),
|
|
|
|
);
|
|
|
|
|
|
|
|
responseData =
|
|
|
|
responseData.AddListenerCertificatesResponse.AddListenerCertificatesResult
|
|
|
|
.Certificates.member;
|
|
|
|
}
|
|
|
|
|
|
|
|
//https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_DescribeListenerCertificates.html
|
|
|
|
if (operation === 'getMany') {
|
|
|
|
const params = ['Version=2015-12-01'];
|
|
|
|
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', 0);
|
2022-10-07 06:07:38 -07:00
|
|
|
|
|
|
|
const listenerId = this.getNodeParameter('listenerId', i) as string;
|
|
|
|
|
|
|
|
params.push(`ListenerArn=${listenerId}`);
|
|
|
|
|
|
|
|
if (returnAll) {
|
|
|
|
responseData = await awsApiRequestSOAPAllItems.call(
|
|
|
|
this,
|
|
|
|
'DescribeListenerCertificatesResponse.DescribeListenerCertificatesResult.Certificates.member',
|
|
|
|
'elasticloadbalancing',
|
|
|
|
'GET',
|
|
|
|
'/?Action=DescribeListenerCertificates&' + params.join('&'),
|
|
|
|
);
|
|
|
|
} else {
|
2023-01-13 09:11:56 -08:00
|
|
|
params.push('PageSize=' + (this.getNodeParameter('limit', 0) as unknown as string));
|
2022-10-07 06:07:38 -07:00
|
|
|
|
|
|
|
responseData = await awsApiRequestSOAP.call(
|
|
|
|
this,
|
|
|
|
'elasticloadbalancing',
|
|
|
|
'GET',
|
|
|
|
'/?Action=DescribeListenerCertificates&' + params.join('&'),
|
|
|
|
);
|
|
|
|
|
|
|
|
responseData =
|
|
|
|
responseData.DescribeListenerCertificatesResponse.DescribeListenerCertificatesResult
|
|
|
|
.Certificates.member;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_RemoveListenerCertificates.html
|
|
|
|
if (operation === 'remove') {
|
|
|
|
const params = ['Version=2015-12-01'];
|
|
|
|
|
|
|
|
params.push(
|
2023-01-13 09:11:56 -08:00
|
|
|
'Certificates.member.1.CertificateArn=' +
|
|
|
|
(this.getNodeParameter('certificateId', i) as string),
|
2022-10-07 06:07:38 -07:00
|
|
|
);
|
|
|
|
|
2023-01-13 09:11:56 -08:00
|
|
|
params.push('ListenerArn=' + (this.getNodeParameter('listenerId', i) as string));
|
2022-10-07 06:07:38 -07:00
|
|
|
|
|
|
|
responseData = await awsApiRequestSOAP.call(
|
|
|
|
this,
|
|
|
|
'elasticloadbalancing',
|
|
|
|
'GET',
|
|
|
|
'/?Action=RemoveListenerCertificates&' + params.join('&'),
|
|
|
|
);
|
|
|
|
|
|
|
|
responseData = { sucess: true };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource === 'loadBalancer') {
|
|
|
|
//https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_CreateLoadBalancer.html
|
|
|
|
if (operation === 'create') {
|
|
|
|
const ipAddressType = this.getNodeParameter('ipAddressType', i) as string;
|
|
|
|
|
|
|
|
const name = this.getNodeParameter('name', i) as string;
|
|
|
|
|
|
|
|
const schema = this.getNodeParameter('schema', i) as string;
|
|
|
|
|
|
|
|
const type = this.getNodeParameter('type', i) as string;
|
|
|
|
|
|
|
|
const subnets = this.getNodeParameter('subnets', i) as string[];
|
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2022-10-07 06:07:38 -07:00
|
|
|
|
|
|
|
const params = ['Version=2015-12-01'];
|
|
|
|
|
|
|
|
params.push(`IpAddressType=${ipAddressType}`);
|
|
|
|
|
|
|
|
params.push(`Name=${name}`);
|
|
|
|
|
|
|
|
params.push(`Scheme=${schema}`);
|
|
|
|
|
|
|
|
params.push(`Type=${type}`);
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
for (let index = 1; index <= subnets.length; index++) {
|
|
|
|
params.push(`Subnets.member.${index}=${subnets[index - 1]}`);
|
2022-10-07 06:07:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (additionalFields.securityGroups) {
|
|
|
|
const securityGroups = additionalFields.securityGroups as string[];
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
for (let index = 1; index <= securityGroups.length; index++) {
|
|
|
|
params.push(`SecurityGroups.member.${index}=${securityGroups[index - 1]}`);
|
2022-10-07 06:07:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (additionalFields.tagsUi) {
|
|
|
|
const tags = (additionalFields.tagsUi as IDataObject).tagValues as IDataObject[];
|
|
|
|
|
|
|
|
if (tags) {
|
2022-12-02 12:54:28 -08:00
|
|
|
for (let index = 1; index <= tags.length; index++) {
|
|
|
|
params.push(`Tags.member.${index}.Key=${tags[index - 1].key}`);
|
2022-10-07 06:07:38 -07:00
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
params.push(`Tags.member.${index}.Value=${tags[index - 1].value}`);
|
2022-10-07 06:07:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
responseData = await awsApiRequestSOAP.call(
|
|
|
|
this,
|
|
|
|
'elasticloadbalancing',
|
|
|
|
'GET',
|
|
|
|
'/?Action=CreateLoadBalancer&' + params.join('&'),
|
|
|
|
);
|
|
|
|
|
|
|
|
responseData =
|
|
|
|
responseData.CreateLoadBalancerResponse.CreateLoadBalancerResult.LoadBalancers.member;
|
|
|
|
}
|
|
|
|
|
|
|
|
//https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_DeleteLoadBalancer.html
|
|
|
|
if (operation === 'delete') {
|
|
|
|
const params = ['Version=2015-12-01'];
|
|
|
|
|
2023-01-13 09:11:56 -08:00
|
|
|
params.push(
|
|
|
|
'LoadBalancerArn=' + (this.getNodeParameter('loadBalancerId', i) as string),
|
|
|
|
);
|
2022-10-07 06:07:38 -07:00
|
|
|
|
|
|
|
responseData = await awsApiRequestSOAP.call(
|
|
|
|
this,
|
|
|
|
'elasticloadbalancing',
|
|
|
|
'GET',
|
|
|
|
'/?Action=DeleteLoadBalancer&' + params.join('&'),
|
|
|
|
);
|
|
|
|
|
|
|
|
responseData = { success: true };
|
|
|
|
}
|
|
|
|
|
|
|
|
//https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_DescribeLoadBalancers.html
|
|
|
|
if (operation === 'getMany') {
|
|
|
|
const params = ['Version=2015-12-01'];
|
|
|
|
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', 0);
|
2022-10-07 06:07:38 -07:00
|
|
|
|
|
|
|
if (returnAll) {
|
2022-11-18 07:29:44 -08:00
|
|
|
const filters = this.getNodeParameter('filters', i);
|
2022-10-07 06:07:38 -07:00
|
|
|
|
|
|
|
if (filters.names) {
|
|
|
|
const names = (filters.names as string).split(',');
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
for (let index = 1; index <= names.length; index++) {
|
|
|
|
params.push(`Names.member.${index}=${names[index - 1]}`);
|
2022-10-07 06:07:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
responseData = await awsApiRequestSOAPAllItems.call(
|
|
|
|
this,
|
|
|
|
'DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers.member',
|
|
|
|
'elasticloadbalancing',
|
|
|
|
'GET',
|
|
|
|
'/?Action=DescribeLoadBalancers&' + params.join('&'),
|
|
|
|
);
|
|
|
|
} else {
|
2023-01-13 09:11:56 -08:00
|
|
|
params.push('PageSize=' + this.getNodeParameter('limit', 0).toString());
|
2022-10-07 06:07:38 -07:00
|
|
|
|
|
|
|
responseData = await awsApiRequestSOAP.call(
|
|
|
|
this,
|
|
|
|
'elasticloadbalancing',
|
|
|
|
'GET',
|
|
|
|
'/?Action=DescribeLoadBalancers&' + params.join('&'),
|
|
|
|
);
|
|
|
|
|
|
|
|
responseData =
|
|
|
|
responseData.DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers
|
|
|
|
.member;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_DescribeLoadBalancers.html
|
|
|
|
if (operation === 'get') {
|
|
|
|
const params = ['Version=2015-12-01'];
|
|
|
|
|
2023-01-13 09:11:56 -08:00
|
|
|
params.push(
|
|
|
|
'LoadBalancerArns.member.1=' + (this.getNodeParameter('loadBalancerId', i) as string),
|
|
|
|
);
|
2022-10-07 06:07:38 -07:00
|
|
|
|
|
|
|
responseData = await awsApiRequestSOAP.call(
|
|
|
|
this,
|
|
|
|
'elasticloadbalancing',
|
|
|
|
'GET',
|
|
|
|
'/?Action=DescribeLoadBalancers&' + params.join('&'),
|
|
|
|
);
|
|
|
|
|
|
|
|
responseData =
|
|
|
|
responseData.DescribeLoadBalancersResponse.DescribeLoadBalancersResult.LoadBalancers
|
|
|
|
.member;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
returnData.push(
|
|
|
|
...this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), {
|
|
|
|
itemData: { item: i },
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
|
|
|
returnData.push({ error: (error as JsonObject).toString() });
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [returnData as INodeExecutionData[]];
|
|
|
|
}
|
|
|
|
}
|