Skip to content

Commit

Permalink
Merge d605be5 into 4d4374c
Browse files Browse the repository at this point in the history
  • Loading branch information
davepgreene committed Jun 29, 2018
2 parents 4d4374c + d605be5 commit 8681611
Show file tree
Hide file tree
Showing 74 changed files with 5,497 additions and 1,252 deletions.
3 changes: 1 addition & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"parser":"babel-eslint",
"extends": "rapid7/base"
"extends": "react-app"
}
30 changes: 23 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
node_modules/
dist/
test/.aws/
*.log
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage
/test/.aws/
/test/data/test.json

# production
/build
/dist

# misc
.DS_Store
test/data/test.json
typings/
coverage/
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

19 changes: 6 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
language: node_js
env:
- CXX=g++-4.8
sudo: false
node_js:
- "node"
script:
- npm test
- npm run lint
- npm run cover
- yarn test
- yarn lint
- yarn cover
after_success:
npm run report
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- yarn report
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015-2016 Frank Mitchell, Rapid7 LLC.
Copyright (c) 2015-2018 Frank Mitchell, Rapid7 LLC.

MIT License
===========
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,31 +195,31 @@ the URL's valid, it will prompt you to login to your identity provider. If the
login's successful, you'll see temporary AWS credentials in the UI.

## Building
Awsaml is built using [Node][] version 7.4.0 and [Yarn][] version 1.3.2, so
Awsaml is built using [Node][] and [Yarn][], so
make sure you've got a compatible versions installed. Then run Yarn to install
dependencies and build Awsaml.

~~~bash
rm -rf node_modules/
yarn install
yarn run build
yarn build
~~~

Those commnds will create a "dist" folder with zipped binaries. If you only want
Those commands will create a "dist" folder with zipped binaries. If you only want
to create binaries for specific platforms, you can set a `PLATFORM` environment
variable before building.

~~~bash
export PLATFORM=linux
yarn run build
yarn build
~~~

Allowed values for `PLATFORM` are `darwin`, `linux` and `win32`. You can build
binaries for multiple platforms by using a comma separated list.

~~~bash
export PLATFORM=darwin,linux
yarn run build
yarn build
~~~

## Setup on OSX with Homebrew
Expand Down
4 changes: 3 additions & 1 deletion lib/auth.js → api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class Auth {
if (req.isAuthenticated()) {
return next();
}
res.redirect(options.entryPoint);
res.json({
redirect: options.entryPoint
});
};
}

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions lib/response.js → api/response.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

module.exports = {
title: 'Rapid7 - Awsaml',
platform: process.platform
Expand Down
8 changes: 5 additions & 3 deletions lib/routes/auth.js → api/routes/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

const url = require('url');
const express = require('express');
const router = express.Router();

Expand All @@ -16,7 +15,10 @@ module.exports = (app, auth) => {
req.session.passport.principalArn = arns[1];
req.session.passport.accountId = arns[0].split(':')[4]; // eslint-disable-line rapid7/static-magic-numbers
/* eslint-enable no-param-reassign */
res.redirect('/refresh');
let frontend = process.env.ELECTRON_START_URL || app.get('baseUrl');
frontend = new url.URL(frontend);
frontend.searchParams.set('auth', 'true');
res.redirect(frontend);
});

return router;
Expand Down
52 changes: 36 additions & 16 deletions lib/routes/configure.js → api/routes/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const router = express.Router();

const xmldom = require('xmldom');
const xpath = require('xpath.js');
const config = require('../../config');
const config = require('../config');

const HTTP_OK = 200;

Expand All @@ -16,21 +16,26 @@ const ResponseObj = require('./../response');

module.exports = (app, auth) => {
router.get('/', (req, res) => {
const storedMetadataUrls = Storage.get('metadataUrls') || {};
const storedMetadataUrls = Storage.get('metadataUrls') || [];

// We populate the value of the metadata url field on the following (in order of precedence):
// 1. Use the current session's metadata url (may have been rejected).
// 2. Use the latest validated metadata url.
// 3. Support the <= v1.3.0 storage key.
// 4. Default the metadata url to empty string.
const defaultMetadataUrl =
let defaultMetadataUrl =
app.get('metadataUrl') ||
Storage.get('previousMetadataUrl') ||
Storage.get('metadataUrl') ||
Object.keys(storedMetadataUrls)[0] ||
'';

res.render('configure', Object.assign(ResponseObj, {
if (!defaultMetadataUrl) {
if (storedMetadataUrls.length > 0 && storedMetadataUrls[0].hasOwnProperty('url')) {
defaultMetadataUrl = storedMetadataUrls[0].url;
}
}

res.json(Object.assign(ResponseObj, {
defaultMetadataUrl,
metadataUrls: storedMetadataUrls,
metadataUrlValid: Storage.get('metadataUrlValid'),
Expand All @@ -40,19 +45,25 @@ module.exports = (app, auth) => {

router.post('/', (req, res) => {
const metadataUrl = req.body.metadataUrl;
const origin = req.body.origin;
const metaDataResponseObj = Object.assign(ResponseObj, {defaultMetadataUrl: metadataUrl});

let storedMetadataUrls = Storage.get('metadataUrls') || {},
let storedMetadataUrls = Storage.get('metadataUrls') || [],
profileName = req.body.profileName;

const profile = storedMetadataUrls.find((profile) => profile.url === metadataUrl);

if (profileName === '') {
profileName = metadataUrl;
}

if (profileName && storedMetadataUrls[metadataUrl] && storedMetadataUrls[metadataUrl] !== profileName) {
storedMetadataUrls[metadataUrl] = profileName;
Storage.set(storedMetadataUrls);
}
storedMetadataUrls = storedMetadataUrls.map((p) => {
if (profileName && p.url === metadataUrl && p.name !== profileName) {
p.name = profileName;
}
return p;
});
Storage.set('metadataUrls', storedMetadataUrls);
app.set('metadataUrl', metadataUrl);

const xmlReq = https.get(metadataUrl, (xmlRes) => {
Expand All @@ -62,7 +73,7 @@ module.exports = (app, auth) => {
Storage.set('metadataUrlValid', false);
Storage.set('metadataUrlError', Errors.urlInvalidErr);

res.render('configure', Object.assign(metaDataResponseObj, {
res.json(Object.assign(metaDataResponseObj, {
metadataUrlValid: false,
error: Errors.urlInvalidErr
}));
Expand Down Expand Up @@ -110,24 +121,33 @@ module.exports = (app, auth) => {
Storage.set('previousMetadataUrl', metadataUrl);
let metadataUrls = Storage.get('metadataUrls') || {};

if (!metadataUrls.hasOwnProperty(metadataUrl)) {
metadataUrls[metadataUrl] = profileName || metadataUrl;
if (!profile) {
metadataUrls.push({
name: profileName || metadataUrl,
url: metadataUrl
});
Storage.set('metadataUrls', metadataUrls);
}

app.set('entryPointUrl', config.auth.entryPoint);
auth.configure(config.auth);
res.redirect(config.auth.entryPoint);
if (origin === 'electron') {
res.redirect(config.auth.entryPoint);
} else {
res.json({
redirect: config.auth.entryPoint
});
}
} else {
res.render('configure', Object.assign(metaDataResponseObj, {
res.json(Object.assign(metaDataResponseObj, {
error: Errors.invalidMetadataErr
}));
}
});
});

xmlReq.on('error', (err) => {
res.render('configure', Object.assign(metaDataResponseObj, {
res.json(Object.assign(metaDataResponseObj, {
error: err.message
}));
});
Expand Down
6 changes: 3 additions & 3 deletions lib/routes/logout.js → api/routes/logout.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

const express = require('express');
const router = express.Router();

module.exports = (app) => {
router.get('/', (req, res) => {
app.set('entryPointUrl', null);
req.session.destroy();
res.redirect(app.get('configureUrl'));
res.json({
logout: true
});
});

return router;
Expand Down
21 changes: 21 additions & 0 deletions api/routes/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const express = require('express');
const url = require('url');
const router = express.Router();

module.exports = () => {
router.delete('/', (req, res) => {
let {profile} = url.parse(req.url, true).query;
let idx = parseInt(profile, 10);

let metadataUrls = Storage.get('metadataUrls');
metadataUrls = metadataUrls.map((metadataUrl, i) => {
return (i !== idx) ? metadataUrl : null;
}).filter((el) => !!el);

Storage.set('metadataUrls', metadataUrls);

res.status(200).end();
});

return router;
};
27 changes: 18 additions & 9 deletions lib/routes/refresh.js → api/routes/refresh.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const express = require('express');
const router = express.Router();

const config = require('../../config');
const config = require('../config');

const Aws = require('aws-sdk');
const AwsCredentials = require('../../lib/aws-credentials');
const AwsCredentials = require('../aws-credentials');
const credentials = new AwsCredentials(config.aws);

const ResponseObj = require('./../response');
Expand All @@ -15,6 +15,9 @@ module.exports = (app) => {
const session = req.session.passport;

if (session === undefined) {
res.status(401).json({
error: 'Invalid session'
});
return;
}

Expand All @@ -29,7 +32,9 @@ module.exports = (app) => {
DurationSeconds: config.aws.duration
}, (assumeRoleErr, data) => {
if (assumeRoleErr) {
res.redirect(config.auth.entryPoint);
res.json({
redirect: config.auth.entryPoint
});

return;
}
Expand All @@ -45,17 +50,21 @@ module.exports = (app) => {
let metadataUrls = Storage.get('metadataUrls');

// If the stored metadataUrl label value is the same as the URL default to the profile name!
if (metadataUrls[metadataUrl] === metadataUrl) {
metadataUrls[metadataUrl] = profileName;
Storage.set('metadataUrls', metadataUrls);
}
res.render('refresh', credentialResponseObj);
metadataUrls = metadataUrls.map((p) => {
if (p.url === metadataUrl && p.name === metadataUrl) {
p.name = profileName;
}
return p;
});
Storage.set('metadataUrls', metadataUrls);

credentials.save(data.Credentials, profileName, (credSaveErr) => {
if (credSaveErr) {
res.render('refresh', Object.assign(credentialResponseObj, {
res.json(Object.assign(credentialResponseObj, {
error: credSaveErr
}));
} else {
res.json(credentialResponseObj);
}
});
});
Expand Down
11 changes: 11 additions & 0 deletions api/routes/static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const path = require('path');
const express = require('express');
const router = express.Router();

module.exports = () => {
router.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '/../../build/index.html'));
});

return router;
};
Loading

0 comments on commit 8681611

Please sign in to comment.