Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

Hook into vault #1

Merged
merged 7 commits into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from 5 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
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:slim

MAINTAINER Team Lucretius

ADD package.json /tmp/package.json
RUN cd /tmp && npm install
RUN mkdir -p /app/ && cp -a /tmp/node_modules /app/

RUN npm install --silent -g webpack

ADD . /app
WORKDIR /app

RUN webpack && npm run build

EXPOSE 8000

CMD ["npm", "run", "serve"]
6 changes: 3 additions & 3 deletions app/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ injectTapEventPlugin();
window.CustomEvent = CustomEvent;
})();

const checkAuthToken = (nextState, replace, callback) => {
let vaultAuthToken = window.localStorage.getItem('vaultAuthenticationToken');
const checkAccessToken = (nextState, replace, callback) => {
let vaultAuthToken = window.localStorage.getItem('vaultAccessToken');
if (!vaultAuthToken) {
replace(`/login`)
}
Expand All @@ -41,7 +41,7 @@ ReactDOM.render((
<MuiThemeProvider muiTheme={muiTheme}>
<Router history={browserHistory}>
<Route path="/login" component={Login}/>
<Route path="/" component={Home} onEnter={checkAuthToken}>
<Route path="/" component={Home} onEnter={checkAccessToken}>
<Route path="*" component={Home}/>
</Route>
</Router>
Expand Down
24 changes: 22 additions & 2 deletions app/components/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Settings from 'material-ui/svg-icons/action/settings';
import Dialog from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';
import { browserHistory } from 'react-router';
import axios from 'axios';

export default class Login extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -40,12 +41,30 @@ export default class Login extends React.Component {

validateAuthToken(e) {
if (e.keyCode === 13) {
console.log(`Validating auth token: ${this.state.authToken}`);
if (!window.localStorage.getItem("vaultUrl")) {
this.setState({errorMessage: "No Vault url specified. Click the gear to edit your Vault url"});
return;
}
window.localStorage.setItem("vaultAuthenticationToken",this.state.authToken);
window.location.href = '/';
axios.post(
`${window.localStorage.getItem("vaultUrl")}/v1/auth/github/login`,
{ "token": this.state.authToken },
{ headers: {'Access-Control-Allow-Originh': '*', 'Content-Type': 'text/plain'}}
)
.then((data) => {
let accessToken = _.get(data, 'auth.client_token');
if(accessToken) {
window.localStorage.setItem("vaultAccessToken",accessToken);
console.log(`Fetched token: ${accessToken}`);
window.location.href = '/';
} else {
//No access token returned, error
}
})
.catch(() => {
//something went wrong
});

}
}

Expand Down Expand Up @@ -110,3 +129,4 @@ export default class Login extends React.Component {
);
}
}

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@
},
"dependencies": {
"axios": "^0.15.2",
"body-parser": "^1.15.2",
"copy-to-clipboard": "^3.0.5",
"express": "^4.14.0",
"lodash": "^4.16.6",
"material-ui": "^0.16.1",
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react-router": "^3.0.0",
"react-tap-event-plugin": "^1.0.0"
"react-tap-event-plugin": "^1.0.0",
"serve-favicon": "^2.3.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here about the favicon

}
}
29 changes: 29 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import express from 'express';
import bodyParser from 'body-parser';
import favicon from 'serve-favicon';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably dont need this favicon thing.


const PORT = 8000;

var app = express();

app.use('/assets', express.static('dist'));

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));

// parse application/json
app.use(bodyParser.json());

app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});

app.listen(PORT, () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually throw this line on the very bottom after I register all of my routes.

console.log(`Vault UI listening on: ${PORT}`);
});

app.get('*', function(req, res) {
res.render('index.html');
});