2022-06-15 07:59:40 -05:00
|
|
|
import { css } from '@emotion/css';
|
2022-07-21 11:56:20 -05:00
|
|
|
import React, { useState } from 'react';
|
2022-06-15 07:59:40 -05:00
|
|
|
|
|
|
|
import { GrafanaTheme2 } from '@grafana/data';
|
2022-07-21 11:56:20 -05:00
|
|
|
import { Alert, Button, ConfirmModal, useStyles2 } from '@grafana/ui';
|
2022-06-15 07:59:40 -05:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
onMigrate: () => void;
|
|
|
|
disabled?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const MigrateToServiceAccountsCard = ({ onMigrate, disabled }: Props): JSX.Element => {
|
2022-07-21 11:56:20 -05:00
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
2022-06-15 07:59:40 -05:00
|
|
|
const styles = useStyles2(getStyles);
|
|
|
|
|
2022-07-21 11:56:20 -05:00
|
|
|
const docsLink = (
|
|
|
|
<a
|
|
|
|
className="external-link"
|
|
|
|
href="https://grafana.com/docs/grafana/latest/administration/api-keys/#migrate-api-keys-to-grafana-service-accounts/"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
here.
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
const migrationBoxDesc = (
|
|
|
|
<span>Are you sure you want to migrate all API keys to service accounts? Find out more {docsLink}</span>
|
|
|
|
);
|
|
|
|
|
2022-06-15 07:59:40 -05:00
|
|
|
return (
|
2022-07-21 11:56:20 -05:00
|
|
|
<Alert title="Switch from API keys to service accounts" severity="info">
|
2022-06-15 07:59:40 -05:00
|
|
|
<div className={styles.text}>
|
2022-07-21 11:56:20 -05:00
|
|
|
Each API key will be automatically migrated into a service account with a token. The service account will be
|
|
|
|
created with the same permission as the API Key and current API Keys will continue to work as they were.
|
2022-06-15 07:59:40 -05:00
|
|
|
</div>
|
|
|
|
<div className={styles.actionRow}>
|
2022-07-21 11:56:20 -05:00
|
|
|
<Button className={styles.actionButton} onClick={() => setIsModalOpen(true)}>
|
|
|
|
Migrate to service accounts now
|
|
|
|
</Button>
|
|
|
|
<ConfirmModal
|
|
|
|
title={'Migrate API keys to service accounts'}
|
|
|
|
isOpen={isModalOpen}
|
|
|
|
body={migrationBoxDesc}
|
|
|
|
confirmText={'Yes, migrate now'}
|
|
|
|
onConfirm={onMigrate}
|
|
|
|
onDismiss={() => setIsModalOpen(false)}
|
|
|
|
/>
|
2022-06-15 07:59:40 -05:00
|
|
|
</div>
|
|
|
|
</Alert>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getStyles = (theme: GrafanaTheme2) => ({
|
|
|
|
text: css`
|
|
|
|
margin-bottom: ${theme.spacing(2)};
|
|
|
|
`,
|
|
|
|
actionRow: css`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
`,
|
|
|
|
actionButton: css`
|
|
|
|
margin-right: ${theme.spacing(2)};
|
|
|
|
`,
|
|
|
|
});
|