Merge workflows view
[arvados.git] / src / views-components / current-token-dialog / current-token-dialog.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { Dialog, DialogActions, DialogTitle, DialogContent, WithStyles, withStyles, StyleRulesCallback, Button, Typography, Paper } from '@material-ui/core';
7 import { ArvadosTheme } from '~/common/custom-theme';
8 import { withDialog } from '~/store/dialog/with-dialog';
9 import { WithDialogProps } from '~/store/dialog/with-dialog';
10 import { compose } from 'redux';
11 import { connect } from 'react-redux';
12 import { CurrentTokenDialogData, getCurrentTokenDialogData } from '~/store/current-token-dialog/current-token-dialog-actions';
13 import { DefaultCodeSnippet } from '~/components/default-code-snippet/default-code-snippet';
14
15 type CssRules = 'link' | 'paper' | 'button';
16
17 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
18     link: {
19         color: theme.palette.primary.main,
20         textDecoration: 'none',
21         margin: '0px 4px'
22     },
23     paper: {
24         padding: theme.spacing.unit,
25         marginBottom: theme.spacing.unit * 2,
26         backgroundColor: theme.palette.grey["200"],
27         border: `1px solid ${theme.palette.grey["300"]}`
28     },
29     button: {
30         fontSize: '0.8125rem',
31         fontWeight: 600
32     }
33 });
34
35 type CurrentTokenProps = CurrentTokenDialogData & WithDialogProps<{}> & WithStyles<CssRules>;
36
37 export const CurrentTokenDialog = compose(
38     withStyles(styles),
39     connect(getCurrentTokenDialogData),
40     withDialog('currentTokenDialog')
41 )(class extends React.Component<CurrentTokenProps> {
42     render() {
43         const { classes, open, closeDialog, ...data } = this.props;
44         return <Dialog
45             open={open}
46             onClose={closeDialog}
47             fullWidth={true}
48             maxWidth='md'>
49             <DialogTitle>Current Token</DialogTitle>
50             <DialogContent>
51                 <Typography variant='body1' paragraph={true}>
52                     The Arvados API token is a secret key that enables the Arvados SDKs to access Arvados with the proper permissions.
53                             <Typography component='p'>
54                         For more information see
55                                 <a href='http://doc.arvados.org/user/reference/api-tokens.html' target='blank' className={classes.link}>
56                             Getting an API token.
57                                 </a>
58                     </Typography>
59                 </Typography>
60                 <Typography variant='body1' paragraph={true}>
61                     Paste the following lines at a shell prompt to set up the necessary environment for Arvados SDKs to authenticate to your klingenc account.
62                         </Typography>
63                 <DefaultCodeSnippet lines={[getSnippet(data)]} />
64                 <Typography variant='body1'>
65                     Arvados
66                             <a href='http://doc.arvados.org/user/reference/api-tokens.html' target='blank' className={classes.link}>virtual machines</a>
67                     do this for you automatically. This setup is needed only when you use the API remotely (e.g., from your own workstation).
68                         </Typography>
69             </DialogContent>
70             <DialogActions>
71                 <Button onClick={closeDialog} className={classes.button} color="primary">CLOSE</Button>
72             </DialogActions>
73         </Dialog>;
74     }
75 }
76 );
77
78 const getSnippet = ({ apiHost, currentToken }: CurrentTokenDialogData) =>
79 `HISTIGNORE=$HISTIGNORE:'export ARVADOS_API_TOKEN=*'
80 export ARVADOS_API_TOKEN=${currentToken}
81 export ARVADOS_API_HOST=${apiHost}
82 unset ARVADOS_API_HOST_INSECURE`;