import { css, cx } from '@emotion/css'; import React, { useState, useCallback } from 'react'; import { DataSourceSettings, SelectableValue } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; import { useTheme2 } from '../../themes'; import { FormField } from '../FormField/FormField'; import { InlineFormLabel } from '../FormLabel/FormLabel'; import { InlineField } from '../Forms/InlineField'; import { Input } from '../Forms/Legacy/Input/Input'; import { Icon } from '../Icon/Icon'; import { Select } from '../Select/Select'; import { InlineSwitch } from '../Switch/Switch'; import { TagsInput } from '../TagsInput/TagsInput'; import { BasicAuthSettings } from './BasicAuthSettings'; import { CustomHeadersSettings } from './CustomHeadersSettings'; import { HttpProxySettings } from './HttpProxySettings'; import { TLSAuthSettings } from './TLSAuthSettings'; import { HttpSettingsProps } from './types'; const ACCESS_OPTIONS: Array> = [ { label: 'Server (default)', value: 'proxy', }, { label: 'Browser', value: 'direct', }, ]; const DEFAULT_ACCESS_OPTION = { label: 'Server (default)', value: 'proxy', }; const HttpAccessHelp = () => (

Access mode controls how requests to the data source will be handled.  Server {' '} should be the preferred way if nothing else is stated.

Server access mode (Default):

All requests will be made from the browser to Grafana backend/server which in turn will forward the requests to the data source and by that circumvent possible Cross-Origin Resource Sharing (CORS) requirements. The URL needs to be accessible from the grafana backend/server if you select this access mode.

Browser access mode:

All requests will be made from the browser directly to the data source and may be subject to Cross-Origin Resource Sharing (CORS) requirements. The URL needs to be accessible from the browser if you select this access mode.

); const LABEL_WIDTH = 26; export const DataSourceHttpSettings: React.FC = (props) => { const { defaultUrl, dataSourceConfig, onChange, showAccessOptions, sigV4AuthToggleEnabled, showForwardOAuthIdentityOption, azureAuthSettings, renderSigV4Editor, } = props; let urlTooltip; const [isAccessHelpVisible, setIsAccessHelpVisible] = useState(false); const theme = useTheme2(); const onSettingsChange = useCallback( (change: Partial>) => { onChange({ ...dataSourceConfig, ...change, }); }, [dataSourceConfig, onChange] ); switch (dataSourceConfig.access) { case 'direct': urlTooltip = ( <> Your access method is Browser, this means the URL needs to be accessible from the browser. ); break; case 'proxy': urlTooltip = ( <> Your access method is Server, this means the URL needs to be accessible from the grafana backend/server. ); break; default: urlTooltip = 'Specify a complete HTTP URL (for example http://your_server:8080)'; } const accessSelect = ( onSettingsChange({ url: event.currentTarget.value })} /> ); const azureAuthEnabled: boolean = (azureAuthSettings?.azureAuthSupported && azureAuthSettings.getAzureAuthEnabled(dataSourceConfig)) || false; return (
<>

HTTP

{showAccessOptions && ( <>
{isAccessHelpVisible && } )} {dataSourceConfig.access === 'proxy' && (
Allowed cookies onSettingsChange({ jsonData: { ...dataSourceConfig.jsonData, keepCookies: cookies } }) } />
{ onSettingsChange({ jsonData: { ...dataSourceConfig.jsonData, timeout: parseInt(event.currentTarget.value, 10) }, }); }} />
)}
<>

Auth

{ onSettingsChange({ basicAuth: event!.currentTarget.checked }); }} /> { onSettingsChange({ withCredentials: event!.currentTarget.checked }); }} />
{azureAuthSettings?.azureAuthSupported && (
{ onSettingsChange( azureAuthSettings.setAzureAuthEnabled(dataSourceConfig, event!.currentTarget.checked) ); }} />
)} {sigV4AuthToggleEnabled && (
{ onSettingsChange({ jsonData: { ...dataSourceConfig.jsonData, sigV4Auth: event!.currentTarget.checked }, }); }} />
)} {dataSourceConfig.access === 'proxy' && ( onSettingsChange({ jsonData })} showForwardOAuthIdentityOption={showForwardOAuthIdentityOption} /> )}
{dataSourceConfig.basicAuth && ( <>
Basic Auth Details
)} {azureAuthSettings?.azureAuthSupported && azureAuthEnabled && azureAuthSettings.azureSettingsUI && ( )} {dataSourceConfig.jsonData.sigV4Auth && sigV4AuthToggleEnabled && renderSigV4Editor} {(dataSourceConfig.jsonData.tlsAuth || dataSourceConfig.jsonData.tlsAuthWithCACert) && ( )} {dataSourceConfig.access === 'proxy' && ( )}
); };