Skip to content

Commit

Permalink
Use clouds from SDK (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
aangelisc committed Apr 19, 2024
1 parent 1671c34 commit 2f24c25
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -27,7 +27,7 @@
"license": "Apache",
"devDependencies": {
"@babel/core": "^7.21.4",
"@grafana/azure-sdk": "0.0.1",
"@grafana/azure-sdk": "0.0.2",
"@grafana/e2e": "10.4.1",
"@grafana/e2e-selectors": "10.4.1",
"@grafana/eslint-config": "^7.0.0",
Expand Down
14 changes: 1 addition & 13 deletions src/components/ConfigEditor/AzureCredentials.ts
@@ -1,19 +1,7 @@
import { DataSourceSettings, SelectableValue } from '@grafana/data';
import { DataSourceSettings } from '@grafana/data';
import { AdxDataSourceOptions, AdxDataSourceSecureOptions } from 'types';
import { getCredentials } from './AzureCredentialsConfig';

export enum AzureCloud {
Public = 'AzureCloud',
China = 'AzureChinaCloud',
USGovernment = 'AzureUSGovernment',
}

export const KnownAzureClouds = [
{ value: AzureCloud.Public, label: 'Azure' },
{ value: AzureCloud.China, label: 'Azure China' },
{ value: AzureCloud.USGovernment, label: 'Azure US Government' },
] as SelectableValue[];

export function isCredentialsComplete(
options: DataSourceSettings<AdxDataSourceOptions, AdxDataSourceSecureOptions>
): boolean {
Expand Down
9 changes: 7 additions & 2 deletions src/components/ConfigEditor/AzureCredentialsConfig.ts
Expand Up @@ -2,11 +2,16 @@ import { AzureCredentials, ConcealedSecret } from '@grafana/azure-sdk';
import { DataSourceSettings } from '@grafana/data';
import { AzureSettings, config } from '@grafana/runtime';

import { AzureCloud } from './AzureCredentials';

const concealed: ConcealedSecret = Symbol('Concealed client secret');
const concealedLegacy: ConcealedSecret = Symbol('Concealed legacy client secret');

// Known clouds explicitly used with legacy credentials
enum AzureCloud {
Public = 'AzureCloud',
China = 'AzureChinaCloud',
USGovernment = 'AzureUSGovernment',
}

// TODO: Remove once it added to the runtime library
interface AzureSettingsEx extends AzureSettings {
userIdentityEnabled: boolean;
Expand Down
13 changes: 9 additions & 4 deletions src/components/ConfigEditor/index.tsx
@@ -1,6 +1,6 @@
import React, { useCallback, useEffect, useMemo } from 'react';
import { AzureCredentials } from '@grafana/azure-sdk';
import { FeatureToggles, DataSourcePluginOptionsEditorProps } from '@grafana/data';
import { AzureCredentials, getAzureClouds } from '@grafana/azure-sdk';
import { FeatureToggles, DataSourcePluginOptionsEditorProps, SelectableValue } from '@grafana/data';
import { Switch, InlineField } from '@grafana/ui';
import { config } from '@grafana/runtime';
import { gte } from 'semver';
Expand All @@ -10,7 +10,6 @@ import ConnectionConfig from './ConnectionConfig';
import DatabaseConfig from './DatabaseConfig';
import QueryConfig from './QueryConfig';
import TrackingConfig from './TrackingConfig';
import { KnownAzureClouds } from './AzureCredentials';
import {
getCredentials,
getDefaultCredentials,
Expand Down Expand Up @@ -39,6 +38,12 @@ const ConfigEditor: React.FC<ConfigEditorProps> = (props) => {
const { options, onOptionsChange } = props;
const { jsonData } = options;

const clouds = useMemo(() => {
return getAzureClouds().map<SelectableValue>((c) => {
return { value: c.name, label: c.displayName };
});
}, []);

const credentials = useMemo(() => getCredentials(options), [options]);

const hasAdditionalSettings = useMemo(
Expand Down Expand Up @@ -101,7 +106,7 @@ const ConfigEditor: React.FC<ConfigEditorProps> = (props) => {
workloadIdentityEnabled={getWorkloadIdentityEnabled()}
oboEnabled={getOboEnabled()}
credentials={credentials}
azureCloudOptions={KnownAzureClouds}
azureCloudOptions={clouds}
onCredentialsChange={onCredentialsChange}
/>
<Divider />
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Expand Up @@ -1864,12 +1864,12 @@
dependencies:
tslib "^2.4.0"

"@grafana/azure-sdk@0.0.1":
version "0.0.1"
resolved "https://registry.yarnpkg.com/@grafana/azure-sdk/-/azure-sdk-0.0.1.tgz#a81d3d51861bc56860f742121da049ce4d81fa42"
integrity sha512-looWP4qdNXujpsXYo1aII8RCWf3G9y5KXbG6KqZG2CxkzpbD84f+3V0paiRB5qcKwMwmLW1Mzr3hioEXCnh34A==
"@grafana/azure-sdk@0.0.2":
version "0.0.2"
resolved "https://registry.yarnpkg.com/@grafana/azure-sdk/-/azure-sdk-0.0.2.tgz#037619958b50e7a4c5bc1d641fd3a7acbee314f6"
integrity sha512-ZcQHqMOEPtZp15qOcoo8KL22OBPpOC8b6OfCmrp0Rxbbw9/3MP9xYc58kr2Ky4JwA0e6yKAzgFw+7KpV5ztIWw==
dependencies:
ts-jest "29.1.1"
ts-jest "29.1.2"

"@grafana/data@10.4.1":
version "10.4.1"
Expand Down Expand Up @@ -10981,10 +10981,10 @@ ts-easing@^0.2.0:
resolved "https://registry.yarnpkg.com/ts-easing/-/ts-easing-0.2.0.tgz#c8a8a35025105566588d87dbda05dd7fbfa5a4ec"
integrity sha512-Z86EW+fFFh/IFB1fqQ3/+7Zpf9t2ebOAxNI/V6Wo7r5gqiqtxmgTlQ1qbqQcjLKYeSHPTsEmvlJUDg/EuL0uHQ==

ts-jest@29.1.1:
version "29.1.1"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.1.1.tgz#f58fe62c63caf7bfcc5cc6472082f79180f0815b"
integrity sha512-D6xjnnbP17cC85nliwGiL+tpoKN0StpgE0TeOjXQTU6MVCfsB4v7aW05CgQ/1OywGb0x/oy9hHFnN+sczTiRaA==
ts-jest@29.1.2:
version "29.1.2"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.1.2.tgz#7613d8c81c43c8cb312c6904027257e814c40e09"
integrity sha512-br6GJoH/WUX4pu7FbZXuWGKGNDuU7b8Uj77g/Sp7puZV6EXzuByl6JrECvm0MzVzSTkSHWTihsXt+5XYER5b+g==
dependencies:
bs-logger "0.x"
fast-json-stable-stringify "2.x"
Expand Down

0 comments on commit 2f24c25

Please sign in to comment.