2020-10-27 07:08:08 -05:00
|
|
|
import React from 'react';
|
|
|
|
import { selectors } from '@grafana/e2e-selectors';
|
2021-03-18 04:44:26 -05:00
|
|
|
import { HorizontalGroup, InfoBox, List, PluginSignatureBadge, useTheme } from '@grafana/ui';
|
2020-10-27 07:08:08 -05:00
|
|
|
import { StoreState } from '../../types';
|
|
|
|
import { getAllPluginsErrors } from './state/selectors';
|
|
|
|
import { loadPlugins, loadPluginsErrors } from './state/actions';
|
|
|
|
import useAsync from 'react-use/lib/useAsync';
|
|
|
|
import { connect, MapDispatchToProps, MapStateToProps } from 'react-redux';
|
|
|
|
import { hot } from 'react-hot-loader';
|
2021-03-18 04:44:26 -05:00
|
|
|
import { PluginError, PluginErrorCode, PluginSignatureStatus } from '@grafana/data';
|
2020-10-27 07:08:08 -05:00
|
|
|
import { css } from 'emotion';
|
|
|
|
|
|
|
|
interface ConnectedProps {
|
|
|
|
errors: PluginError[];
|
|
|
|
}
|
|
|
|
|
|
|
|
interface DispatchProps {
|
|
|
|
loadPluginsErrors: typeof loadPluginsErrors;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface OwnProps {
|
|
|
|
children?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
type PluginsErrorsInfoProps = ConnectedProps & DispatchProps & OwnProps;
|
|
|
|
|
|
|
|
export const PluginsErrorsInfoUnconnected: React.FC<PluginsErrorsInfoProps> = ({
|
|
|
|
loadPluginsErrors,
|
|
|
|
errors,
|
|
|
|
children,
|
|
|
|
}) => {
|
|
|
|
const theme = useTheme();
|
|
|
|
|
|
|
|
const { loading } = useAsync(async () => {
|
|
|
|
await loadPluginsErrors();
|
|
|
|
}, [loadPlugins]);
|
|
|
|
|
|
|
|
if (loading || errors.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<InfoBox
|
|
|
|
aria-label={selectors.pages.PluginsList.signatureErrorNotice}
|
|
|
|
severity="warning"
|
|
|
|
urlTitle="Read more about plugin signing"
|
2020-11-09 06:32:48 -06:00
|
|
|
url="https://grafana.com/docs/grafana/latest/plugins/plugin-signatures/"
|
2020-10-27 07:08:08 -05:00
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<p>
|
|
|
|
We have encountered{' '}
|
2020-11-18 08:36:35 -06:00
|
|
|
<a
|
|
|
|
href="https://grafana.com/docs/grafana/latest/developers/plugins/backend/"
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
>
|
2020-10-27 07:08:08 -05:00
|
|
|
data source backend plugins
|
|
|
|
</a>{' '}
|
|
|
|
that are unsigned. Grafana Labs cannot guarantee the integrity of unsigned plugins and recommends using signed
|
|
|
|
plugins only.
|
|
|
|
</p>
|
|
|
|
The following plugins are disabled and not shown in the list below:
|
|
|
|
<List
|
|
|
|
items={errors}
|
|
|
|
className={css`
|
|
|
|
list-style-type: circle;
|
|
|
|
`}
|
2021-01-20 00:59:48 -06:00
|
|
|
renderItem={(e) => (
|
2020-10-27 07:08:08 -05:00
|
|
|
<div
|
|
|
|
className={css`
|
|
|
|
margin-top: ${theme.spacing.sm};
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<HorizontalGroup spacing="sm" justify="flex-start" align="center">
|
|
|
|
<strong>{e.pluginId}</strong>
|
|
|
|
<PluginSignatureBadge
|
|
|
|
status={mapPluginErrorCodeToSignatureStatus(e.errorCode)}
|
|
|
|
className={css`
|
|
|
|
margin-top: 0;
|
|
|
|
`}
|
|
|
|
/>
|
|
|
|
</HorizontalGroup>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
</InfoBox>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps: MapStateToProps<ConnectedProps, OwnProps, StoreState> = (state: StoreState) => {
|
|
|
|
return {
|
|
|
|
errors: getAllPluginsErrors(state.plugins),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapDispatchToProps: MapDispatchToProps<DispatchProps, OwnProps> = {
|
|
|
|
loadPluginsErrors,
|
|
|
|
};
|
|
|
|
|
|
|
|
export const PluginsErrorsInfo = hot(module)(
|
|
|
|
connect(mapStateToProps, mapDispatchToProps)(PluginsErrorsInfoUnconnected)
|
|
|
|
);
|
2021-03-18 04:44:26 -05:00
|
|
|
|
|
|
|
function mapPluginErrorCodeToSignatureStatus(code: PluginErrorCode) {
|
|
|
|
switch (code) {
|
|
|
|
case PluginErrorCode.invalidSignature:
|
|
|
|
return PluginSignatureStatus.invalid;
|
|
|
|
case PluginErrorCode.missingSignature:
|
|
|
|
return PluginSignatureStatus.missing;
|
|
|
|
case PluginErrorCode.modifiedSignature:
|
|
|
|
return PluginSignatureStatus.modified;
|
|
|
|
default:
|
|
|
|
return PluginSignatureStatus.missing;
|
|
|
|
}
|
|
|
|
}
|