/usr/share/grafana/public/app/plugins/datasource/azuremonitor
import { AzureCredentials, getDatasourceCredentials, getDefaultAzureCloud, getClientSecret, resolveLegacyCloudName, updateDatasourceCredentials, } from '@grafana/azure-sdk'; import { config } from '@grafana/runtime'; import { AzureMonitorDataSourceInstanceSettings, AzureMonitorDataSourceSettings } from './types/types'; export function getCredentials( options: AzureMonitorDataSourceSettings | AzureMonitorDataSourceInstanceSettings ): AzureCredentials { // Try to get the credentials from the datasource settings, // If not found, return the legacy azure monitor credentials if they exist or fallback to default credentials const creds = getDatasourceCredentials(options); if (creds) { return creds; } return getLegacyCredentials(options) || getDefaultCredentials(); } export function updateCredentials( options: AzureMonitorDataSourceSettings, credentials: AzureCredentials ): AzureMonitorDataSourceSettings { return updateDatasourceCredentials(options, credentials); } function getLegacyCredentials( options: AzureMonitorDataSourceSettings | AzureMonitorDataSourceInstanceSettings ): AzureCredentials | undefined { try { // If authentication type isn't explicitly specified and datasource has client credentials, // then this is existing datasource which is configured for app registration (client secret) if ( options.jsonData.azureAuthType === 'clientsecret' || (!options.jsonData.azureAuthType && options.jsonData.tenantId && options.jsonData.clientId) ) { return { authType: 'clientsecret', tenantId: options.jsonData.tenantId, clientId: options.jsonData.clientId, azureCloud: resolveLegacyCloudName(options.jsonData.cloudName) || getDefaultAzureCloud(), clientSecret: getClientSecret(options), }; } // If the authentication type is not set, then no legacy credentials exist so return undefined if (!options.jsonData.azureAuthType) { return undefined; } return { authType: options.jsonData.azureAuthType }; } catch (e) { if (e instanceof Error) { console.error('Unable to restore legacy credentials: %s', e.message); } return undefined; } } function getDefaultCredentials(): AzureCredentials { if (config.azure.managedIdentityEnabled) { return { authType: 'msi' }; } else if (config.azure.workloadIdentityEnabled) { return { authType: 'workloadidentity' }; } else { return { authType: 'clientsecret', azureCloud: getDefaultAzureCloud() }; } }
.
Edit
..
Edit
CHANGELOG.md
Edit
README.md
Edit
azureMetadata
Edit
azure_log_analytics
Edit
azure_monitor
Edit
azure_resource_graph
Edit
components
Edit
credentials.ts
Edit
dashboards
Edit
dataquery.cue
Edit
dataquery.gen.ts
Edit
datasource.test.ts
Edit
datasource.ts
Edit
dist
Edit
e2e
Edit
grafanaTemplateVariableFns.ts
Edit
grafanaTemplateVariables.test.ts
Edit
i18next.config.ts
Edit
img
Edit
jest-setup.js
Edit
jest.config.js
Edit
locales
Edit
mocks
Edit
module.test.ts
Edit
module.ts
Edit
package.json
Edit
plugin.json
Edit
project.json
Edit
query_help.md
Edit
resourcePicker
Edit
time_grain_converter.test.ts
Edit
time_grain_converter.ts
Edit
tracking.ts
Edit
tsconfig.json
Edit
types
Edit
utils
Edit
variables.test.ts
Edit
variables.ts
Edit
webpack.config.ts
Edit