@f5devcentral/f5-cloud-libs-aws
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -22,3 +22,2 @@ /** | ||
const path = require('path'); | ||
const crypto = require('crypto'); | ||
@@ -41,3 +40,2 @@ const Aws = require('aws-sdk'); | ||
const cryptoUtil = require('@f5devcentral/f5-cloud-libs').cryptoUtil; | ||
const localCryptoUtil = require('@f5devcentral/f5-cloud-libs').localCryptoUtil; | ||
const KEYS = require('@f5devcentral/f5-cloud-libs').sharedConstants.KEYS; | ||
@@ -101,11 +99,15 @@ | ||
* | ||
* @param {Object} providerOptions - Provider specific options. | ||
* @param {String} providerOptions.s3Bucket - S3 bucket to use for storage. | ||
* @param {String} providerOptions.sqsUrl - SQS queue name. | ||
* @param {Number} [providerOptions.mgmtPort] - BIG-IP management port. Default 443. | ||
* @param {String} [providerOptions.roleArn] - ARN of role to assume. | ||
* @param {String} [providerOptions.externalId] - External Id for role to assume. | ||
* @param {Object} [options] - Options for this instance. | ||
* @param {Boolean} [options.autoscale] - Whether or not this instance will | ||
* be used for autoscaling. | ||
* @param {Object} providerOptions - Provider specific options. | ||
* @param {String} providerOptions.s3Bucket - S3 bucket to use for storage. | ||
* @param {String} providerOptions.sqsUrl - SQS queue name. | ||
* @param {Number} [providerOptions.mgmtPort] - BIG-IP management port. Default 443. | ||
* @param {String} [providerOptions.roleArn] - ARN of role to assume. | ||
* @param {String} [providerOptions.externalId] - External Id for role to assume. | ||
* @param {String} [providerOptions.accessKeyId] - AWS access key id. Required if BIG-IP is | ||
* not running in AWS. | ||
* @param {String} [providerOptions.secret] - AWS secret access key. | ||
* Required if BIG-IP is not running in AWS. | ||
* @param {Object} [options] - Options for this instance. | ||
* @param {Boolean} [options.autoscale] - Whether or not this instance will | ||
* be used for autoscaling. | ||
* | ||
@@ -154,17 +156,8 @@ * @returns {Promise} A promise which will be resolved when init is complete. | ||
if (this.providerOptions.secretId && this.providerOptions.accessKeyId) { | ||
return getSecret(this.providerOptions.secretId, this.providerOptions.accessKeyId) | ||
.then((secretAccessKey) => { | ||
Aws.config.credentials = | ||
new Aws.Credentials(this.providerOptions.accessKeyId, secretAccessKey); | ||
return q(); | ||
}) | ||
.catch((err) => { | ||
const message = (`Error retrieving secret access key: ${err}`); | ||
this.logger.info(message); | ||
return q.reject(new Error(message)); | ||
}); | ||
if (this.providerOptions.secret && this.providerOptions.accessKeyId) { | ||
Aws.config.credentials = | ||
new Aws.Credentials(this.providerOptions.accessKeyId, this.providerOptions.secret); | ||
} else { | ||
Aws.config.credentials = new Aws.EC2MetadataCredentials(AWS_RETRY_OPTIONS); | ||
} | ||
Aws.config.credentials = new Aws.EC2MetadataCredentials(AWS_RETRY_OPTIONS); | ||
return q(); | ||
@@ -375,2 +368,5 @@ }) | ||
* } | ||
* | ||
* Unfortunately it is not possible to set the hostname here as the hostname may not match the private DNS | ||
* name based on VPC settings. | ||
*/ | ||
@@ -481,4 +477,3 @@ AwsAutoscaleProvider.prototype.getInstances = function getInstances(options) { | ||
.setPublicIp(instance.PublicIpAddress) | ||
.setMgmtIp(instance.PrivateIpAddress) | ||
.setHostname(instance.PrivateDnsName); | ||
.setMgmtIp(instance.PrivateIpAddress); | ||
instances[instance.InstanceId] = autoscaleInstance; | ||
@@ -1270,2 +1265,6 @@ }); | ||
* @param {String} [autoscaleGroupId] - Limit to just this autoscale group Id | ||
* | ||
* @returns {Promise} A promise which is resolved with all of the autoscale groups | ||
* for this account (or autoscaleGroupId) or rejected if an | ||
* error occurs | ||
*/ | ||
@@ -1276,2 +1275,4 @@ function getAutoscalingGroups(autoscaling, autoscaleGroupId) { | ||
const accumulatedResults = []; | ||
if (autoscaleGroupId) { | ||
@@ -1281,10 +1282,29 @@ params.AutoScalingGroupNames = [autoscaleGroupId]; | ||
autoscaling.describeAutoScalingGroups(params, (err, data) => { | ||
if (err) { | ||
deferred.reject(err); | ||
} else { | ||
deferred.resolve(data.AutoScalingGroups); | ||
const accumulateResults = function accumulateResults(data) { | ||
data.AutoScalingGroups.forEach((autoscalingGroup) => { | ||
accumulatedResults.push(autoscalingGroup); | ||
}); | ||
}; | ||
const getNextSet = function getNextSet(nextToken) { | ||
if (nextToken) { | ||
params.NextToken = nextToken; | ||
} | ||
}); | ||
autoscaling.describeAutoScalingGroups(params, (err, data) => { | ||
if (err) { | ||
deferred.reject(err); | ||
} else { | ||
accumulateResults(data); | ||
if (data.NextToken) { | ||
getNextSet(data.NextToken); | ||
} else { | ||
deferred.resolve(accumulatedResults); | ||
} | ||
} | ||
}); | ||
}; | ||
getNextSet(); | ||
return deferred.promise; | ||
@@ -1684,15 +1704,2 @@ } | ||
function getSecret(secretId, accessKeyId) { | ||
const hash = crypto.createHash('sha512'); | ||
hash.update(accessKeyId); | ||
return localCryptoUtil.decryptDataFromRestStorage(secretId, hash.digest('hex')) | ||
.then((data) => { | ||
return data.secretAccessKey; | ||
}) | ||
.catch((err) => { | ||
logger.info('Error getting secret', err && err.message ? err.message : err); | ||
return q.reject(err); | ||
}); | ||
} | ||
module.exports = AwsAutoscaleProvider; |
{ | ||
"name": "@f5devcentral/f5-cloud-libs-aws", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "AWS implementation of f5-cloud-libs cloud provider code", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -304,2 +304,110 @@ /** | ||
} | ||
}, | ||
testAutoscale: { | ||
testInstanceMaps(test) { | ||
const nextToken = 'this is the next token'; | ||
const g1Instances = [ | ||
{ | ||
InstanceId: 'g1id1', | ||
LifecycleState: 'InService', | ||
LaunchConfigurationName: 'launchConfig1' | ||
}, | ||
{ | ||
InstanceId: 'g1id2', | ||
LifecycleState: 'InService', | ||
LaunchConfigurationName: 'launchConfig1' | ||
} | ||
]; | ||
const g2Instances = [ | ||
{ | ||
InstanceId: 'g2id1', | ||
LifecycleState: 'InService', | ||
LaunchConfigurationName: 'launchConfig2' | ||
}, | ||
{ | ||
InstanceId: 'g2id2', | ||
LifecycleState: 'InService', | ||
LaunchConfigurationName: 'launchConfig2' | ||
} | ||
]; | ||
awsMock.AutoScaling.prototype.describeAutoScalingGroups | ||
= function describeAutoScalingGroups(params, cb) { | ||
let data; | ||
if (!params.NextToken) { | ||
data = { | ||
NextToken: nextToken, | ||
AutoScalingGroups: [ | ||
{ | ||
AutoScalingGroupName: 'group1', | ||
Instances: g1Instances, | ||
Tags: [ | ||
{ | ||
Key: 'aws:cloudformation:stack-id', | ||
Value: 'stack1' | ||
} | ||
] | ||
} | ||
] | ||
}; | ||
} else if (params.NextToken === nextToken) { | ||
data = { | ||
AutoScalingGroups: [ | ||
{ | ||
AutoScalingGroupName: 'group2', | ||
Instances: g2Instances, | ||
Tags: [ | ||
{ | ||
Key: 'aws:cloudformation:stack-id', | ||
Value: 'stack2' | ||
} | ||
] | ||
} | ||
] | ||
}; | ||
} | ||
cb(null, data); | ||
}; | ||
test.expect(3); | ||
provider.init(providerOptions, { autoscale: true }) | ||
.then(() => { | ||
test.deepEqual( | ||
provider.instanceIdToAutoscaleGroupMap, | ||
{ | ||
g1id1: 'group1', | ||
g1id2: 'group1', | ||
g2id1: 'group2', | ||
g2id2: 'group2' | ||
} | ||
); | ||
test.deepEqual( | ||
provider.instanceIdToLaunchConfigMap, | ||
{ | ||
g1id1: 'launchConfig1', | ||
g1id2: 'launchConfig1', | ||
g2id1: 'launchConfig2', | ||
g2id2: 'launchConfig2' | ||
} | ||
); | ||
test.deepEqual( | ||
provider.stackIdToInstanceMap, | ||
{ | ||
stack1: g1Instances, | ||
stack2: g2Instances | ||
} | ||
); | ||
}) | ||
.catch((err) => { | ||
test.ok(false, err.message); | ||
}) | ||
.finally(() => { | ||
test.done(); | ||
}); | ||
} | ||
} | ||
@@ -620,4 +728,3 @@ }, | ||
PublicIpAddress: '111.222.333.444', | ||
PrivateIpAddress: '7.8.9.0', | ||
PrivateDnsName: 'missingHostname3' | ||
PrivateIpAddress: '7.8.9.0' | ||
} | ||
@@ -637,3 +744,2 @@ ] | ||
test.strictEqual(returnedInstances.id3.isMaster, false); | ||
test.strictEqual(returnedInstances.id3.hostname, 'missingHostname3'); | ||
test.strictEqual(returnedInstances.id3.mgmtIp, '7.8.9.0'); | ||
@@ -640,0 +746,0 @@ test.strictEqual(returnedInstances.id3.privateIp, '7.8.9.0'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
301972
8200