Skip to content

Commit

Permalink
serviceconnector: Change nonNullValue to nonNullProp (#1582)
Browse files Browse the repository at this point in the history
* Change to nonNullProp

* Change to nonNullPropAndValue
  • Loading branch information
motm32 authored Sep 19, 2023
1 parent 89cc483 commit 10be48e
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 29 deletions.
12 changes: 6 additions & 6 deletions serviceconnector/src/createLinker/LinkerCreateStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzureWizardExecuteStep, GenericTreeItem, nonNullProp, nonNullValue, randomUtils } from "@microsoft/vscode-azext-utils";
import { AzureWizardExecuteStep, GenericTreeItem, nonNullProp, nonNullValueAndProp, randomUtils } from "@microsoft/vscode-azext-utils";
import * as vscode from 'vscode';
import { TargetServiceTypeName } from "../../constants";
import { createLinkerClient } from "../linkerClient";
Expand All @@ -25,8 +25,8 @@ export class LinkerCreateStep extends AzureWizardExecuteStep<ICreateLinkerContex
clientType: context.clientType
};

await client.linker.beginCreateOrUpdateAndWait(nonNullValue(context.sourceResourceUri), nonNullValue(context.linkerName), context.linker);
const config = await client.linker.listConfigurations(nonNullValue(context.sourceResourceUri), nonNullValue(context.linkerName));
await client.linker.beginCreateOrUpdateAndWait(nonNullProp(context, 'sourceResourceUri'), nonNullProp(context, 'linkerName'), context.linker);
const config = await client.linker.listConfigurations(nonNullProp(context, 'sourceResourceUri'), nonNullProp(context, 'linkerName'));

context.activityChildren = [];
for (const item of nonNullProp(config, 'configurations')) {
Expand All @@ -45,11 +45,11 @@ export class LinkerCreateStep extends AzureWizardExecuteStep<ICreateLinkerContex
private getSourceResourceId(context: ICreateLinkerContext): string {
switch (context.targetService?.group) {
case TargetServiceTypeName.Storage:
return nonNullValue(context.storageAccount?.id);
return nonNullValueAndProp(context.storageAccount, 'id');
case TargetServiceTypeName.CosmosDB:
return nonNullValue(context.databaseAccount?.id);
return nonNullValueAndProp(context.databaseAccount, 'id');
case TargetServiceTypeName.KeyVault:
return nonNullValue(context.keyVaultAccount?.id);
return nonNullValueAndProp(context.keyVaultAccount, 'id');
default:
throw new Error(vscode.l10n.t('No target type found'));
}
Expand Down
4 changes: 2 additions & 2 deletions serviceconnector/src/createLinker/LinkerNameStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzureWizardPromptStep, nonNullValue, randomUtils } from '@microsoft/vscode-azext-utils';
import { AzureWizardPromptStep, nonNullValueAndProp, randomUtils } from '@microsoft/vscode-azext-utils';
import * as vscode from 'vscode';
import { ICreateLinkerContext } from './ICreateLinkerContext';

export class LinkerNameStep extends AzureWizardPromptStep<ICreateLinkerContext>{
public async prompt(context: ICreateLinkerContext): Promise<void> {
context.linkerName = await context.ui.showInputBox({
prompt: vscode.l10n.t('Enter a name for the connection'),
value: nonNullValue(context.targetServiceType?.name) + '_' + randomUtils.getRandomHexString(5),
value: nonNullValueAndProp(context.targetServiceType, 'name') + '_' + randomUtils.getRandomHexString(5),
validateInput: this.validateInput
});
}
Expand Down
6 changes: 3 additions & 3 deletions serviceconnector/src/deleteLinker/DeleteLinkerStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzureWizardExecuteStep, GenericTreeItem, nonNullProp, nonNullValue, randomUtils } from "@microsoft/vscode-azext-utils";
import { AzureWizardExecuteStep, GenericTreeItem, nonNullProp, randomUtils } from "@microsoft/vscode-azext-utils";
import { createLinkerClient } from "../linkerClient";
import { IPickLinkerContext } from "./IPickLinkerContext";

Expand All @@ -12,7 +12,7 @@ export class DeleteLinkerStep extends AzureWizardExecuteStep<IPickLinkerContext>

public async execute(context: IPickLinkerContext): Promise<void> {
const client = await createLinkerClient(context);
const config = await client.linker.listConfigurations(nonNullValue(context.sourceResourceUri), nonNullValue(context.linkerName));
const config = await client.linker.listConfigurations(nonNullProp(context, 'sourceResourceUri'), nonNullProp(context, 'linkerName'));

context.activityChildren = [];
for (const item of nonNullProp(config, 'configurations')) {
Expand All @@ -23,7 +23,7 @@ export class DeleteLinkerStep extends AzureWizardExecuteStep<IPickLinkerContext>
}));
}

await client.linker.beginDeleteAndWait(nonNullValue(context.sourceResourceUri), nonNullValue(context.linkerName));
await client.linker.beginDeleteAndWait(nonNullProp(context, 'sourceResourceUri'), nonNullProp(context, 'linkerName'));
}

public shouldExecute(): boolean {
Expand Down
6 changes: 3 additions & 3 deletions serviceconnector/src/deleteLinker/LinkerListStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { uiUtils } from "@microsoft/vscode-azext-azureutils";
import { AzureWizardPromptStep, IAzureQuickPickItem, nonNullValue } from "@microsoft/vscode-azext-utils";
import { AzureWizardPromptStep, IAzureQuickPickItem, nonNullProp } from "@microsoft/vscode-azext-utils";
import * as vscode from 'vscode';
import { createLinkerClient } from "../linkerClient";
import { IPickLinkerContext } from "./IPickLinkerContext";
Expand All @@ -20,9 +20,9 @@ export class LinkerListStep extends AzureWizardPromptStep<IPickLinkerContext>{

private async getPicks(context: IPickLinkerContext): Promise<IAzureQuickPickItem<string>[]> {
const client = await createLinkerClient(context);
const linkers = (await uiUtils.listAllIterator(client.linker.list(nonNullValue(context.sourceResourceUri))));
const linkers = (await uiUtils.listAllIterator(client.linker.list(nonNullProp(context, 'sourceResourceUri'))));
return linkers.map(l => {
return { label: nonNullValue(l.name), data: nonNullValue(l.name) }
return { label: nonNullProp(l, 'name'), data: nonNullProp(l, 'name') }
});
}
}
6 changes: 3 additions & 3 deletions serviceconnector/src/tree/ServiceConnectorGroupItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { uiUtils } from "@microsoft/vscode-azext-azureutils";
import { ISubscriptionContext, TreeElementBase, callWithTelemetryAndErrorHandling, createSubscriptionContext, nonNullValue } from "@microsoft/vscode-azext-utils";
import { ISubscriptionContext, TreeElementBase, callWithTelemetryAndErrorHandling, createSubscriptionContext, nonNullProp, nonNullValue } from "@microsoft/vscode-azext-utils";
import * as vscode from 'vscode';
import { TreeItem, TreeItemCollapsibleState } from "vscode";
import { LinkerItem } from "../createLinker/createLinker";
Expand All @@ -22,11 +22,11 @@ export class ServiceConnectorGroupItem implements TreeElementBase {
async getChildren(): Promise<ServiceConnectorItem[]> {
const result = await callWithTelemetryAndErrorHandling('getChildren', async () => {
const client = new (await import('@azure/arm-servicelinker')).ServiceLinkerManagementClient(this.subscription.credentials);
const linkers = (await uiUtils.listAllIterator(client.linker.list(nonNullValue(this.item.id))));
const linkers = (await uiUtils.listAllIterator(client.linker.list(nonNullProp(this.item, 'id'))));
return linkers.map(linker => createServiceConnectorItem(this.subscription, this.item, linker));
});

return nonNullValue(result);
return nonNullValue(result, 'getChildren');
}

getTreeItem(): TreeItem {
Expand Down
4 changes: 2 additions & 2 deletions serviceconnector/src/tree/ServiceConnectorGroupTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { uiUtils } from "@microsoft/vscode-azext-azureutils";
import { AzExtParentTreeItem, AzExtTreeItem, TreeItemIconPath, createContextValue, nonNullValue } from "@microsoft/vscode-azext-utils";
import { AzExtParentTreeItem, AzExtTreeItem, TreeItemIconPath, createContextValue, nonNullProp } from "@microsoft/vscode-azext-utils";
import * as vscode from 'vscode';
import { getIconPath } from "./IconPath";
import { ServiceConnectorTreeItem } from "./ServiceConnectorTreeItem";
Expand All @@ -16,7 +16,7 @@ export class ServiceConnectorGroupTreeItem extends AzExtParentTreeItem {

public async loadMoreChildrenImpl(): Promise<AzExtTreeItem[]> {
const client = new (await import('@azure/arm-servicelinker')).ServiceLinkerManagementClient(this.subscription.credentials);
const linkers = (await uiUtils.listAllIterator(client.linker.list(nonNullValue(this.resourceId))));
const linkers = (await uiUtils.listAllIterator(client.linker.list(nonNullProp(this, 'resourceId'))));

const children = await this.createTreeItemsWithErrorHandling(
linkers,
Expand Down
6 changes: 3 additions & 3 deletions serviceconnector/src/tree/ServiceConnectorItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { AzureResource, LinkerResource, TargetServiceBaseUnion } from "@azure/arm-servicelinker";
import { ISubscriptionContext, TreeElementBase, nonNullValue } from "@microsoft/vscode-azext-utils";
import { ISubscriptionContext, TreeElementBase, nonNullProp } from "@microsoft/vscode-azext-utils";
import { ThemeIcon, TreeItem } from "vscode";
import { LinkerItem } from "../createLinker/createLinker";
import { getIconPath } from "./IconPath";
Expand Down Expand Up @@ -36,9 +36,9 @@ export function createServiceConnectorItem(subscription: ISubscriptionContext, i


export function connectionIconPath(linker: LinkerResource): string {
const targetResource = nonNullValue(linker.targetService)
const targetResource = nonNullProp(linker, 'targetService')
if (isAzureResource(targetResource)) {
const id: string = nonNullValue(targetResource.id)
const id: string = nonNullProp(targetResource, 'id')
if (id.includes('Microsoft.Storage')) {
return 'AzureStorageAccount';
} else if (id.includes('Microsoft.DBforPostgreSQL')) {
Expand Down
4 changes: 2 additions & 2 deletions serviceconnector/src/tree/ServiceConnectorTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { LinkerResource } from "@azure/arm-servicelinker";
import { AzExtParentTreeItem, AzExtTreeItem, TreeItemIconPath, createContextValue, nonNullValue } from "@microsoft/vscode-azext-utils";
import { AzExtParentTreeItem, AzExtTreeItem, TreeItemIconPath, createContextValue, nonNullProp } from "@microsoft/vscode-azext-utils";
import { ThemeIcon } from "vscode";
import { getIconPath } from "./IconPath";
import { connectionIconPath } from "./ServiceConnectorItem";
Expand All @@ -25,7 +25,7 @@ export class ServiceConnectorTreeItem extends AzExtTreeItem {
}

public get label(): string {
return nonNullValue(this.linker.name);
return nonNullProp(this.linker, 'name');
}

public get contextValue(): string {
Expand Down
10 changes: 5 additions & 5 deletions serviceconnector/src/validateLinker/ValidateLinkerStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzureWizardExecuteStep, GenericTreeItem, nonNullValue, randomUtils } from "@microsoft/vscode-azext-utils";
import { AzureWizardExecuteStep, GenericTreeItem, nonNullProp, randomUtils } from "@microsoft/vscode-azext-utils";
import { ThemeColor, ThemeIcon } from "vscode";
import { IPickLinkerContext } from "../deleteLinker/IPickLinkerContext";
import { createLinkerClient } from "../linkerClient";
Expand All @@ -13,22 +13,22 @@ export class ValidateLinkerStep extends AzureWizardExecuteStep<IPickLinkerContex

public async execute(context: IPickLinkerContext): Promise<void> {
const client = await createLinkerClient(context);
const response = await client.linker.beginValidateAndWait(nonNullValue(context.sourceResourceUri), nonNullValue(context.linkerName));
const response = await client.linker.beginValidateAndWait(nonNullProp(context, 'sourceResourceUri'), nonNullProp(context, 'linkerName'));

context.activityChildren = [];

for (const detail of nonNullValue(response.validationDetail)) {
for (const detail of nonNullProp(response, 'validationDetail')) {
if (detail.result === "failure") {
context.activityChildren.push(new GenericTreeItem(undefined, {
contextValue: `validateResult-${detail.name}-` + randomUtils.getRandomHexString(3),
label: nonNullValue(detail.name),
label: nonNullProp(detail, 'name'),
iconPath: new ThemeIcon('error', new ThemeColor('testing.iconFailed'))
}));
throw new Error(detail.description);
} else {
context.activityChildren.push(new GenericTreeItem(undefined, {
contextValue: `validateResult-${detail.name}` + randomUtils.getRandomHexString(3),
label: nonNullValue(detail.name),
label: nonNullProp(detail, 'name'),
iconPath: new ThemeIcon('pass', new ThemeColor('testing.iconPassed'))
}));
}
Expand Down

0 comments on commit 10be48e

Please sign in to comment.