Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[src] updated for aws-cdk syntax #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const RESOURCES = [
'alert',
'beanstalkElastigroup',
'group',
'Group',
'healthCheck',
'mrScaler',
'spectrumAlert',
Expand All @@ -36,10 +37,21 @@ function getToken(event, cb) {
if(err) return cb("Token creation failed: " + err);
if(response.statusCode > 201) return cb("Token creation failed: " + response.statusMessage);

var accessToken = JSON.parse(body)['response']['items'][0]['accessToken'];
var accessToken;
var group = JSON.parse(body)['response']['items'][0];

if (group['AccessToken']) {
accessToken = group['AccessToken']
} else if (group['accessToken']) {
accessToken = group['accessToken']
}

cb(null, accessToken);
});
}
else if(config.AccessToken) {
cb(null, config.AccessToken);
}
else if(config.accessToken) {
cb(null, config.accessToken);
}
Expand Down Expand Up @@ -70,7 +82,6 @@ function addNulls(oldConfig, newConfig) {
diff.applyChange(patchConfig, oldConfig, patch);
}
});

return patchConfig;
}

Expand All @@ -92,6 +103,7 @@ function getConfig(event, cb) {
}
}
}

if(!config) {
var matchResourceConfig = _.intersection(_.keys(event), RESOURCES);
config = event[matchResourceConfig[0]];
Expand Down Expand Up @@ -214,10 +226,12 @@ module.exports.parseBoolean = function(str) {

module.exports.getSpotinstAccountId = function(event) {
console.log("acctId Full Event: " + JSON.stringify(event, null, 2));
var accountId = _.get(event, 'ResourceProperties.accountId') || _.get(event, 'accountId');
var accountId = _.get(event, 'ResourceProperties.AccountId') || _.get(event, 'AccountId')
|| _.get(event, 'ResourceProperties.accountId') || _.get(event, 'accountId');

if (!accountId) {
console.log(_.get(event, 'OldResourceProperties'));
accountId = _.get(event, 'OldResourceProperties.accountId');
accountId = _.get(event, 'OldResourceProperties.accountId') || _.get(event, 'OldResourceProperties.AccountId');
}
console.log('spotinst account id is: ', accountId);
return accountId;
Expand Down Expand Up @@ -726,12 +740,22 @@ module.exports.getTokenAsync = function(obj){
if(response.statusCode > 201) {
return reject("Token creation failed: " + response.statusMessage);
}

var accessToken = JSON.parse(body)['response']['items'][0]['accessToken'];

var accessToken;
var group = JSON.parse(body)['response']['items'][0];

if (group['AccessToken']) {
accessToken = group['AccessToken']
} else if (group['accessToken']) {
accessToken = group['accessToken']
}

return resolve(accessToken);
});
}
else if(config.AccessToken) {
return resolve(config.AccessToken);
}
else if(config.accessToken) {
return resolve(config.accessToken);
}
Expand Down