@f5devcentral/f5-cloud-libs-aws
Advanced tools
Comparing version 2.0.3 to 2.1.0
@@ -22,2 +22,3 @@ /** | ||
const path = require('path'); | ||
const crypto = require('crypto'); | ||
@@ -40,2 +41,3 @@ 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; | ||
@@ -136,15 +138,37 @@ | ||
.then((response) => { | ||
this.nodeProperties.mgmtIp = response.privateIp; | ||
this.nodeProperties.privateIp = response.privateIp; | ||
this.nodeProperties.instanceId = response.instanceId; | ||
this.nodeProperties.region = response.region; | ||
if (response) { | ||
this.nodeProperties.mgmtIp = response.privateIp; | ||
this.nodeProperties.privateIp = response.privateIp; | ||
this.nodeProperties.instanceId = response.instanceId; | ||
this.nodeProperties.region = response.region; | ||
} | ||
if (!this.providerOptions.region && !this.nodeProperties.region) { | ||
const message = 'No region found in provider options or iid doc'; | ||
return q.reject(new Error(message)); | ||
} | ||
Aws.config.update({ region: this.providerOptions.region || this.nodeProperties.region }); | ||
Aws.config.update(AWS_RETRY_OPTIONS); | ||
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)); | ||
}); | ||
} | ||
Aws.config.credentials = new Aws.EC2MetadataCredentials(AWS_RETRY_OPTIONS); | ||
if ( | ||
this.providerOptions.roleArn && | ||
!(this.providerOptions.roleArn === "''" || this.providerOptions.roleArn === '""') | ||
) { | ||
return q(); | ||
}) | ||
.then(() => { | ||
if (this.providerOptions.roleArn | ||
&& !(this.providerOptions.roleArn === "''" || this.providerOptions.roleArn === '""')) { | ||
return getTemporaryCredentials(this.providerOptions, this.nodeProperties.instanceId); | ||
@@ -1206,7 +1230,18 @@ } | ||
fs.readFile(filename, (err, data) => { | ||
if (err) { | ||
deferred.reject(err); | ||
fs.stat(filename, (fsStatErr) => { | ||
if (fsStatErr && fsStatErr.code === 'ENOENT') { | ||
logger.debug('No iid doc found'); | ||
deferred.resolve({}); | ||
} else if (fsStatErr) { | ||
const message = `Error reading iid doc: ${fsStatErr.code}`; | ||
logger.info(message); | ||
deferred.reject(new Error(message)); | ||
} else { | ||
deferred.resolve(JSON.parse(data.toString())); | ||
fs.readFile(filename, (err, data) => { | ||
if (err) { | ||
deferred.reject(err); | ||
} else { | ||
deferred.resolve(JSON.parse(data.toString())); | ||
} | ||
}); | ||
} | ||
@@ -1644,2 +1679,15 @@ }); | ||
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.0.3", | ||
"version": "2.1.0", | ||
"description": "AWS implementation of f5-cloud-libs cloud provider code", | ||
@@ -25,3 +25,3 @@ "keywords": [ | ||
"peerDependencies": { | ||
"@f5devcentral/f5-cloud-libs": "^4.1.0-beta.1" | ||
"@f5devcentral/f5-cloud-libs": "^4.2.0-beta.1" | ||
}, | ||
@@ -28,0 +28,0 @@ "devDependencies": { |
@@ -41,2 +41,5 @@ /** | ||
let fsReadFile; | ||
let fsStat; | ||
let iidDoc; | ||
@@ -73,2 +76,5 @@ let instances; | ||
fsReadFile = fsMock.readFile; | ||
fsStat = fsMock.stat; | ||
awsMock.config = { | ||
@@ -95,2 +101,5 @@ configUpdate: {}, | ||
tearDown(callback) { | ||
fsMock.readFile = fsReadFile; | ||
fsMock.stat = fsStat; | ||
Object.keys(require.cache).forEach((key) => { | ||
@@ -153,3 +162,3 @@ delete require.cache[key]; | ||
fsMock.readFile = function modify(filename, cb) { | ||
fsMock.readFile = function readFile(filename, cb) { | ||
let data; | ||
@@ -167,2 +176,5 @@ | ||
}; | ||
fsMock.stat = function stat(filename, cb) { | ||
cb(null); | ||
}; | ||
@@ -224,2 +236,3 @@ callback(); | ||
}; | ||
providerOptions.region = 'foo'; | ||
callback(); | ||
@@ -226,0 +239,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
297560
15
8096