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 147
Add ability to show current token + renew lease #114
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,16 @@ import Github from 'mui-icons/fontawesome/github'; | |
import CountDown from './countdown.js' | ||
import styles from './header.css'; | ||
import { callVaultApi, history } from '../../shared/VaultUtils.jsx'; | ||
import IconMenu from 'material-ui/IconMenu'; | ||
import MenuItem from 'material-ui/MenuItem'; | ||
import NavigationMenu from 'material-ui/svg-icons/navigation/menu'; | ||
import Divider from 'material-ui/Divider'; | ||
import Dialog from 'material-ui/Dialog'; | ||
import TextField from 'material-ui/TextField'; | ||
import sharedStyles from '../styles.css'; | ||
import RaisedButton from 'material-ui/RaisedButton'; | ||
import ContentContentCopy from 'material-ui/svg-icons/content/content-copy'; | ||
import copy from 'copy-to-clipboard'; | ||
|
||
var logout = () => { | ||
window.localStorage.removeItem('vaultAccessToken'); | ||
|
@@ -23,8 +33,15 @@ class Header extends React.Component { | |
super(props); | ||
this.state = { | ||
serverAddr: window.localStorage.getItem('vaultUrl'), | ||
version: '' | ||
version: '', | ||
tokenDialogOpened: false, | ||
tokenRenewed: false, | ||
ttl: 0 | ||
} | ||
_.bindAll( | ||
this, | ||
'renewTokenLease' | ||
); | ||
} | ||
|
||
static propTypes = { | ||
|
@@ -49,8 +66,43 @@ class Header extends React.Component { | |
}); | ||
} | ||
|
||
renewTokenLease() { | ||
callVaultApi('post', 'auth/token/renew-self') | ||
.then((resp) => { | ||
snackBarMessage("Session renewed"); | ||
this.setState({ ttl: resp.data.auth.lease_duration, tokenRenewed: true }); | ||
}) | ||
.catch(snackBarMessage) | ||
} | ||
|
||
|
||
render() { | ||
|
||
let tokenDialogOptions = [ | ||
<FlatButton label="Close" primary={true} onTouchTap={() => this.setState({ tokenDialogOpened: false })} /> | ||
]; | ||
|
||
let showToken = () => { | ||
return ( | ||
<Dialog | ||
title="Token" | ||
modal={true} | ||
open={this.state.tokenDialogOpened} | ||
actions={tokenDialogOptions} | ||
> | ||
<div className={sharedStyles.newTokenCodeEmitted}> | ||
<TextField | ||
fullWidth={true} | ||
disabled={true} | ||
floatingLabelText="Token" | ||
defaultValue={window.localStorage.getItem("vaultAccessToken")} | ||
/> | ||
<RaisedButton icon={<ContentContentCopy />} label="Copy to Clipboard" onTouchTap={() => { copy(window.localStorage.getItem("vaultAccessToken")) }} /> | ||
</div> | ||
</Dialog> | ||
) | ||
} | ||
|
||
let renderTokenInfo = () => { | ||
|
||
let infoSectionItems = [] | ||
|
@@ -77,7 +129,16 @@ class Header extends React.Component { | |
</span> | ||
) | ||
|
||
if (this.props.tokenIdentity.ttl) { | ||
if (this.state.tokenRenewed) { | ||
infoSectionItems.push( | ||
<span key="infoSessionTimeout" className={styles.infoSectionItem}> | ||
<span className={styles.infoSectionItemKey}>token ttl</span> | ||
<span className={styles.infoSectionItemValue}> | ||
<CountDown countDown={this.state.ttl} retrigger={this.props.tokenIdentity.last_renewal_time} /> | ||
</span> | ||
</span> | ||
); | ||
} else if (this.props.tokenIdentity.ttl) { | ||
infoSectionItems.push( | ||
<span key="infoSessionTimeout" className={styles.infoSectionItem}> | ||
<span className={styles.infoSectionItemKey}>token ttl</span> | ||
|
@@ -101,34 +162,52 @@ class Header extends React.Component { | |
} | ||
|
||
return ( | ||
<div id={styles.headerWrapper}> | ||
<Toolbar style={{ backgroundColor: '#000000', height: '64px' }}> | ||
<ToolbarGroup firstChild={true}> | ||
<IconButton | ||
onTouchTap={() => { | ||
if(WEBPACK_DEF_TARGET_WEB) { | ||
window.open('https://github.com/djenriquez/vault-ui', '_blank'); | ||
} else { | ||
event.preventDefault(); | ||
require('electron').shell.openExternal('https://github.com/djenriquez/vault-ui') | ||
} | ||
}} | ||
> | ||
<Github className={styles.title}/> | ||
</IconButton> | ||
<ToolbarTitle className={styles.title} | ||
onTouchTap={() => { | ||
history.push('/'); | ||
}} | ||
text="VAULT - UI" /> | ||
</ToolbarGroup> | ||
<ToolbarGroup> | ||
{renderTokenInfo()} | ||
</ToolbarGroup> | ||
<ToolbarGroup lastChild={true}> | ||
<FlatButton className={styles.title} onTouchTap={logout} label="Logout" /> | ||
</ToolbarGroup> | ||
</Toolbar> | ||
<div> | ||
{showToken()} | ||
<div id={styles.headerWrapper}> | ||
<Toolbar style={{ backgroundColor: '#000000', height: '64px' }}> | ||
<ToolbarGroup firstChild={true}> | ||
<IconButton | ||
onTouchTap={() => { | ||
if (WEBPACK_DEF_TARGET_WEB) { | ||
window.open('https://github.com/djenriquez/vault-ui', '_blank'); | ||
} else { | ||
event.preventDefault(); | ||
require('electron').shell.openExternal('https://github.com/djenriquez/vault-ui') | ||
} | ||
}} | ||
> | ||
<Github className={styles.title} /> | ||
</IconButton> | ||
<ToolbarTitle className={styles.title} | ||
onTouchTap={() => { | ||
history.push('/'); | ||
}} | ||
text="VAULT - UI" /> | ||
</ToolbarGroup> | ||
<ToolbarGroup> | ||
{renderTokenInfo()} | ||
</ToolbarGroup> | ||
<ToolbarGroup lastChild={true}> | ||
<IconMenu iconButtonElement={<IconButton ><NavigationMenu color='white' /></IconButton>}> | ||
<MenuItem | ||
primaryText="Show token" | ||
onTouchTap={() => this.setState({ tokenDialogOpened: true })} | ||
/> | ||
<Divider /> | ||
<MenuItem | ||
primaryText="Renew token lease" | ||
onTouchTap={this.renewTokenLease} | ||
/> | ||
<Divider /> | ||
<MenuItem | ||
primaryText="Logout" | ||
onTouchTap={logout} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logout is preserved and added to the icon menu. |
||
/> | ||
</IconMenu> | ||
</ToolbarGroup> | ||
</Toolbar> | ||
</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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little bit of a hacky solution, but wasn't sure how to update the TTL once renewed since the value came from a super class. I'm definitely open to suggestions if there are better ways to handle this.