mirror of https://github.com/grafana/grafana
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-sdkpull/49101/head^2
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(); |
||||
}); |
||||
}); |
@ -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> |
||||
</> |
||||
); |
||||
}; |
Loading…
Reference in new issue