From 7bfea07b9bf879f8de307c05dfe3fb040d64e1aa Mon Sep 17 00:00:00 2001 From: Arvind Ranasaria Date: Wed, 30 Sep 2020 14:25:15 -0700 Subject: [PATCH] Fetch arc dc config profile list from azdata (#12678) --- extensions/arc/package.json | 13 ++------- .../src/helpers/optionSources.ts | 28 +++++++++++++++---- .../resource-deployment/src/interfaces.ts | 6 ++-- .../src/ui/modelViewUtils.ts | 5 +++- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/extensions/arc/package.json b/extensions/arc/package.json index 82816b8384..fd08549181 100644 --- a/extensions/arc/package.json +++ b/extensions/arc/package.json @@ -185,16 +185,9 @@ "variableName": "AZDATA_NB_VAR_ARC_PROFILE", "editable": false, "options": { - "values": [ - "azure-arc-ake", - "azure-arc-aks-default-storage", - "azure-arc-aks-premium-storage", - "azure-arc-aks-hci", - "azure-arc-azure-openshift", - "azure-arc-eks", - "azure-arc-kubeadm", - "azure-arc-openshift" - ], + "source": { + "type": "ArcControllerConfigProfilesOptionsSource" + }, "defaultValue": "azure-arc-aks-default-storage", "optionsType": "radio" } diff --git a/extensions/resource-deployment/src/helpers/optionSources.ts b/extensions/resource-deployment/src/helpers/optionSources.ts index 4584e8eb46..84142bcc0a 100644 --- a/extensions/resource-deployment/src/helpers/optionSources.ts +++ b/extensions/resource-deployment/src/helpers/optionSources.ts @@ -11,8 +11,9 @@ import { apiService } from '../services/apiService'; import { throwUnless } from '../utils'; import { CacheManager } from './cacheManager'; -export enum OptionsSourceType { - ArcControllersOptionsSource = 'ArcControllersOptionsSource' +export const enum OptionsSourceType { + ArcControllersOptionsSource = 'ArcControllersOptionsSource', + ArcControllerConfigProfilesOptionsSource = 'ArcControllerConfigProfilesOptionsSource' } export abstract class OptionsSource implements IOptionsSource { @@ -20,14 +21,22 @@ export abstract class OptionsSource implements IOptionsSource { get type(): OptionsSourceType { return this._type; } get variableNames(): { [index: string]: string; } { return this._variableNames; } - abstract async getOptions(): Promise; - abstract async getVariableValue(variableName: string, input: string): Promise; - abstract getIsPassword(variableName: string): boolean; + abstract getOptions(): Promise; + getVariableValue(variableName: string, controllerLabel: string): Promise { + throw new Error(loc.variableValueFetchForUnsupportedVariable(variableName)); + } + + getIsPassword(variableName: string): boolean { + throw new Error(loc.isPasswordFetchForUnsupportedVariable(variableName)); + } constructor(private _variableNames: { [index: string]: string }, private _type: OptionsSourceType) { } } +/** + * Class that provides options sources for an Arc Data Controller + */ export class ArcControllersOptionsSource extends OptionsSource { private _cacheManager = new CacheManager(); @@ -82,3 +91,12 @@ export class ArcControllersOptionsSource extends OptionsSource { } } } + +/** + * Class that provides options sources for an Arc Data Controller's Config Profiles + */ +export class ArcControllerConfigProfilesOptionsSource extends OptionsSource { + async getOptions(): Promise { + return (await apiService.azdataApi.azdata.arc.dc.config.list()).result; + } +} diff --git a/extensions/resource-deployment/src/interfaces.ts b/extensions/resource-deployment/src/interfaces.ts index 56a58acbf8..91cd374b3d 100644 --- a/extensions/resource-deployment/src/interfaces.ts +++ b/extensions/resource-deployment/src/interfaces.ts @@ -219,9 +219,9 @@ export type ComponentCSSStyles = { }; export interface IOptionsSource { - readonly type: OptionsSourceType, - readonly variableNames: { [index: string]: string; }, - getOptions(): Promise, + readonly type: OptionsSourceType; + readonly variableNames: { [index: string]: string; }; + getOptions(): Promise; getVariableValue(variableName: string, input: string): Promise; getIsPassword(variableName: string): boolean; } diff --git a/extensions/resource-deployment/src/ui/modelViewUtils.ts b/extensions/resource-deployment/src/ui/modelViewUtils.ts index c43eebcf24..415dc9e0b6 100644 --- a/extensions/resource-deployment/src/ui/modelViewUtils.ts +++ b/extensions/resource-deployment/src/ui/modelViewUtils.ts @@ -9,7 +9,7 @@ import { EOL, homedir as os_homedir } from 'os'; import * as path from 'path'; import * as vscode from 'vscode'; import * as nls from 'vscode-nls'; -import { ArcControllersOptionsSource, OptionsSourceType } from '../helpers/optionSources'; +import { ArcControllerConfigProfilesOptionsSource, ArcControllersOptionsSource, OptionsSourceType } from '../helpers/optionSources'; import { AzureAccountFieldInfo, AzureLocationsFieldInfo, ComponentCSSStyles, DialogInfoBase, FieldInfo, FieldType, FilePickerFieldInfo, IOptionsSource, KubeClusterContextFieldInfo, LabelPosition, NoteBookEnvironmentVariablePrefix, OptionsInfo, OptionsType, PageInfoBase, RowInfo, SectionInfo, TextCSSStyles } from '../interfaces'; import * as loc from '../localizedConstants'; import { apiService } from '../services/apiService'; @@ -439,6 +439,9 @@ async function processOptionsTypeField(context: FieldContext): Promise { case OptionsSourceType.ArcControllersOptionsSource: optionsSource = new ArcControllersOptionsSource(context.fieldInfo.options.source.variableNames, context.fieldInfo.options.source.type); break; + case OptionsSourceType.ArcControllerConfigProfilesOptionsSource: + optionsSource = new ArcControllerConfigProfilesOptionsSource(context.fieldInfo.options.source.variableNames, context.fieldInfo.options.source.type); + break; default: throw new Error(loc.noOptionsSourceDefined(context.fieldInfo.options.source.type)); }