mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Auth: Remove grafana ui dependency to the aws sdk (#43559)
* remove grafana ui dependency to the aws sdk * wip * cleanup * add tests * point to real version of aws-sdk
This commit is contained in:
parent
be57e73b61
commit
bd320ee0b3
@ -0,0 +1,77 @@
|
|||||||
|
import { render, screen } from '@testing-library/react';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { DataSourceHttpSettings } from '@grafana/ui';
|
||||||
|
|
||||||
|
import { HttpSettingsProps } from './types';
|
||||||
|
|
||||||
|
const setup = (propOverrides?: object) => {
|
||||||
|
const onChange = jest.fn();
|
||||||
|
const props: HttpSettingsProps = {
|
||||||
|
dataSourceConfig: {
|
||||||
|
id: 4,
|
||||||
|
uid: 'x',
|
||||||
|
orgId: 1,
|
||||||
|
name: 'gdev-influxdb',
|
||||||
|
type: 'influxdb',
|
||||||
|
typeName: 'Influxdb',
|
||||||
|
typeLogoUrl: '',
|
||||||
|
access: 'direct',
|
||||||
|
url: 'http://localhost:8086',
|
||||||
|
password: '',
|
||||||
|
user: 'grafana',
|
||||||
|
database: 'site',
|
||||||
|
basicAuth: false,
|
||||||
|
basicAuthUser: '',
|
||||||
|
basicAuthPassword: '',
|
||||||
|
withCredentials: false,
|
||||||
|
isDefault: false,
|
||||||
|
jsonData: {
|
||||||
|
timeInterval: '15s',
|
||||||
|
httpMode: 'GET',
|
||||||
|
keepCookies: ['cookie1', 'cookie2'],
|
||||||
|
},
|
||||||
|
secureJsonData: {
|
||||||
|
password: true,
|
||||||
|
},
|
||||||
|
secureJsonFields: {},
|
||||||
|
readOnly: true,
|
||||||
|
},
|
||||||
|
onChange,
|
||||||
|
...propOverrides,
|
||||||
|
defaultUrl: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
render(<DataSourceHttpSettings {...props} />);
|
||||||
|
return { onChange };
|
||||||
|
};
|
||||||
|
|
||||||
|
const SIGV4TestEditor = (props: { renderText: string }) => {
|
||||||
|
return <>{props.renderText}</>;
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('DataSourceHttpSettings', () => {
|
||||||
|
it('should render SIGV4 label if SIGV4 is enabled', () => {
|
||||||
|
setup({ sigV4AuthToggleEnabled: true });
|
||||||
|
expect(screen.getByLabelText('SigV4 auth')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not render SIGV4 label if SIGV4 is not enabled', () => {
|
||||||
|
setup({ sigV4AuthToggleEnabled: false });
|
||||||
|
expect(screen.queryByText('SigV4 auth')).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render SIGV4 editor if provided and SIGV4 is enabled', () => {
|
||||||
|
const expectedText = 'sigv4-test-editor';
|
||||||
|
setup({
|
||||||
|
sigV4AuthToggleEnabled: true,
|
||||||
|
renderSigV4Editor: <SIGV4TestEditor renderText={expectedText}></SIGV4TestEditor>,
|
||||||
|
dataSourceConfig: {
|
||||||
|
jsonData: {
|
||||||
|
sigV4Auth: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(screen.getByText(expectedText)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
@ -17,7 +17,6 @@ import { TagsInput } from '../TagsInput/TagsInput';
|
|||||||
import { BasicAuthSettings } from './BasicAuthSettings';
|
import { BasicAuthSettings } from './BasicAuthSettings';
|
||||||
import { CustomHeadersSettings } from './CustomHeadersSettings';
|
import { CustomHeadersSettings } from './CustomHeadersSettings';
|
||||||
import { HttpProxySettings } from './HttpProxySettings';
|
import { HttpProxySettings } from './HttpProxySettings';
|
||||||
import { SigV4AuthSettings } from './SigV4AuthSettings';
|
|
||||||
import { TLSAuthSettings } from './TLSAuthSettings';
|
import { TLSAuthSettings } from './TLSAuthSettings';
|
||||||
import { HttpSettingsProps } from './types';
|
import { HttpSettingsProps } from './types';
|
||||||
|
|
||||||
@ -71,6 +70,7 @@ export const DataSourceHttpSettings: React.FC<HttpSettingsProps> = (props) => {
|
|||||||
sigV4AuthToggleEnabled,
|
sigV4AuthToggleEnabled,
|
||||||
showForwardOAuthIdentityOption,
|
showForwardOAuthIdentityOption,
|
||||||
azureAuthSettings,
|
azureAuthSettings,
|
||||||
|
renderSigV4Editor,
|
||||||
} = props;
|
} = props;
|
||||||
let urlTooltip;
|
let urlTooltip;
|
||||||
const [isAccessHelpVisible, setIsAccessHelpVisible] = useState(false);
|
const [isAccessHelpVisible, setIsAccessHelpVisible] = useState(false);
|
||||||
@ -292,8 +292,7 @@ export const DataSourceHttpSettings: React.FC<HttpSettingsProps> = (props) => {
|
|||||||
<azureAuthSettings.azureSettingsUI dataSourceConfig={dataSourceConfig} onChange={onChange} />
|
<azureAuthSettings.azureSettingsUI dataSourceConfig={dataSourceConfig} onChange={onChange} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{dataSourceConfig.jsonData.sigV4Auth && sigV4AuthToggleEnabled && <SigV4AuthSettings {...props} />}
|
{dataSourceConfig.jsonData.sigV4Auth && sigV4AuthToggleEnabled && renderSigV4Editor}
|
||||||
|
|
||||||
{(dataSourceConfig.jsonData.tlsAuth || dataSourceConfig.jsonData.tlsAuthWithCACert) && (
|
{(dataSourceConfig.jsonData.tlsAuth || dataSourceConfig.jsonData.tlsAuthWithCACert) && (
|
||||||
<TLSAuthSettings dataSourceConfig={dataSourceConfig} onChange={onChange} />
|
<TLSAuthSettings dataSourceConfig={dataSourceConfig} onChange={onChange} />
|
||||||
)}
|
)}
|
||||||
|
@ -1,72 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
import {
|
|
||||||
AwsAuthDataSourceSecureJsonData,
|
|
||||||
AwsAuthDataSourceJsonData,
|
|
||||||
ConnectionConfig,
|
|
||||||
ConnectionConfigProps,
|
|
||||||
} from '@grafana/aws-sdk';
|
|
||||||
import { DataSourceSettings } from '@grafana/data';
|
|
||||||
|
|
||||||
import { HttpSettingsBaseProps } from './types';
|
|
||||||
|
|
||||||
export const SigV4AuthSettings: React.FC<HttpSettingsBaseProps> = (props) => {
|
|
||||||
const { dataSourceConfig, onChange } = props;
|
|
||||||
|
|
||||||
// The @grafana/aws-sdk ConnectionConfig is designed to be rendered in a ConfigEditor,
|
|
||||||
// taking DataSourcePluginOptionsEditorProps as props. We therefore need to map the props accordingly.
|
|
||||||
const connectionConfigProps: ConnectionConfigProps<AwsAuthDataSourceJsonData, AwsAuthDataSourceSecureJsonData> = {
|
|
||||||
onOptionsChange: (awsDataSourceSettings) => {
|
|
||||||
const dataSourceSettings: DataSourceSettings<any, any> = {
|
|
||||||
...dataSourceConfig,
|
|
||||||
jsonData: {
|
|
||||||
...dataSourceConfig.jsonData,
|
|
||||||
sigV4AuthType: awsDataSourceSettings.jsonData.authType,
|
|
||||||
sigV4Profile: awsDataSourceSettings.jsonData.profile,
|
|
||||||
sigV4AssumeRoleArn: awsDataSourceSettings.jsonData.assumeRoleArn,
|
|
||||||
sigV4ExternalId: awsDataSourceSettings.jsonData.externalId,
|
|
||||||
sigV4Region: awsDataSourceSettings.jsonData.defaultRegion,
|
|
||||||
sigV4Endpoint: awsDataSourceSettings.jsonData.endpoint,
|
|
||||||
},
|
|
||||||
secureJsonFields: {
|
|
||||||
sigV4AccessKey: awsDataSourceSettings.secureJsonFields?.accessKey,
|
|
||||||
sigV4SecretKey: awsDataSourceSettings.secureJsonFields?.secretKey,
|
|
||||||
},
|
|
||||||
secureJsonData: {
|
|
||||||
sigV4AccessKey: awsDataSourceSettings.secureJsonData?.accessKey,
|
|
||||||
sigV4SecretKey: awsDataSourceSettings.secureJsonData?.secretKey,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
onChange(dataSourceSettings);
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
...dataSourceConfig,
|
|
||||||
jsonData: {
|
|
||||||
...dataSourceConfig.jsonData,
|
|
||||||
authType: dataSourceConfig.jsonData.sigV4AuthType,
|
|
||||||
profile: dataSourceConfig.jsonData.sigV4Profile,
|
|
||||||
assumeRoleArn: dataSourceConfig.jsonData.sigV4AssumeRoleArn,
|
|
||||||
externalId: dataSourceConfig.jsonData.sigV4ExternalId,
|
|
||||||
defaultRegion: dataSourceConfig.jsonData.sigV4Region,
|
|
||||||
endpoint: dataSourceConfig.jsonData.sigV4Endpoint,
|
|
||||||
},
|
|
||||||
secureJsonFields: {
|
|
||||||
accessKey: dataSourceConfig.secureJsonFields?.sigV4AccessKey,
|
|
||||||
secretKey: dataSourceConfig.secureJsonFields?.sigV4SecretKey,
|
|
||||||
},
|
|
||||||
secureJsonData: {
|
|
||||||
accessKey: dataSourceConfig.secureJsonData?.sigV4AccessKey,
|
|
||||||
secretKey: dataSourceConfig.secureJsonData?.sigV4SecretKey,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className="gf-form">
|
|
||||||
<h6>SigV4 Auth Details</h6>
|
|
||||||
</div>
|
|
||||||
<ConnectionConfig {...connectionConfigProps} skipHeader skipEndpoint></ConnectionConfig>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
@ -37,4 +37,6 @@ export interface HttpSettingsProps extends HttpSettingsBaseProps {
|
|||||||
sigV4AuthToggleEnabled?: boolean;
|
sigV4AuthToggleEnabled?: boolean;
|
||||||
/** Azure authentication settings **/
|
/** Azure authentication settings **/
|
||||||
azureAuthSettings?: AzureAuthSettings;
|
azureAuthSettings?: AzureAuthSettings;
|
||||||
|
/** If SIGV4 is enabled, provide an editor for SIGV4 connection config **/
|
||||||
|
renderSigV4Editor?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
|
|
||||||
|
import { SIGV4ConnectionConfig } from '@grafana/aws-sdk';
|
||||||
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
|
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
|
||||||
import { Alert, DataSourceHttpSettings } from '@grafana/ui';
|
import { Alert, DataSourceHttpSettings } from '@grafana/ui';
|
||||||
import { config } from 'app/core/config';
|
import { config } from 'app/core/config';
|
||||||
@ -41,13 +42,13 @@ export const ConfigEditor = (props: Props) => {
|
|||||||
{`Support for Elasticsearch versions after their end-of-life (currently versions < 7.10) was removed`}
|
{`Support for Elasticsearch versions after their end-of-life (currently versions < 7.10) was removed`}
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<DataSourceHttpSettings
|
<DataSourceHttpSettings
|
||||||
defaultUrl="http://localhost:9200"
|
defaultUrl="http://localhost:9200"
|
||||||
dataSourceConfig={options}
|
dataSourceConfig={options}
|
||||||
showAccessOptions
|
showAccessOptions
|
||||||
onChange={onOptionsChange}
|
onChange={onOptionsChange}
|
||||||
sigV4AuthToggleEnabled={config.sigV4AuthEnabled}
|
sigV4AuthToggleEnabled={config.sigV4AuthEnabled}
|
||||||
|
renderSigV4Editor={<SIGV4ConnectionConfig {...props}></SIGV4ConnectionConfig>}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ElasticDetails value={options} onChange={onOptionsChange} />
|
<ElasticDetails value={options} onChange={onOptionsChange} />
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
import { SIGV4ConnectionConfig } from '@grafana/aws-sdk';
|
||||||
import { DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
|
import { DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
|
||||||
import { AlertingSettings, DataSourceHttpSettings, Alert } from '@grafana/ui';
|
import { AlertingSettings, DataSourceHttpSettings, Alert } from '@grafana/ui';
|
||||||
import { config } from 'app/core/config';
|
import { config } from 'app/core/config';
|
||||||
@ -39,6 +40,7 @@ export const ConfigEditor = (props: Props) => {
|
|||||||
onChange={onOptionsChange}
|
onChange={onOptionsChange}
|
||||||
sigV4AuthToggleEnabled={config.sigV4AuthEnabled}
|
sigV4AuthToggleEnabled={config.sigV4AuthEnabled}
|
||||||
azureAuthSettings={azureAuthSettings}
|
azureAuthSettings={azureAuthSettings}
|
||||||
|
renderSigV4Editor={<SIGV4ConnectionConfig {...props}></SIGV4ConnectionConfig>}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<AlertingSettings<PromOptions>
|
<AlertingSettings<PromOptions>
|
||||||
|
Loading…
Reference in New Issue
Block a user