Fetch arc dc config profile list from azdata (#12678)

This commit is contained in:
Arvind Ranasaria
2020-09-30 14:25:15 -07:00
committed by GitHub
parent ab85028a94
commit 7bfea07b9b
4 changed files with 33 additions and 19 deletions

View File

@@ -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"
}

View File

@@ -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<string[] | CategoryValue[]>;
abstract async getVariableValue(variableName: string, input: string): Promise<string>;
abstract getIsPassword(variableName: string): boolean;
abstract getOptions(): Promise<string[] | CategoryValue[]>;
getVariableValue(variableName: string, controllerLabel: string): Promise<string> {
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<string, string>();
@@ -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<string[]> {
return (await apiService.azdataApi.azdata.arc.dc.config.list()).result;
}
}

View File

@@ -219,9 +219,9 @@ export type ComponentCSSStyles = {
};
export interface IOptionsSource {
readonly type: OptionsSourceType,
readonly variableNames: { [index: string]: string; },
getOptions(): Promise<string[] | azdata.CategoryValue[]>,
readonly type: OptionsSourceType;
readonly variableNames: { [index: string]: string; };
getOptions(): Promise<string[] | azdata.CategoryValue[]>;
getVariableValue(variableName: string, input: string): Promise<string>;
getIsPassword(variableName: string): boolean;
}

View File

@@ -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<void> {
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));
}