This repository has been archived by the owner on Mar 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate wrapping in generic secret backend
- Loading branch information
Matteo Sessa
committed
Feb 18, 2017
1 parent
21616a4
commit ac71bb6
Showing
10 changed files
with
232 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { PropTypes, Component } from 'react' | ||
import _ from 'lodash'; | ||
import { callVaultApi } from '../VaultUtils.jsx' | ||
import Dialog from 'material-ui/Dialog'; | ||
import TextField from 'material-ui/TextField'; | ||
import RaisedButton from 'material-ui/RaisedButton'; | ||
import copy from 'copy-to-clipboard'; | ||
import FontIcon from 'material-ui/FontIcon'; | ||
import FlatButton from 'material-ui/FlatButton'; | ||
import JsonEditor from '../JsonEditor.jsx'; | ||
import styles from './unwrapper.css'; | ||
|
||
export default class SecretUnwrapper extends Component { | ||
static propTypes = { | ||
location: PropTypes.object, | ||
}; | ||
|
||
constructor(props) { | ||
super(props) | ||
|
||
this.state = { | ||
headerMsg: 'Displaying data wrapped with token', | ||
editorContent: null, | ||
error: false, | ||
}; | ||
} | ||
|
||
|
||
|
||
componentDidMount() { | ||
callVaultApi('post', 'sys/wrapping/unwrap', null, null, null, this.props.location.query.token, this.props.location.query.vaultUrl) | ||
.then((resp) => { | ||
this.setState({ | ||
editorContent: resp.data.data | ||
}) | ||
}) | ||
.catch((err) => { | ||
this.setState({ | ||
headerMsg: `Server returned error ${err.response.status} while unwrapping token`, | ||
error: true, | ||
}) | ||
}) | ||
} | ||
|
||
render() { | ||
return ( | ||
<div id={styles.container}> | ||
<div className={this.state.error ? styles.redgradient : styles.bwgradient} id={styles.cell}> | ||
<h4>{this.state.headerMsg}</h4> | ||
<h2>{this.props.location.query.token}</h2> | ||
</div> | ||
<div id={styles.content}> | ||
{this.state.editorContent && <JsonEditor rootName={this.props.location.query.token} modes={['view']} mode={'view'} height={"500px"} value={this.state.editorContent} />} | ||
</div> | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, { PropTypes, Component } from 'react' | ||
import _ from 'lodash'; | ||
import { callVaultApi } from '../VaultUtils.jsx' | ||
import Dialog from 'material-ui/Dialog'; | ||
import TextField from 'material-ui/TextField'; | ||
import RaisedButton from 'material-ui/RaisedButton'; | ||
import copy from 'copy-to-clipboard'; | ||
import FontIcon from 'material-ui/FontIcon'; | ||
import FlatButton from 'material-ui/FlatButton'; | ||
import sharedStyles from '../styles.css'; | ||
|
||
export default class SecretWrapper extends Component { | ||
static propTypes = { | ||
path: PropTypes.string, | ||
onReceiveResponse: PropTypes.func, | ||
onReceiveError: PropTypes.func, | ||
onModalClose: PropTypes.func | ||
} | ||
|
||
static defaultProps = { | ||
path: null, | ||
onReceiveResponse: () => { }, | ||
onReceiveError: () => { }, | ||
onModalClose: () => { } | ||
} | ||
|
||
constructor(props) { | ||
super(props) | ||
} | ||
|
||
state = { | ||
wrapInfo: {}, | ||
}; | ||
|
||
componentDidUpdate(prevProps) { | ||
if (!_.isEqual(prevProps.path, this.props.path) && this.props.path) { | ||
callVaultApi('get', this.props.path, null, null, { 'X-Vault-Wrap-TTL': '10m' }) | ||
.then((response) => { | ||
this.setState({ wrapInfo: response.data.wrap_info }); | ||
this.props.onReceiveResponse(response.data.wrap_info); | ||
}) | ||
.catch((err) => { | ||
this.props.onReceiveError(err); | ||
}) | ||
} | ||
} | ||
|
||
render() { | ||
let vaultUrl = encodeURI(window.localStorage.getItem("vaultUrl")); | ||
let tokenValue = ''; | ||
let urlValue = ''; | ||
if (this.state.wrapInfo) { | ||
let loc = window.location; | ||
tokenValue = this.state.wrapInfo.token; | ||
urlValue = `${loc.protocol}//${loc.hostname}${(loc.port ? ":" + loc.port : "")}/unwrap?token=${tokenValue}&vaultUrl=${vaultUrl}`; | ||
} | ||
|
||
return ( | ||
<Dialog | ||
title="Data has been wrapped" | ||
modal={true} | ||
open={!_.isEmpty(this.state.wrapInfo)} | ||
actions={<FlatButton label="Close" primary={true} onTouchTap={() => {this.props.onModalClose(); this.setState({ wrapInfo: {} })}} />} | ||
onRequestClose={this.props.onModalClose} | ||
> | ||
<div className={sharedStyles.newTokenCodeEmitted}> | ||
<TextField | ||
fullWidth={true} | ||
disabled={true} | ||
floatingLabelText="This is a single-use unwrap token to read the wrapped data" | ||
defaultValue={tokenValue} | ||
/> | ||
<RaisedButton icon={<FontIcon className="fa fa-clipboard" />} label="Copy to Clipboard" onTouchTap={() => { copy(tokenValue) }} /> | ||
</div > | ||
<div className={sharedStyles.newUrlEmitted}> | ||
<TextField | ||
fullWidth={true} | ||
disabled={true} | ||
floatingLabelText="Use this URL if you want to display the wrapped data using Vault UI" | ||
defaultValue={urlValue} | ||
/> | ||
<RaisedButton icon={<FontIcon className="fa fa-clipboard" />} label="Copy to Clipboard" onTouchTap={() => { copy(urlValue) }} /> | ||
</div> | ||
</Dialog > | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#container { | ||
position: relative; | ||
height: 100%; | ||
width: 100%; | ||
} | ||
|
||
#cell { | ||
text-align: center; | ||
margin-bottom: 20px; | ||
margin-top: 20px; | ||
padding-top: 5px; | ||
padding-bottom: 5px; | ||
} | ||
|
||
.bwgradient { | ||
background: radial-gradient(circle, black, black, white); | ||
} | ||
|
||
.redgradient { | ||
background: radial-gradient(circle, darkred, darkred, white); | ||
} | ||
|
||
#cell h4 { | ||
color: lightgray; | ||
text-transform: full-width; | ||
} | ||
|
||
#cell h2 { | ||
font-family: monospace; | ||
color: #c2daff; | ||
} | ||
|
||
#content { | ||
/*display: inline-block; | ||
text-align: center; | ||
align-content: center;*/ | ||
|
||
width: 80%; | ||
margin: 0 auto; | ||
|
||
/*margin: auto;*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters