import React, { useState, useCallback } from 'react'; import { SelectableValue } from '@grafana/data'; import { css, cx } from 'emotion'; import { useTheme } from '../../themes'; import { BasicAuthSettings } from './BasicAuthSettings'; import { HttpProxySettings } from './HttpProxySettings'; import { TLSAuthSettings } from './TLSAuthSettings'; import { DataSourceSettings } from '@grafana/data'; import { HttpSettingsProps } from './types'; import { CustomHeadersSettings } from './CustomHeadersSettings'; import { Select } from '../Forms/Legacy/Select/Select'; import { Input } from '../Forms/Legacy/Input/Input'; import { FormField } from '../FormField/FormField'; import { FormLabel } from '../FormLabel/FormLabel'; import { Switch } from '../Switch/Switch'; import { TagsInput } from '../TagsInput/TagsInput'; 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 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.

); export const DataSourceHttpSettings: React.FC = props => { const { defaultUrl, dataSourceConfig, onChange, showAccessOptions } = props; let urlTooltip; const [isAccessHelpVisible, setIsAccessHelpVisible] = useState(false); const theme = useTheme(); const onSettingsChange = useCallback( (change: Partial>) => { onChange({ ...dataSourceConfig, ...change, }); }, [dataSourceConfig] ); 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 })} /> ); return (
<>

HTTP

{showAccessOptions && ( <>
{isAccessHelpVisible && } )} {dataSourceConfig.access === 'proxy' && (
Whitelisted Cookies onSettingsChange({ jsonData: { ...dataSourceConfig.jsonData, keepCookies: cookies } }) } width={20} />
)}
<>

Auth

{ onSettingsChange({ basicAuth: event!.currentTarget.checked }); }} /> { onSettingsChange({ withCredentials: event!.currentTarget.checked }); }} tooltip="Whether credentials such as cookies or auth headers should be sent with cross-site requests." />
{dataSourceConfig.access === 'proxy' && ( onSettingsChange({ jsonData })} /> )}
{dataSourceConfig.basicAuth && ( <>
Basic Auth Details
)} {(dataSourceConfig.jsonData.tlsAuth || dataSourceConfig.jsonData.tlsAuthWithCACert) && ( )}
); };