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