mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AzureMonitor: Deprecate using separate credentials for Logs (#34758)
* Hide switch for using different credentials in AzureMonitor * Apply feedback. Use @testing-library
This commit is contained in:
parent
261319a4be
commit
48dc78fd48
@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import AnalyticsConfig, { Props } from './AnalyticsConfig';
|
||||
|
||||
const setup = (propsFunc?: (props: Props) => Props) => {
|
||||
@ -47,14 +47,14 @@ const setup = (propsFunc?: (props: Props) => Props) => {
|
||||
props = propsFunc(props);
|
||||
}
|
||||
|
||||
return shallow(<AnalyticsConfig {...props} />);
|
||||
return render(<AnalyticsConfig {...props} />);
|
||||
};
|
||||
|
||||
describe('Render', () => {
|
||||
it('should render component', () => {
|
||||
const wrapper = setup();
|
||||
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
expect(wrapper.baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should disable log analytics credentials form', () => {
|
||||
@ -68,7 +68,7 @@ describe('Render', () => {
|
||||
},
|
||||
},
|
||||
}));
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
expect(wrapper.baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should enable azure log analytics load workspaces button', () => {
|
||||
@ -87,6 +87,37 @@ describe('Render', () => {
|
||||
},
|
||||
},
|
||||
}));
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
expect(wrapper.baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should not render the Switch to use different creds for log analytics by default', () => {
|
||||
setup((props) => ({
|
||||
...props,
|
||||
options: {
|
||||
...props.options,
|
||||
jsonData: {
|
||||
...props.options.jsonData,
|
||||
azureLogAnalyticsSameAs: undefined,
|
||||
},
|
||||
},
|
||||
}));
|
||||
expect(screen.queryByLabelText('Same details as Azure Monitor API')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('is deprecated', { exact: false })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
// Remove this test with deprecated code
|
||||
it('should not render the Switch if different creds for log analytics were set from before', () => {
|
||||
setup((props) => ({
|
||||
...props,
|
||||
options: {
|
||||
...props.options,
|
||||
jsonData: {
|
||||
...props.options.jsonData,
|
||||
azureLogAnalyticsSameAs: false,
|
||||
},
|
||||
},
|
||||
}));
|
||||
expect(screen.queryByLabelText('Same details as Azure Monitor API')).toBeInTheDocument();
|
||||
expect(screen.queryByText('is deprecated', { exact: false })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { FunctionComponent, useEffect, useMemo, useReducer, useState } from 'react';
|
||||
import { SelectableValue } from '@grafana/data';
|
||||
import { AzureCredentialsForm } from './AzureCredentialsForm';
|
||||
import { InlineFormLabel, LegacyForms, Button } from '@grafana/ui';
|
||||
import { InlineFormLabel, LegacyForms, Button, Alert } from '@grafana/ui';
|
||||
const { Select, Switch } = LegacyForms;
|
||||
import { AzureDataSourceSettings, AzureCredentials } from '../types';
|
||||
import {
|
||||
@ -23,11 +23,15 @@ export const AnalyticsConfig: FunctionComponent<Props> = (props: Props) => {
|
||||
const { updateOptions, getSubscriptions, getWorkspaces } = props;
|
||||
const primaryCredentials = useMemo(() => getCredentials(props.options), [props.options]);
|
||||
const logAnalyticsCredentials = useMemo(() => getLogAnalyticsCredentials(props.options), [props.options]);
|
||||
|
||||
const subscriptionId = logAnalyticsCredentials
|
||||
? logAnalyticsCredentials.defaultSubscriptionId
|
||||
: primaryCredentials.defaultSubscriptionId;
|
||||
|
||||
const credentialsEnabled = primaryCredentials.authType === 'clientsecret';
|
||||
// Only show a section for setting LogAnalytics credentials if they were set from before
|
||||
// And the authType is supported
|
||||
const [credentialsUsed, _] = useState(!!logAnalyticsCredentials);
|
||||
const credentialsEnabled = credentialsUsed && primaryCredentials.authType === 'clientsecret';
|
||||
|
||||
const hasRequiredFields =
|
||||
subscriptionId &&
|
||||
@ -134,6 +138,7 @@ export const AnalyticsConfig: FunctionComponent<Props> = (props: Props) => {
|
||||
onChange={onLogAnalyticsSameAsChange}
|
||||
{...tooltipAttribute}
|
||||
/>
|
||||
|
||||
{showSameAsHelpMsg && (
|
||||
<div className="grafana-info-box m-t-2">
|
||||
<div className="alert-body">
|
||||
@ -141,13 +146,23 @@ export const AnalyticsConfig: FunctionComponent<Props> = (props: Props) => {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{logAnalyticsCredentials && (
|
||||
<AzureCredentialsForm
|
||||
managedIdentityEnabled={false}
|
||||
credentials={logAnalyticsCredentials}
|
||||
onCredentialsChange={onCredentialsChange}
|
||||
getSubscriptions={getSubscriptions}
|
||||
/>
|
||||
<>
|
||||
<Alert severity="info" title="Deprecated">
|
||||
Using different credentials for Azure Monitor Logs is deprecated and will be removed in a future
|
||||
version.
|
||||
<br />
|
||||
Create a different Data Source if you need to use different credentials.
|
||||
</Alert>
|
||||
|
||||
<AzureCredentialsForm
|
||||
managedIdentityEnabled={false}
|
||||
credentials={logAnalyticsCredentials}
|
||||
onCredentialsChange={onCredentialsChange}
|
||||
getSubscriptions={getSubscriptions}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user