UNPKG

briareus

Version:

Briareus assists with Feature Branch deploys to ECS

48 lines (38 loc) 1.46 kB
'use strict' const AWS = require('aws-sdk'); const async = require('async'); const _ = require('lodash'); const config = require('../config'); let action = module.exports = function (pipeline, payload, cb) { const elbv2 = new AWS.ELBv2(); // Return if we have no ACM Certificate if (!payload.assets.acmCertificate) return cb(null, []); const attemptLimit = 10; let attempts = 0; function waitUntilCertificateIsDetached(cb) { elbv2.describeListenerCertificates({ ListenerArn: payload.alb.listenerArn, PageSize: 100 }, function (err, data) { if (err) return cb(err); if (_.some(data.Certificates, ['CertificateArn', payload.assets.acmCertificate.arn])) { if (attempts >= attemptLimit) return cb(new Error('Timeout occured waiting for the ACM Certificate to detatch from the Load Balancer')) setTimeout(() => waitUntilCertificateIsDetached(cb), config.get('awsApiPollingTimeout')); return; } cb(); }); } const params = { Certificates: [{ CertificateArn: payload.assets.acmCertificate.arn, }], ListenerArn: payload.alb.listenerArn }; async.series([ (next) => elbv2.removeListenerCertificates(params, next), (next) => waitUntilCertificateIsDetached(next) ], (err) => { if (err) return cb(err); cb(null, []); }); }; action.waiting = 'Removing ACM Certifcate from ALB Listener'; action.done = 'ACM Certifcate has been removed from ALB Listener';