in src/Models/AzureUtility.ts [277:421]
private static async _getARMParameters(
parameterTemplate: ARMParameterTemplate,
parameters?: ARMParameters
): Promise<ARMParameters | undefined> {
parameters = parameters || ({} as ARMParameters);
for (const key of Object.keys(parameterTemplate)) {
if (Object.prototype.hasOwnProperty.call(parameters, key)) {
continue;
}
const keyDisplayName = AzureUtility._getKeyDisplayName(key);
const parameter = parameterTemplate[key];
let value: string | number | boolean | null = null;
let inputValue = "";
if (parameter.allowedValues) {
const values: vscode.QuickPickItem[] = [];
for (const value of parameter.allowedValues) {
if (value !== null) {
values.push({ label: value.toString(), description: "" });
}
}
const _value = await vscode.window.showQuickPick(values, {
placeHolder: `Select value of ${keyDisplayName}`,
ignoreFocusOut: true
});
if (!_value) {
return undefined;
}
inputValue = _value.label;
} else if (key.substr(0, 2) === "$$") {
// Read value from file
if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) {
inputValue = "";
} else {
const _key = key.substr(2);
const filePath = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, "..", _key);
AzureUtility._context.asAbsolutePath(_key);
if (fs.existsSync(filePath)) {
inputValue = fs.readFileSync(filePath, "utf8");
} else {
inputValue = "";
}
}
} else if (key.substr(0, 1) === "$") {
// Read value from workspace config
const _key = key.substr(1);
let iothubConnectionString: string | undefined;
const azureConfigFileHandler = new AzureConfigFileHandler(this._projectFolder);
const componentConfig = await azureConfigFileHandler.getComponentByType(
ScaffoldType.Workspace,
ComponentType.IoTHub
);
if (componentConfig) {
iothubConnectionString = componentConfig.componentInfo?.values.iothubConnectionString;
}
switch (_key) {
case "iotHubName":
if (!iothubConnectionString) {
inputValue = "";
} else {
const iotHubNameMatches = iothubConnectionString.match(/HostName=(.*?)\./);
if (!iotHubNameMatches) {
inputValue = "";
} else {
inputValue = iotHubNameMatches[1];
}
}
break;
case "iotHubKeyName":
if (!iothubConnectionString) {
inputValue = "";
} else {
const iotHubKeyNameMatches = iothubConnectionString.match(/SharedAccessKeyName=(.*?)(;|$)/);
if (!iotHubKeyNameMatches) {
inputValue = "";
} else {
inputValue = iotHubKeyNameMatches[1];
}
}
break;
case "iotHubKey":
if (!iothubConnectionString) {
inputValue = "";
} else {
const iotHubKeyMatches = iothubConnectionString.match(/SharedAccessKey=(.*?)(;|$)/);
if (!iotHubKeyMatches) {
inputValue = "";
} else {
inputValue = iotHubKeyMatches[1];
}
}
break;
case "subscription":
inputValue = AzureUtility._subscriptionId || "";
break;
default: {
const _value = ConfigHandler.get<string>(_key);
if (!_value) {
inputValue = "";
} else {
inputValue = _value;
}
}
}
} else {
const _value = await vscode.window.showInputBox({
prompt: `Input value for ${keyDisplayName}`,
ignoreFocusOut: true,
value: parameter.defaultValue ? parameter.defaultValue.toString() : "",
validateInput: async (value: string) => {
return AzureUtility._commonParameterCheck(value, parameter);
}
});
if (!_value) {
return undefined;
}
inputValue = _value;
}
switch (parameter.type.toLocaleLowerCase()) {
case "string":
value = inputValue;
break;
case "int":
value = Number(inputValue);
break;
case "bool":
value = inputValue.toLocaleLowerCase() === "true";
break;
default:
break;
}
parameters[key] = { value };
}
return parameters;
}