From edbe45efc2d35966002d189a21ab72588328807b Mon Sep 17 00:00:00 2001 From: Matias Chomicki Date: Tue, 26 Sep 2023 17:17:17 +0200 Subject: [PATCH] Elasticsearch: HTTP settings migration (#72840) * Elasticsearch: migrate data source http settings * Elasticsearch: migrate data source http settings * Remove test code * Update unit test * Connection settings: add url placeholder * Elasticsearch config editor: improve on-change handling of custom auth * Config editor: add missing oauthPassThru option --- .../configuration/ConfigEditor.test.tsx | 4 +- .../configuration/ConfigEditor.tsx | 69 +++++++++++++------ .../plugins/datasource/elasticsearch/types.ts | 2 + 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/configuration/ConfigEditor.test.tsx b/public/app/plugins/datasource/elasticsearch/configuration/ConfigEditor.test.tsx index 7cd9ac0336e..850cdb470df 100644 --- a/public/app/plugins/datasource/elasticsearch/configuration/ConfigEditor.test.tsx +++ b/public/app/plugins/datasource/elasticsearch/configuration/ConfigEditor.test.tsx @@ -15,7 +15,9 @@ describe('ConfigEditor', () => { render( {}} options={createDefaultConfigOptions()} />); // Check DataSourceHttpSettings are rendered - expect(screen.getByRole('heading', { name: 'HTTP' })).toBeInTheDocument(); + expect(screen.getByRole('heading', { name: 'Connection' })).toBeInTheDocument(); + expect(screen.getByRole('heading', { name: 'Authentication' })).toBeInTheDocument(); + expect(screen.getByRole('heading', { name: 'Advanced HTTP settings' })).toBeInTheDocument(); // Check ElasticDetails are rendered expect(screen.getByText('Elasticsearch details')).toBeInTheDocument(); diff --git a/public/app/plugins/datasource/elasticsearch/configuration/ConfigEditor.tsx b/public/app/plugins/datasource/elasticsearch/configuration/ConfigEditor.tsx index 7161d28a673..a3ca98774df 100644 --- a/public/app/plugins/datasource/elasticsearch/configuration/ConfigEditor.tsx +++ b/public/app/plugins/datasource/elasticsearch/configuration/ConfigEditor.tsx @@ -1,9 +1,17 @@ -import React, { useEffect, useRef } from 'react'; +import React, { useEffect } from 'react'; import { SIGV4ConnectionConfig } from '@grafana/aws-sdk'; import { DataSourcePluginOptionsEditorProps } from '@grafana/data'; -import { ConfigSection, DataSourceDescription } from '@grafana/experimental'; -import { Alert, DataSourceHttpSettings } from '@grafana/ui'; +import { + AdvancedHttpSettings, + Auth, + AuthMethod, + ConfigSection, + ConnectionSettings, + convertLegacyAuthProps, + DataSourceDescription, +} from '@grafana/experimental'; +import { Alert, SecureSocksProxySettings } from '@grafana/ui'; import { Divider } from 'app/core/components/Divider'; import { config } from 'app/core/config'; @@ -17,12 +25,6 @@ import { coerceOptions, isValidOptions } from './utils'; export type Props = DataSourcePluginOptionsEditorProps; export const ConfigEditor = (props: Props) => { - // we decide on whether to show access options or not at the point when the config page opens. - // whatever happens while the page is open, this decision does not change. - // (we do this to avoid situations where you switch access-mode and suddenly - // the access-mode-select-box vanishes) - const showAccessOptions = useRef(props.options.access === 'direct'); - const { options, onOptionsChange } = props; useEffect(() => { @@ -31,6 +33,22 @@ export const ConfigEditor = (props: Props) => { } }, [onOptionsChange, options]); + const authProps = convertLegacyAuthProps({ + config: options, + onChange: onOptionsChange, + }); + if (config.sigV4AuthEnabled) { + authProps.customMethods = [ + { + id: 'custom-sigv4', + label: 'SigV4 auth', + description: 'AWS Signature Version 4 authentication', + component: , + }, + ]; + authProps.selectedMethod = options.jsonData.sigV4Auth ? 'custom-sigv4' : authProps.selectedMethod; + } + return ( <> {options.access === 'direct' && ( @@ -43,27 +61,36 @@ export const ConfigEditor = (props: Props) => { docsLink="https://grafana.com/docs/grafana/latest/datasources/elasticsearch" hasRequiredFields={false} /> - - - } - secureSocksDSProxyEnabled={config.secureSocksDSProxyEnabled} + + + { + onOptionsChange({ + ...options, + basicAuth: method === AuthMethod.BasicAuth, + withCredentials: method === AuthMethod.CrossSiteCredentials, + jsonData: { + ...options.jsonData, + sigV4Auth: method === 'custom-sigv4', + oauthPassThru: method === AuthMethod.OAuthForward, + }, + }); + }} /> - - + + + {config.secureSocksDSProxyEnabled && ( + + )}