@ -2,15 +2,9 @@ import React, { FunctionComponent, useEffect, useMemo, useReducer, useState } fr
import { SelectableValue } from '@grafana/data' ;
import { SelectableValue } from '@grafana/data' ;
import { AzureCredentialsForm } from './AzureCredentialsForm' ;
import { AzureCredentialsForm } from './AzureCredentialsForm' ;
import { InlineFormLabel , LegacyForms , Button , Alert } from '@grafana/ui' ;
import { InlineFormLabel , LegacyForms , Button , Alert } from '@grafana/ui' ;
const { Select , Switch } = LegacyForms ;
const { Select } = LegacyForms ;
import { AzureDataSourceSettings , AzureCredentials } from '../types' ;
import { AzureDataSourceSettings } from '../types' ;
import {
import { getCredentials , isCredentialsComplete } from '../credentials' ;
getCredentials ,
getLogAnalyticsCredentials ,
isCredentialsComplete ,
updateLogAnalyticsCredentials ,
updateLogAnalyticsSameAs ,
} from '../credentials' ;
export interface Props {
export interface Props {
options : AzureDataSourceSettings ;
options : AzureDataSourceSettings ;
@ -22,22 +16,16 @@ export interface Props {
export const AnalyticsConfig : FunctionComponent < Props > = ( props : Props ) = > {
export const AnalyticsConfig : FunctionComponent < Props > = ( props : Props ) = > {
const { updateOptions , getSubscriptions , getWorkspaces } = props ;
const { updateOptions , getSubscriptions , getWorkspaces } = props ;
const primaryCredentials = useMemo ( ( ) = > getCredentials ( props . options ) , [ props . options ] ) ;
const primaryCredentials = useMemo ( ( ) = > getCredentials ( props . options ) , [ props . options ] ) ;
const logAnalyticsCredentials = useMemo ( ( ) = > getLogAnalyticsCredentials ( props . options ) , [ props . options ] ) ;
const subscriptionId = logAnalyticsCredentials
const subscriptionId = primaryCredentials . defaultSubscriptionId ;
? logAnalyticsCredentials . defaultSubscriptionId
: primaryCredentials . defaultSubscriptionId ;
// Only show a section for setting LogAnalytics credentials if they were set from before
// Only show a section for setting LogAnalytics credentials if
// And the authType is supported
// they were set from before with different values and the
const [ credentialsUsed , _ ] = useState ( ! ! logAnalyticsCredentials ) ;
// authType is supported
const credentialsEnabled = credentialsUsed && primaryCredentials . authType === 'clientsecret' ;
const logCredentialsEnabled =
primaryCredentials . authType === 'clientsecret' && props . options . jsonData . azureLogAnalyticsSameAs === false ;
const hasRequiredFields =
const hasRequiredFields = subscriptionId && isCredentialsComplete ( primaryCredentials ) ;
subscriptionId &&
( logAnalyticsCredentials
? isCredentialsComplete ( logAnalyticsCredentials )
: isCredentialsComplete ( primaryCredentials ) ) ;
const defaultWorkspace = props . options . jsonData . logAnalyticsDefaultWorkspace ;
const defaultWorkspace = props . options . jsonData . logAnalyticsDefaultWorkspace ;
@ -91,18 +79,6 @@ export const AnalyticsConfig: FunctionComponent<Props> = (props: Props) => {
}
}
} ;
} ;
const [ sameAsSwitched , setSameAsSwitched ] = useState ( false ) ;
const onCredentialsChange = ( updatedCredentials : AzureCredentials ) = > {
updateOptions ( ( options ) = > updateLogAnalyticsCredentials ( options , updatedCredentials ) ) ;
} ;
const onLogAnalyticsSameAsChange = ( event : React.SyntheticEvent < HTMLInputElement > ) = > {
const sameAs = event . currentTarget . checked ;
updateOptions ( ( options ) = > updateLogAnalyticsSameAs ( options , sameAs ) ) ;
setSameAsSwitched ( true ) ;
} ;
const onDefaultWorkspaceChange = ( selected : SelectableValue < string > ) = > {
const onDefaultWorkspaceChange = ( selected : SelectableValue < string > ) = > {
updateOptions ( ( options ) = > {
updateOptions ( ( options ) = > {
return {
return {
@ -115,57 +91,31 @@ export const AnalyticsConfig: FunctionComponent<Props> = (props: Props) => {
} ) ;
} ) ;
} ;
} ;
const tooltipAttribute = {
. . . ( ! logAnalyticsCredentials && {
tooltip : 'Workspaces are pulled from default subscription selected above.' ,
} ) ,
} ;
const showSameAsHelpMsg =
credentialsEnabled &&
sameAsSwitched &&
primaryCredentials . authType === 'clientsecret' &&
! primaryCredentials . clientSecret ;
return (
return (
< >
< >
< h3 className = "page-heading" > Azure Monitor Logs < / h3 >
< h3 className = "page-heading" > Azure Monitor Logs < / h3 >
{ c redentialsEnabled && (
{ logCredentialsEnabled && (
< >
< >
< Switch
< Alert severity = "error" title = "Deprecated" >
label = "Same details as Azure Monitor API"
Using different credentials for Azure Monitor Logs is no longer supported . Authentication information above
checked = { ! logAnalyticsCredentials }
will be used instead . Please create a new data source with the credentials below .
onChange = { onLogAnalyticsSameAsChange }
{ . . . tooltipAttribute }
/ >
{ showSameAsHelpMsg && (
< div className = "grafana-info-box m-t-2" >
< div className = "alert-body" >
< p > Re - enter your Azure Monitor Client Secret to use this setting . < / p >
< / div >
< / div >
) }
{ logAnalyticsCredentials && (
< >
< 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 >
< / Alert >
< AzureCredentialsForm
< AzureCredentialsForm
managedIdentityEnabled = { false }
managedIdentityEnabled = { false }
credentials = { logAnalyticsCredentials }
credentials = { {
onCredentialsChange = { onCredentialsChange }
. . . primaryCredentials ,
authType : 'clientsecret' ,
// Use deprecated Log Analytics credentials read-only
// to help with a possible migration
tenantId : props.options.jsonData.logAnalyticsTenantId ,
clientId : props.options.jsonData.logAnalyticsClientId ,
} }
getSubscriptions = { getSubscriptions }
getSubscriptions = { getSubscriptions }
disabled = { true }
/ >
/ >
< / >
< / >
) }
) }
< / >
) }
< div className = "gf-form-group" >
< div className = "gf-form-group" >
< div className = "gf-form-inline" >
< div className = "gf-form-inline" >
< div className = "gf-form" >
< div className = "gf-form" >