mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 21:02:29 +08:00
27 lines
774 B
TypeScript
27 lines
774 B
TypeScript
import {
|
|
AzureCredentials,
|
|
AzureDataSourceSettings,
|
|
getDatasourceCredentials,
|
|
getDefaultAzureCloud,
|
|
} from '@grafana/azure-sdk';
|
|
import { config } from '@grafana/runtime';
|
|
|
|
export const getDefaultCredentials = (): AzureCredentials => {
|
|
if (config.azure.managedIdentityEnabled) {
|
|
return { authType: 'msi' };
|
|
} else {
|
|
return { authType: 'clientsecret', azureCloud: getDefaultAzureCloud() };
|
|
}
|
|
};
|
|
|
|
export const getCredentials = (dsSettings: AzureDataSourceSettings): AzureCredentials => {
|
|
const credentials = getDatasourceCredentials(dsSettings);
|
|
if (credentials) {
|
|
return credentials;
|
|
}
|
|
|
|
// If no credentials saved, then return empty credentials
|
|
// of type based on whether the managed identity enabled
|
|
return getDefaultCredentials();
|
|
};
|