Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
removes IAM filtering from accounts, updates docs
Browse files Browse the repository at this point in the history
  • Loading branch information
brianantonelli committed Apr 25, 2017
1 parent 28db4dd commit 84ffa8f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 36 deletions.
24 changes: 8 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Build Status](https://travis-ci.org/Cox-Automotive/alks-node.svg?branch=master)](https://travis-ci.org/Cox-Automotive/alks-node)

## About
Node client for interfacting with the [ALKS](https://github.com/Cox-Automotive/ALKS) services.
Node client for interfacting with ALKS services.

## Usage

Expand All @@ -23,17 +23,9 @@ Returns array of valid session durations.
alks.getDurations();
```

### getAccountSelectorDelimiter()

Returns string dilimeter used for account/role seperation.

```js
alks.getAccountSelectorDelimiter();
```

## Methods

### createKey(account, password, duration, callback)
### createKey(account, password, duration, options, callback)

Creates a new session key with the provided information. Returns a JSON document.

Expand All @@ -55,16 +47,16 @@ alks.createKey(data, 'password', 2, function(err, key){

### getAccounts(server, userid, password, options, callback)

Returns a collection of accounts. Options filter allows you to switch between IAM and non-IAM accounts.
Returns a collection of accounts.

```js
alks.getAccounts('server', 'username', 'password', {filters: { iamOnly: false }}, function(err, accounts){
alks.getAccounts('server', 'username', 'password', {}, function(err, accounts){
if(err) console.error(err);
else console.log(JSON.stringify(accounts));
});
```

### generateConsoleUrl(key, callback)
### generateConsoleUrl(key, options, callback)

Returns a AWS console URL for a given key. The URL is good for 15 minutes.

Expand All @@ -75,14 +67,14 @@ alks.generateConsoleUrl(alksKey, function(err, url){
});
```

### getIamRoleTypes(server, userid, password, callback)
### getIamRoleTypes(server, userid, password, options, callback)

Returns a list of current IAM role types.

### createIamKey(account, password, callback)
### createIamKey(account, password, options, callback)

Generates a new session for use in creating IAM roles and console sessions.

### createIamRole(account, password, roleName, roleType, includeDefaultPolicies, callback)
### createIamRole(account, password, roleName, roleType, includeDefaultPolicies, options, callback)

Creates a new IAM role, provided account must contain valid ALKS IAM session.
32 changes: 13 additions & 19 deletions lib/alks-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var _ = require('underscore'),
var exports = module.exports = {};

var ALKS_DURATIONS = [ 2, 6, 12, 18 ], // reducing due to EB not honoring long sessions: , 24, 36 ],
ACCOUNT_SELECTION_DELIMITER = ' :: ',
AWS_SIGNIN_URL = 'https://signin.aws.amazon.com/federation',
AWS_CONSOLE_URL = 'https://console.aws.amazon.com/',
SANITIZE_FIELDS = [ 'password' ],
Expand All @@ -18,10 +17,6 @@ exports.getDurations = function(){
return ALKS_DURATIONS;
};

exports.getAccountSelectorDelimiter = function(){
return ACCOUNT_SELECTION_DELIMITER;
};

var getMessageFromBadResponse = function(results){
if(results.body){
if(results.body.statusMessage){
Expand Down Expand Up @@ -178,7 +173,6 @@ exports.createIamRole = function(account, password, roleName, roleType, includeD
exports.getAccounts = function(server, userid, password, opts, callback){
var payload = { userid: userid, password: password },
options = _.extend({
filters: {},
debug: false,
ua: DEFAULT_UA
}, opts),
Expand Down Expand Up @@ -206,28 +200,28 @@ exports.getAccounts = function(server, userid, password, opts, callback){

// new API style to support IAM
if(results.body.accountListRole){
var accountRolesFitlered = {};
_.each(results.body.accountListRole, function(role, acct){
if((options.filters.iamOnly && !role[0].iamKeyActive)
|| (!options.filters.iamOnly && role[0].iamKeyActive)){
return;
}
accountRolesFitlered[acct] = role;
});

var accounts = [];
_.each(accountRolesFitlered, function(role, acct){
accounts.push([acct, role[0].role].join(ACCOUNT_SELECTION_DELIMITER));

_.each(results.body.accountListRole, function(role, acct){
accounts.push({
account: acct,
role: role[0].role,
iam: role[0].iamKeyActive
});
});
}
// v1 API style without IAM
else{
_.each(results.body.accountRoles, function(role, acct){
accounts.push([acct, role[0]].join(ACCOUNT_SELECTION_DELIMITER));
accounts.push({
account: acct,
role: role[0],
iam: false
});
});
}

accounts = _.sortBy(accounts, function(account){ return account; });
accounts = _.sortBy(accounts, function(account){ return account.account; });

callback(null, accounts);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alks-node",
"version": "0.3.1",
"version": "0.4.0",
"description": "Node client for ALKS",
"main": "lib/alks-api.js",
"scripts": {
Expand Down

0 comments on commit 84ffa8f

Please sign in to comment.