MySQL: make it possible to add CA cert without using tlsAuth (#58226)

This commit is contained in:
Oscar Kilhed 2022-11-07 09:38:42 +01:00 committed by GitHub
parent d673c8809b
commit b1bfae0350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 35 deletions

View File

@ -12,31 +12,36 @@ import { InlineField, SecretTextArea } from '@grafana/ui';
export interface Props<T extends DataSourceJsonData, S> { export interface Props<T extends DataSourceJsonData, S> {
editorProps: DataSourcePluginOptionsEditorProps<T, S>; editorProps: DataSourcePluginOptionsEditorProps<T, S>;
showCACert?: boolean; showCACert?: boolean;
showKeyPair?: boolean;
secureJsonFields?: KeyValue<Boolean>; secureJsonFields?: KeyValue<Boolean>;
labelWidth?: number; labelWidth?: number;
} }
export const TLSSecretsConfig = <T extends DataSourceJsonData, S extends {} = {}>(props: Props<T, S>) => { export const TLSSecretsConfig = <T extends DataSourceJsonData, S extends {} = {}>(props: Props<T, S>) => {
const { labelWidth, editorProps, showCACert } = props; const { labelWidth, editorProps, showCACert, showKeyPair = true } = props;
const { secureJsonFields } = editorProps.options; const { secureJsonFields } = editorProps.options;
return ( return (
<> <>
<InlineField {showKeyPair ? (
tooltip={<span>To authenticate with an TLS/SSL client certificate, provide the client certificate here.</span>} <InlineField
labelWidth={labelWidth} tooltip={
label="TLS/SSL Client Certificate" <span>To authenticate with an TLS/SSL client certificate, provide the client certificate here.</span>
> }
<SecretTextArea labelWidth={labelWidth}
placeholder="Begins with -----BEGIN CERTIFICATE-----" label="TLS/SSL Client Certificate"
cols={45} >
rows={7} <SecretTextArea
isConfigured={secureJsonFields && secureJsonFields.tlsClientCert} placeholder="Begins with -----BEGIN CERTIFICATE-----"
onChange={onUpdateDatasourceSecureJsonDataOption(editorProps, 'tlsClientCert')} cols={45}
onReset={() => { rows={7}
updateDatasourcePluginResetOption(editorProps, 'tlsClientCert'); isConfigured={secureJsonFields && secureJsonFields.tlsClientCert}
}} onChange={onUpdateDatasourceSecureJsonDataOption(editorProps, 'tlsClientCert')}
></SecretTextArea> onReset={() => {
</InlineField> updateDatasourcePluginResetOption(editorProps, 'tlsClientCert');
}}
></SecretTextArea>
</InlineField>
) : null}
{showCACert ? ( {showCACert ? (
<InlineField <InlineField
tooltip={<span>If the selected TLS/SSL mode requires a server root certificate, provide it here.</span>} tooltip={<span>If the selected TLS/SSL mode requires a server root certificate, provide it here.</span>}
@ -55,23 +60,24 @@ export const TLSSecretsConfig = <T extends DataSourceJsonData, S extends {} = {}
></SecretTextArea> ></SecretTextArea>
</InlineField> </InlineField>
) : null} ) : null}
{showKeyPair ? (
<InlineField <InlineField
tooltip={<span>To authenticate with a client TLS/SSL certificate, provide the key here.</span>} tooltip={<span>To authenticate with a client TLS/SSL certificate, provide the key here.</span>}
labelWidth={labelWidth} labelWidth={labelWidth}
label="TLS/SSL Client Key" label="TLS/SSL Client Key"
> >
<SecretTextArea <SecretTextArea
placeholder="Begins with -----BEGIN RSA PRIVATE KEY-----" placeholder="Begins with -----BEGIN RSA PRIVATE KEY-----"
cols={45} cols={45}
rows={7} rows={7}
isConfigured={secureJsonFields && secureJsonFields.tlsClientKey} isConfigured={secureJsonFields && secureJsonFields.tlsClientKey}
onChange={onUpdateDatasourceSecureJsonDataOption(editorProps, 'tlsClientKey')} onChange={onUpdateDatasourceSecureJsonDataOption(editorProps, 'tlsClientKey')}
onReset={() => { onReset={() => {
updateDatasourcePluginResetOption(editorProps, 'tlsClientKey'); updateDatasourcePluginResetOption(editorProps, 'tlsClientKey');
}} }}
></SecretTextArea> ></SecretTextArea>
</InlineField> </InlineField>
) : null}
</> </>
); );
}; };

View File

@ -128,10 +128,11 @@ export const ConfigurationEditor = (props: DataSourcePluginOptionsEditorProps<My
</InlineField> </InlineField>
</FieldSet> </FieldSet>
{options.jsonData.tlsAuth ? ( {jsonData.tlsAuth || jsonData.tlsAuthWithCACert ? (
<FieldSet label="TLS/SSL Auth Details"> <FieldSet label="TLS/SSL Auth Details">
<TLSSecretsConfig <TLSSecretsConfig
showCACert={jsonData.tlsAuthWithCACert} showCACert={jsonData.tlsAuthWithCACert}
showKeyPair={jsonData.tlsAuth}
editorProps={props} editorProps={props}
labelWidth={25} labelWidth={25}
></TLSSecretsConfig> ></TLSSecretsConfig>