Prometheus: get Azure clouds from SDK (#87676)

* Prometheus: get the list of azure clouds from the SDK instead of from a hard coded list

* Update yarn.lock

* Fix lint

---------

Co-authored-by: Jeremy Angel (from Dev Box) <jeremyangel@microsoft.com>
Co-authored-by: Andreas Christou <andreas.christou@grafana.com>
This commit is contained in:
Jon Cole 2024-05-25 01:56:53 +09:00 committed by GitHub
parent 67b90ceba5
commit 61db22f4b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 25 additions and 12 deletions

View File

@ -245,6 +245,7 @@
"@floating-ui/react": "0.26.14",
"@glideapps/glide-data-grid": "^6.0.0",
"@grafana/aws-sdk": "0.3.3",
"@grafana/azure-sdk": "0.0.3",
"@grafana/data": "workspace:*",
"@grafana/e2e-selectors": "workspace:*",
"@grafana/experimental": "1.7.11",

View File

@ -6,8 +6,8 @@ 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 { AzureCredentials } from './AzureCredentials';
import { getAzureCloudOptions, getCredentials, updateCredentials } from './AzureCredentialsConfig';
import { AzureCredentialsForm } from './AzureCredentialsForm';
export const AzureAuthSettings = (props: HttpSettingsBaseProps) => {
@ -60,7 +60,7 @@ export const AzureAuthSettings = (props: HttpSettingsBaseProps) => {
managedIdentityEnabled={config.azure.managedIdentityEnabled}
workloadIdentityEnabled={config.azure.workloadIdentityEnabled}
credentials={credentials}
azureCloudOptions={KnownAzureClouds}
azureCloudOptions={getAzureCloudOptions()}
onCredentialsChange={onCredentialsChange}
disabled={dataSourceConfig.readOnly}
/>

View File

@ -1,5 +1,3 @@
import { SelectableValue } from '@grafana/data';
export enum AzureCloud {
Public = 'AzureCloud',
China = 'AzureChinaCloud',
@ -7,12 +5,6 @@ export enum AzureCloud {
None = '',
}
export const KnownAzureClouds: Array<SelectableValue<AzureCloud>> = [
{ value: AzureCloud.Public, label: 'Azure' },
{ value: AzureCloud.China, label: 'Azure China' },
{ value: AzureCloud.USGovernment, label: 'Azure US Government' },
];
export type AzureAuthType = 'msi' | 'clientsecret' | 'workloadidentity';
export type ConcealedSecret = symbol;

View File

@ -1,4 +1,5 @@
import { DataSourceSettings } from '@grafana/data';
import { getAzureClouds } from '@grafana/azure-sdk';
import { DataSourceSettings, SelectableValue } from '@grafana/data';
import { config } from '@grafana/runtime';
import { AzureCloud, AzureCredentials, ConcealedSecret } from './AzureCredentials';
@ -23,6 +24,15 @@ export function hasCredentials(options: DataSourceSettings<any, any>): boolean {
return !!options.jsonData.azureCredentials;
}
export function getAzureCloudOptions(): Array<SelectableValue<string>> {
const cloudInfo = getAzureClouds();
return cloudInfo.map((cloud) => ({
value: cloud.name,
label: cloud.displayName,
}));
}
export function getDefaultCredentials(): AzureCredentials {
if (config.azure.managedIdentityEnabled) {
return { authType: 'msi' };

View File

@ -2975,6 +2975,15 @@ __metadata:
languageName: node
linkType: hard
"@grafana/azure-sdk@npm:0.0.3":
version: 0.0.3
resolution: "@grafana/azure-sdk@npm:0.0.3"
dependencies:
ts-jest: "npm:29.1.2"
checksum: 10/fc888711e79865c3ff08f21401ed51b3d5a189e38c691a2dd60915af843612481deb45a1f804fe4a631636dae966f6591984e7e4f37ea0c62fd5e0a4c0cf1166
languageName: node
linkType: hard
"@grafana/data@npm:11.0.0, @grafana/data@workspace:*, @grafana/data@workspace:packages/grafana-data":
version: 0.0.0-use.local
resolution: "@grafana/data@workspace:packages/grafana-data"
@ -16691,6 +16700,7 @@ __metadata:
"@floating-ui/react": "npm:0.26.14"
"@glideapps/glide-data-grid": "npm:^6.0.0"
"@grafana/aws-sdk": "npm:0.3.3"
"@grafana/azure-sdk": "npm:0.0.3"
"@grafana/data": "workspace:*"
"@grafana/e2e-selectors": "workspace:*"
"@grafana/eslint-config": "npm:7.0.0"