Use shared nonNull utils (#343)
This commit is contained in:
Родитель
8f633a3e3a
Коммит
8c1e59d91b
|
@ -27,7 +27,6 @@ export { VirtualMachineTreeItem } from "./src/tree/VirtualMachineTreeItem";
|
|||
export { createComputeClient, createResourceClient } from './src/utils/azureClients';
|
||||
export * from './src/utils/cpUtils';
|
||||
export * from './src/utils/delay';
|
||||
export { nonNullProp, nonNullValue } from './src/utils/nonNull';
|
||||
export { getRandomHexString } from './src/utils/randomUtils';
|
||||
export * from './src/vsCodeConfig/extensions';
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
"@azure/arm-resources": "^5.0.0",
|
||||
"@azure/arm-resources-profile-2020-09-01-hybrid": "^1.0.0",
|
||||
"@microsoft/vscode-azext-azureutils": "^0.3.1",
|
||||
"@microsoft/vscode-azext-utils": "^0.3.7",
|
||||
"@microsoft/vscode-azext-utils": "^0.3.9",
|
||||
"fs-extra": "^8.1.0",
|
||||
"open": "^8.0.4",
|
||||
"semver": "^5.7.0",
|
||||
|
@ -960,9 +960,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@microsoft/vscode-azext-utils": {
|
||||
"version": "0.3.7",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-utils/-/vscode-azext-utils-0.3.7.tgz",
|
||||
"integrity": "sha512-TCIo1rVPYso5r9UrDfZK2j9FvvruW4BOTjtgK9g8F6gRB3FvpBd8AlQhXcffe8NmKNPJhbmdRSwhk51EujK2FA==",
|
||||
"version": "0.3.9",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-utils/-/vscode-azext-utils-0.3.9.tgz",
|
||||
"integrity": "sha512-xVUxksOGsf6UfAgisLsf+SIVumvY/28Tgsm3HMNf4b+UX4/YSSFTWhZ8oeJ4Y/q9W0c1gbOMagjR+KPcE/7V9g==",
|
||||
"dependencies": {
|
||||
"@vscode/extension-telemetry": "^0.6.2",
|
||||
"dayjs": "^1.11.2",
|
||||
|
@ -12886,9 +12886,9 @@
|
|||
}
|
||||
},
|
||||
"@microsoft/vscode-azext-utils": {
|
||||
"version": "0.3.7",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-utils/-/vscode-azext-utils-0.3.7.tgz",
|
||||
"integrity": "sha512-TCIo1rVPYso5r9UrDfZK2j9FvvruW4BOTjtgK9g8F6gRB3FvpBd8AlQhXcffe8NmKNPJhbmdRSwhk51EujK2FA==",
|
||||
"version": "0.3.9",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-utils/-/vscode-azext-utils-0.3.9.tgz",
|
||||
"integrity": "sha512-xVUxksOGsf6UfAgisLsf+SIVumvY/28Tgsm3HMNf4b+UX4/YSSFTWhZ8oeJ4Y/q9W0c1gbOMagjR+KPcE/7V9g==",
|
||||
"requires": {
|
||||
"@vscode/extension-telemetry": "^0.6.2",
|
||||
"dayjs": "^1.11.2",
|
||||
|
|
|
@ -234,7 +234,7 @@
|
|||
"@azure/arm-resources": "^5.0.0",
|
||||
"@azure/arm-resources-profile-2020-09-01-hybrid": "^1.0.0",
|
||||
"@microsoft/vscode-azext-azureutils": "^0.3.1",
|
||||
"@microsoft/vscode-azext-utils": "^0.3.7",
|
||||
"@microsoft/vscode-azext-utils": "^0.3.9",
|
||||
"fs-extra": "^8.1.0",
|
||||
"open": "^8.0.4",
|
||||
"semver": "^5.7.0",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ComputeManagementClient, VirtualMachine, VirtualMachineExtension } from "@azure/arm-compute";
|
||||
import { IActionContext, parseError } from "@microsoft/vscode-azext-utils";
|
||||
import { IActionContext, nonNullValueAndProp, parseError } from "@microsoft/vscode-azext-utils";
|
||||
import * as fse from "fs-extra";
|
||||
import { ProgressLocation, Uri, window } from "vscode";
|
||||
import { sshFsPath, vmFilter } from "../constants";
|
||||
|
@ -12,7 +12,6 @@ import { ext } from "../extensionVariables";
|
|||
import { localize } from "../localize";
|
||||
import { ResolvedVirtualMachineTreeItem, VirtualMachineTreeItem } from "../tree/VirtualMachineTreeItem";
|
||||
import { createComputeClient } from "../utils/azureClients";
|
||||
import { nonNullValueAndProp } from "../utils/nonNull";
|
||||
import { configureSshConfig } from "../utils/sshUtils";
|
||||
|
||||
export async function addSshKey(context: IActionContext, node?: ResolvedVirtualMachineTreeItem): Promise<void> {
|
||||
|
|
|
@ -5,12 +5,11 @@
|
|||
|
||||
import { NetworkInterface, NetworkManagementClient, PublicIPAddress, Subnet } from '@azure/arm-network';
|
||||
import { AzExtLocation, LocationListStep } from '@microsoft/vscode-azext-azureutils';
|
||||
import { AzureWizardExecuteStep } from "@microsoft/vscode-azext-utils";
|
||||
import { AzureWizardExecuteStep, nonNullProp, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
|
||||
import { Progress } from "vscode";
|
||||
import { ext } from '../../extensionVariables';
|
||||
import { localize } from '../../localize';
|
||||
import { createNetworkClient } from '../../utils/azureClients';
|
||||
import { nonNullProp, nonNullValueAndProp } from '../../utils/nonNull';
|
||||
import { IVirtualMachineWizardContext } from './IVirtualMachineWizardContext';
|
||||
|
||||
export class NetworkInterfaceCreateStep extends AzureWizardExecuteStep<IVirtualMachineWizardContext> {
|
||||
|
|
|
@ -5,12 +5,11 @@
|
|||
|
||||
import { NetworkManagementClient, NetworkSecurityGroup, SecurityRule } from '@azure/arm-network';
|
||||
import { LocationListStep } from "@microsoft/vscode-azext-azureutils";
|
||||
import { AzureWizardExecuteStep } from "@microsoft/vscode-azext-utils";
|
||||
import { AzureWizardExecuteStep, nonNullProp, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
|
||||
import { Progress } from "vscode";
|
||||
import { ext } from '../../extensionVariables';
|
||||
import { localize } from '../../localize';
|
||||
import { createNetworkClient } from '../../utils/azureClients';
|
||||
import { nonNullProp, nonNullValueAndProp } from '../../utils/nonNull';
|
||||
import { IVirtualMachineWizardContext } from './IVirtualMachineWizardContext';
|
||||
|
||||
export class NetworkSecurityGroupCreateStep extends AzureWizardExecuteStep<IVirtualMachineWizardContext> {
|
||||
|
|
|
@ -5,12 +5,11 @@
|
|||
|
||||
import { NetworkManagementClient, PublicIPAddress } from '@azure/arm-network';
|
||||
import { LocationListStep } from '@microsoft/vscode-azext-azureutils';
|
||||
import { AzureWizardExecuteStep } from "@microsoft/vscode-azext-utils";
|
||||
import { AzureWizardExecuteStep, nonNullProp, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
|
||||
import { Progress } from "vscode";
|
||||
import { ext } from '../../extensionVariables';
|
||||
import { localize } from '../../localize';
|
||||
import { createNetworkClient } from '../../utils/azureClients';
|
||||
import { nonNullProp, nonNullValueAndProp } from '../../utils/nonNull';
|
||||
import { IVirtualMachineWizardContext } from './IVirtualMachineWizardContext';
|
||||
|
||||
export class PublicIpCreateStep extends AzureWizardExecuteStep<IVirtualMachineWizardContext> {
|
||||
|
|
|
@ -4,12 +4,11 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { NetworkManagementClient, Subnet } from '@azure/arm-network';
|
||||
import { AzureWizardExecuteStep } from "@microsoft/vscode-azext-utils";
|
||||
import { AzureWizardExecuteStep, nonNullProp, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
|
||||
import { Progress } from "vscode";
|
||||
import { ext } from '../../extensionVariables';
|
||||
import { localize } from '../../localize';
|
||||
import { createNetworkClient } from '../../utils/azureClients';
|
||||
import { nonNullProp, nonNullValueAndProp } from '../../utils/nonNull';
|
||||
import { IVirtualMachineWizardContext } from './IVirtualMachineWizardContext';
|
||||
|
||||
export class SubnetCreateStep extends AzureWizardExecuteStep<IVirtualMachineWizardContext> {
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { OperatingSystemTypes } from "@azure/arm-compute";
|
||||
import { AzureWizardPromptStep } from "@microsoft/vscode-azext-utils";
|
||||
import { AzureWizardPromptStep, nonNullProp } from "@microsoft/vscode-azext-utils";
|
||||
import { localize } from "../../localize";
|
||||
import { nonNullProp } from "../../utils/nonNull";
|
||||
import { IVirtualMachineWizardContext } from "./IVirtualMachineWizardContext";
|
||||
|
||||
const reservedWords: string[] = ['admin', 'administrator', 'root', 'test', 'user'];
|
||||
|
|
|
@ -6,13 +6,12 @@
|
|||
import { ComputeManagementClient, HardwareProfile, LinuxConfiguration, NetworkProfile, OSProfile, StorageProfile, VirtualMachine, WindowsConfiguration } from '@azure/arm-compute';
|
||||
import { NetworkInterface } from '@azure/arm-network';
|
||||
import { LocationListStep } from '@microsoft/vscode-azext-azureutils';
|
||||
import { AzureWizardExecuteStep, callWithTelemetryAndErrorHandling, IActionContext } from "@microsoft/vscode-azext-utils";
|
||||
import { AzureWizardExecuteStep, callWithTelemetryAndErrorHandling, IActionContext, nonNullProp, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
|
||||
import { MessageItem, Progress, window } from "vscode";
|
||||
import { viewOutput } from '../../constants';
|
||||
import { ext } from '../../extensionVariables';
|
||||
import { localize } from '../../localize';
|
||||
import { createComputeClient } from '../../utils/azureClients';
|
||||
import { nonNullProp, nonNullValueAndProp } from '../../utils/nonNull';
|
||||
import { createSshKey } from '../../utils/sshUtils';
|
||||
import { IVirtualMachineWizardContext } from './IVirtualMachineWizardContext';
|
||||
|
||||
|
|
|
@ -5,12 +5,11 @@
|
|||
|
||||
import { NetworkManagementClient, VirtualNetwork } from '@azure/arm-network';
|
||||
import { LocationListStep } from '@microsoft/vscode-azext-azureutils';
|
||||
import { AzureWizardExecuteStep } from "@microsoft/vscode-azext-utils";
|
||||
import { AzureWizardExecuteStep, nonNullProp, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
|
||||
import { Progress } from "vscode";
|
||||
import { ext } from '../../extensionVariables';
|
||||
import { localize } from '../../localize';
|
||||
import { createNetworkClient } from '../../utils/azureClients';
|
||||
import { nonNullProp, nonNullValueAndProp } from '../../utils/nonNull';
|
||||
import { IVirtualMachineWizardContext } from './IVirtualMachineWizardContext';
|
||||
|
||||
export class VirtualNetworkCreateStep extends AzureWizardExecuteStep<IVirtualMachineWizardContext> {
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
import { ComputeManagementClient, ResourceSku } from "@azure/arm-compute";
|
||||
import { uiUtils } from "@microsoft/vscode-azext-azureutils";
|
||||
import { nonNullProp } from "@microsoft/vscode-azext-utils";
|
||||
import { createComputeClient } from "../../utils/azureClients";
|
||||
import { nonNullProp } from "../../utils/nonNull";
|
||||
import { IVirtualMachineWizardContext } from "./IVirtualMachineWizardContext";
|
||||
|
||||
export async function getAvailableVMLocations(context: IVirtualMachineWizardContext): Promise<string[]> {
|
||||
|
|
|
@ -4,13 +4,12 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ComputeManagementClient } from "@azure/arm-compute";
|
||||
import { IActionContext } from "@microsoft/vscode-azext-utils";
|
||||
import { IActionContext, nonNullValue } from "@microsoft/vscode-azext-utils";
|
||||
import { vmFilter } from "../constants";
|
||||
import { ext } from "../extensionVariables";
|
||||
import { localize } from "../localize";
|
||||
import { ResolvedVirtualMachineTreeItem, VirtualMachineTreeItem } from "../tree/VirtualMachineTreeItem";
|
||||
import { createComputeClient } from "../utils/azureClients";
|
||||
import { nonNullValue } from "../utils/nonNull";
|
||||
|
||||
export async function restartVirtualMachine(context: IActionContext, node?: ResolvedVirtualMachineTreeItem): Promise<void> {
|
||||
if (!node) {
|
||||
|
|
|
@ -4,13 +4,12 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ComputeManagementClient } from "@azure/arm-compute";
|
||||
import { IActionContext } from "@microsoft/vscode-azext-utils";
|
||||
import { IActionContext, nonNullValue } from "@microsoft/vscode-azext-utils";
|
||||
import { vmFilter } from "../constants";
|
||||
import { ext } from "../extensionVariables";
|
||||
import { localize } from "../localize";
|
||||
import { ResolvedVirtualMachineTreeItem, VirtualMachineTreeItem } from "../tree/VirtualMachineTreeItem";
|
||||
import { createComputeClient } from "../utils/azureClients";
|
||||
import { nonNullValue } from "../utils/nonNull";
|
||||
|
||||
export async function startVirtualMachine(context: IActionContext, node?: ResolvedVirtualMachineTreeItem): Promise<void> {
|
||||
if (!node) {
|
||||
|
|
|
@ -4,13 +4,12 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ComputeManagementClient } from "@azure/arm-compute";
|
||||
import { IActionContext } from "@microsoft/vscode-azext-utils";
|
||||
import { IActionContext, nonNullValue } from "@microsoft/vscode-azext-utils";
|
||||
import { vmFilter } from "../constants";
|
||||
import { ext } from "../extensionVariables";
|
||||
import { localize } from "../localize";
|
||||
import { ResolvedVirtualMachineTreeItem, VirtualMachineTreeItem } from "../tree/VirtualMachineTreeItem";
|
||||
import { createComputeClient } from "../utils/azureClients";
|
||||
import { nonNullValue } from "../utils/nonNull";
|
||||
|
||||
export async function stopVirtualMachine(context: IActionContext, node?: ResolvedVirtualMachineTreeItem): Promise<void> {
|
||||
if (!node) {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
import { ComputeManagementClient, InstanceViewStatus, NetworkInterfaceReference, VirtualMachine, VirtualMachineInstanceView } from '@azure/arm-compute';
|
||||
import { NetworkInterface, NetworkManagementClient, PublicIPAddress } from '@azure/arm-network';
|
||||
import { AzExtTreeItem, AzureWizard, IActionContext, ISubscriptionContext } from '@microsoft/vscode-azext-utils';
|
||||
import { AzExtTreeItem, AzureWizard, IActionContext, ISubscriptionContext, nonNullProp, nonNullValueAndProp } from '@microsoft/vscode-azext-utils';
|
||||
import { ResolvedAppResourceBase, ResolvedAppResourceTreeItem } from '@microsoft/vscode-azext-utils/hostapi';
|
||||
import { ConfirmDeleteStep } from '../commands/deleteVirtualMachine/ConfirmDeleteStep';
|
||||
import { IDeleteChildImplContext, ResourceToDelete } from '../commands/deleteVirtualMachine/deleteConstants';
|
||||
|
@ -15,7 +15,6 @@ import { localize } from '../localize';
|
|||
import { createActivityContext } from '../utils/activityUtils';
|
||||
import { createComputeClient, createNetworkClient } from '../utils/azureClients';
|
||||
import { getNameFromId, getResourceGroupFromId } from '../utils/azureUtils';
|
||||
import { nonNullProp, nonNullValueAndProp } from '../utils/nonNull';
|
||||
import { treeUtils } from '../utils/treeUtils';
|
||||
|
||||
export interface ResolvedVirtualMachine extends ResolvedAppResourceBase {
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.md in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { isNullOrUndefined } from 'util';
|
||||
|
||||
/**
|
||||
* Retrieves a property by name from an object and checks that it's not null and not undefined. It is strongly typed
|
||||
* for the property and will give a compile error if the given name is not a property of the source.
|
||||
*/
|
||||
export function nonNullProp<TSource, TKey extends keyof TSource>(source: TSource, name: TKey): NonNullable<TSource[TKey]> {
|
||||
const value: NonNullable<TSource[TKey]> = <NonNullable<TSource[TKey]>>source[name];
|
||||
return nonNullValue(value, <string>name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that a given value is not null and not undefined.
|
||||
*/
|
||||
export function nonNullValue<T>(value: T | undefined | null, propertyNameOrMessage?: string): T {
|
||||
if (isNullOrUndefined(value)) {
|
||||
throw new Error(
|
||||
'Internal error: Expected value to be neither null nor undefined'
|
||||
+ (propertyNameOrMessage ? `: ${propertyNameOrMessage}` : ''));
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that a given object is not null and not undefined.
|
||||
* Then retrieves a property by name from that object and checks that it's not null and not undefined. It is strongly typed
|
||||
* for the property and will give a compile error if the given name is not a property of the source.
|
||||
*/
|
||||
export function nonNullValueAndProp<TSource, TKey extends keyof TSource>(source: TSource | undefined, name: TKey): NonNullable<TSource[TKey]> {
|
||||
return nonNullProp(nonNullValue(source, <string>name), name);
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
import { ComputeManagementClient, SshPublicKeyGenerateKeyPairResult } from '@azure/arm-compute';
|
||||
import { LocationListStep } from '@microsoft/vscode-azext-azureutils';
|
||||
import { callWithMaskHandling, IActionContext } from '@microsoft/vscode-azext-utils';
|
||||
import { callWithMaskHandling, IActionContext, nonNullValueAndProp } from '@microsoft/vscode-azext-utils';
|
||||
import * as fse from 'fs-extra';
|
||||
import { join } from 'path';
|
||||
import * as SSHConfig from 'ssh-config';
|
||||
|
@ -17,7 +17,6 @@ import { localize } from '../localize';
|
|||
import { ResolvedVirtualMachineTreeItem, VirtualMachineTreeItem } from '../tree/VirtualMachineTreeItem';
|
||||
import { createComputeClient } from './azureClients';
|
||||
import { cpUtils } from "./cpUtils";
|
||||
import { nonNullValueAndProp } from './nonNull';
|
||||
|
||||
export async function createSshKey(context: IVirtualMachineWizardContext, vmName: string, passphrase: string): Promise<{ sshKeyName: string; keyData: string }> {
|
||||
return await callWithMaskHandling(
|
||||
|
|
Загрузка…
Ссылка в новой задаче