mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Update Azure Monitor * Update Prometheus * Update README * Update docs/sources/datasources/azure-monitor/_index.md Co-authored-by: Andrew Hackmann <5140848+bossinc@users.noreply.github.com> * Update docs/sources/datasources/azure-monitor/_index.md Co-authored-by: Beverly <131809838+BeverlyJaneJ@users.noreply.github.com> * Update docs/sources/datasources/azure-monitor/_index.md Co-authored-by: Beverly <131809838+BeverlyJaneJ@users.noreply.github.com> * Update docs/sources/datasources/azure-monitor/_index.md Co-authored-by: Beverly <131809838+BeverlyJaneJ@users.noreply.github.com> * README updates * Fix prettier * memoize options --------- Co-authored-by: Andrew Hackmann <5140848+bossinc@users.noreply.github.com> Co-authored-by: Beverly <131809838+BeverlyJaneJ@users.noreply.github.com>
83 lines
3.0 KiB
TypeScript
83 lines
3.0 KiB
TypeScript
import { cx } from '@emotion/css';
|
|
import React, { FormEvent, useMemo, useState } from 'react';
|
|
|
|
import { config } from '@grafana/runtime';
|
|
import { InlineField, InlineFieldRow, InlineSwitch, Input } from '@grafana/ui';
|
|
import { HttpSettingsBaseProps } from '@grafana/ui/src/components/DataSourceSettings/types';
|
|
|
|
import { KnownAzureClouds, AzureCredentials } from './AzureCredentials';
|
|
import { getCredentials, updateCredentials } from './AzureCredentialsConfig';
|
|
import { AzureCredentialsForm } from './AzureCredentialsForm';
|
|
|
|
export const AzureAuthSettings = (props: HttpSettingsBaseProps) => {
|
|
const { dataSourceConfig, onChange } = props;
|
|
|
|
const [overrideAudienceChecked, setOverrideAudienceChecked] = useState<boolean>(
|
|
!!dataSourceConfig.jsonData.azureEndpointResourceId
|
|
);
|
|
|
|
const credentials = useMemo(() => getCredentials(dataSourceConfig), [dataSourceConfig]);
|
|
|
|
const onCredentialsChange = (credentials: AzureCredentials): void => {
|
|
onChange(updateCredentials(dataSourceConfig, credentials));
|
|
};
|
|
|
|
const onOverrideAudienceChange = (ev: FormEvent<HTMLInputElement>): void => {
|
|
setOverrideAudienceChecked(ev.currentTarget.checked);
|
|
if (!ev.currentTarget.checked) {
|
|
onChange({
|
|
...dataSourceConfig,
|
|
jsonData: { ...dataSourceConfig.jsonData, azureEndpointResourceId: undefined },
|
|
});
|
|
}
|
|
};
|
|
|
|
const onResourceIdChange = (ev: FormEvent<HTMLInputElement>): void => {
|
|
if (overrideAudienceChecked) {
|
|
onChange({
|
|
...dataSourceConfig,
|
|
jsonData: { ...dataSourceConfig.jsonData, azureEndpointResourceId: ev.currentTarget.value },
|
|
});
|
|
}
|
|
};
|
|
|
|
const prometheusConfigOverhaulAuth = config.featureToggles.prometheusConfigOverhaulAuth;
|
|
|
|
const labelWidth = prometheusConfigOverhaulAuth ? 24 : 26;
|
|
|
|
return (
|
|
<>
|
|
<h6>Azure authentication</h6>
|
|
<AzureCredentialsForm
|
|
managedIdentityEnabled={config.azure.managedIdentityEnabled}
|
|
workloadIdentityEnabled={config.azure.workloadIdentityEnabled}
|
|
credentials={credentials}
|
|
azureCloudOptions={KnownAzureClouds}
|
|
onCredentialsChange={onCredentialsChange}
|
|
disabled={dataSourceConfig.readOnly}
|
|
/>
|
|
<h6>Azure configuration</h6>
|
|
<div className="gf-form-group">
|
|
<InlineFieldRow>
|
|
<InlineField labelWidth={labelWidth} label="Override AAD audience" disabled={dataSourceConfig.readOnly}>
|
|
<InlineSwitch value={overrideAudienceChecked} onChange={onOverrideAudienceChange} />
|
|
</InlineField>
|
|
</InlineFieldRow>
|
|
{overrideAudienceChecked && (
|
|
<InlineFieldRow>
|
|
<InlineField labelWidth={labelWidth} label="Resource ID" disabled={dataSourceConfig.readOnly}>
|
|
<Input
|
|
className={cx(prometheusConfigOverhaulAuth ? 'width-20' : 'width-30')}
|
|
value={dataSourceConfig.jsonData.azureEndpointResourceId || ''}
|
|
onChange={onResourceIdChange}
|
|
/>
|
|
</InlineField>
|
|
</InlineFieldRow>
|
|
)}
|
|
</div>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default AzureAuthSettings;
|