1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { Dialog, DialogActions, DialogTitle, DialogContent, WithStyles, withStyles, StyleRulesCallback, Button, Typography } from '@material-ui/core';
7 import * as CopyToClipboard from 'react-copy-to-clipboard';
8 import { ArvadosTheme } from '~/common/custom-theme';
9 import { withDialog } from '~/store/dialog/with-dialog';
10 import { WithDialogProps } from '~/store/dialog/with-dialog';
11 import { connect, DispatchProp } from 'react-redux';
12 import { CurrentTokenDialogData, getCurrentTokenDialogData, CURRENT_TOKEN_DIALOG_NAME } from '~/store/current-token-dialog/current-token-dialog-actions';
13 import { DefaultCodeSnippet } from '~/components/default-code-snippet/default-code-snippet';
14 import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
16 type CssRules = 'link' | 'paper' | 'button' | 'copyButton';
18 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
20 color: theme.palette.primary.main,
21 textDecoration: 'none',
25 padding: theme.spacing.unit,
26 marginBottom: theme.spacing.unit * 2,
27 backgroundColor: theme.palette.grey["200"],
28 border: `1px solid ${theme.palette.grey["300"]}`
31 fontSize: '0.8125rem',
36 marginTop: theme.spacing.unit * 2,
37 marginBottom: theme.spacing.unit * 2,
41 type CurrentTokenProps = CurrentTokenDialogData & WithDialogProps<{}> & WithStyles<CssRules> & DispatchProp;
43 export class CurrentTokenDialogComponent extends React.Component<CurrentTokenProps> {
44 onCopy = (message: string) => {
45 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
48 kind: SnackbarKind.SUCCESS
52 getSnippet = ({ apiHost, currentToken }: CurrentTokenDialogData) =>
53 `HISTIGNORE=$HISTIGNORE:'export ARVADOS_API_TOKEN=*'
54 export ARVADOS_API_TOKEN=${currentToken}
55 export ARVADOS_API_HOST=${apiHost}
56 unset ARVADOS_API_HOST_INSECURE`
59 const { classes, open, closeDialog, ...data } = this.props;
66 <DialogTitle>Current Token</DialogTitle>
68 <Typography paragraph={true}>
69 The Arvados API token is a secret key that enables the Arvados SDKs to access Arvados with the proper permissions.
70 <Typography component='span'>
71 For more information see
72 <a href='http://doc.arvados.org/user/reference/api-tokens.html' target='blank' className={classes.link}>
77 <Typography paragraph={true}>
78 Paste the following lines at a shell prompt to set up the necessary environment for Arvados SDKs to authenticate to your account.
80 <DefaultCodeSnippet lines={[this.getSnippet(data)]} />
81 <CopyToClipboard text={this.getSnippet(data)} onCopy={() => this.onCopy('Token copied to clipboard')}>
86 className={classes.copyButton}
93 <a href='http://doc.arvados.org/user/reference/api-tokens.html' target='blank' className={classes.link}>virtual machines</a>
94 do this for you automatically. This setup is needed only when you use the API remotely (e.g., from your own workstation).
98 <Button onClick={closeDialog} className={classes.button} color="primary">CLOSE</Button>
104 export const CurrentTokenDialog =
106 connect(getCurrentTokenDialogData)(
107 withDialog(CURRENT_TOKEN_DIALOG_NAME)(CurrentTokenDialogComponent)));