Numerous packages for security updates
This commit is contained in:
Родитель
37f453030b
Коммит
931b5cfaec
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
77
package.json
77
package.json
|
@ -790,52 +790,51 @@
|
|||
"webpack-dev": "rimraf dist && webpack --mode development --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/body-parser": "^1.16.8",
|
||||
"@types/express": "^4.11.1",
|
||||
"@types/fs-extra": "^5.0.4",
|
||||
"@types/keytar": "^4.4.0",
|
||||
"@types/mocha": "^2.2.32",
|
||||
"@types/node": "^10.12.3",
|
||||
"@types/terser-webpack-plugin": "^1.2.0",
|
||||
"@types/webpack": "^4.4.24",
|
||||
"copy-webpack-plugin": "^5.0.5",
|
||||
"@types/body-parser": "^1.19.0",
|
||||
"@types/express": "^4.17.7",
|
||||
"@types/fs-extra": "^9.0.1",
|
||||
"@types/keytar": "^4.4.2",
|
||||
"@types/mocha": "^8.0.2",
|
||||
"@types/node": "^14.6.0",
|
||||
"@types/node-fetch": "^2.5.7",
|
||||
"@types/terser-webpack-plugin": "^4.1.0",
|
||||
"@types/webpack": "^4.41.21",
|
||||
"copy-webpack-plugin": "^6.0.3",
|
||||
"fail-on-errors-webpack-plugin": "^3.0.0",
|
||||
"mocha": "^5.1.1",
|
||||
"rimraf": "^2.6.2",
|
||||
"mocha": "^8.1.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"shebang-loader": "0.0.1",
|
||||
"terser-webpack-plugin": "^2.2.2",
|
||||
"ts-loader": "^5.3.1",
|
||||
"tslint": "^4.5.1",
|
||||
"typescript": "^3.0.0",
|
||||
"terser-webpack-plugin": "^4.1.0",
|
||||
"ts-loader": "^8.0.2",
|
||||
"tslint": "^6.1.3",
|
||||
"typescript": "^3.9.7",
|
||||
"vscode": "^1.1.37",
|
||||
"webpack": "^4.27.1",
|
||||
"webpack-cli": "^3.1.2"
|
||||
"webpack": "^4.44.1",
|
||||
"webpack-cli": "^3.3.12"
|
||||
},
|
||||
"dependencies": {
|
||||
"@azure/event-hubs": "^2.0.0",
|
||||
"ajv": "^6.10.0",
|
||||
"axios": "^0.18.1",
|
||||
"azure-arm-deviceprovisioningservices": "^2.1.0",
|
||||
"azure-arm-eventhub": "^3.2.0",
|
||||
"azure-arm-iothub": "^2.0.1",
|
||||
"azure-arm-resource": "^2.0.0-preview",
|
||||
"azure-iot-common": "^1.8.1",
|
||||
"azure-iot-device": "^1.8.1",
|
||||
"azure-iot-device-mqtt": "^1.8.1",
|
||||
"azure-iothub": "^1.8.1",
|
||||
"@azure/arm-deviceprovisioningservices": "^2.1.0",
|
||||
"@azure/arm-eventhub": "^3.2.0",
|
||||
"@azure/arm-iothub": "^3.0.0",
|
||||
"@azure/arm-subscriptions": "^2.0.0",
|
||||
"@azure/event-hubs": "^5.2.2",
|
||||
"@azure/ms-rest-azure-env": "^2.0.0",
|
||||
"@azure/ms-rest-nodeauth": "^3.0.5",
|
||||
"ajv": "^6.12.4",
|
||||
"axios": "^0.19.2",
|
||||
"azure-iot-device-mqtt": "^1.15.0",
|
||||
"azure-iothub": "^1.12.4",
|
||||
"body-parser": "^1.18.2",
|
||||
"express": "^4.16.3",
|
||||
"fecha": "^1.1.0",
|
||||
"fs-extra": "^7.0.0",
|
||||
"handlebars": "^4.3.0",
|
||||
"ms-rest": "^2.3.2",
|
||||
"ms-rest-azure": "^2.5.5",
|
||||
"numbro": "^1.6.2",
|
||||
"replace-in-file": "^3.4.0",
|
||||
"seedrandom": "^2.4.2",
|
||||
"strip-json-comments": "^2.0.1",
|
||||
"uuid": "^3.3.2",
|
||||
"vscode-azureextensionui": "^0.28.2",
|
||||
"fecha": "^4.2.0",
|
||||
"fs-extra": "^9.0.1",
|
||||
"handlebars": "^4.7.6",
|
||||
"numbro": "^2.3.1",
|
||||
"replace-in-file": "^6.1.0",
|
||||
"seedrandom": "^3.0.5",
|
||||
"strip-json-comments": "^3.1.1",
|
||||
"uuid": "^8.3.0",
|
||||
"vscode-azureextensionui": "^0.35.0",
|
||||
"vscode-extension-telemetry": "^0.1.6"
|
||||
},
|
||||
"extensionDependencies": [
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { RoutingEventHubProperties } from "azure-arm-iothub/lib/models";
|
||||
import { IotHubModels } from "@azure/arm-iothub";
|
||||
import { TreeItem } from "vscode";
|
||||
import { AzureSubscription } from "../azure-account.api";
|
||||
|
||||
export class EventHubItem extends TreeItem {
|
||||
constructor(
|
||||
public readonly azureSubscription: AzureSubscription,
|
||||
public readonly eventHubProperty: RoutingEventHubProperties) {
|
||||
public readonly eventHubProperty: IotHubModels.RoutingEventHubProperties) {
|
||||
super(eventHubProperty.name);
|
||||
this.contextValue = "event-hub";
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
import { QuickPickItem } from "vscode";
|
||||
import { IotHubDescription } from "../../node_modules/azure-arm-iothub/lib/models";
|
||||
import { IotHubModels } from "@azure/arm-iothub";
|
||||
import { Utility } from "../utility";
|
||||
|
||||
export class IotHubItem implements QuickPickItem {
|
||||
public readonly label: string;
|
||||
public readonly description: string;
|
||||
constructor(public readonly iotHubDescription: IotHubDescription) {
|
||||
constructor(public readonly iotHubDescription: IotHubModels.IotHubDescription) {
|
||||
this.label = iotHubDescription.name;
|
||||
this.description = Utility.getResourceGroupNameFromId(iotHubDescription.id);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { SubscriptionModels } from "azure-arm-resource";
|
||||
import { SubscriptionModels } from "@azure/arm-subscriptions";
|
||||
import { QuickPickItem } from "vscode";
|
||||
|
||||
export class LocationItem implements QuickPickItem {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { ResourceModels } from "azure-arm-resource";
|
||||
import { ResourceManagementModels } from "@azure/arm-resources";
|
||||
import { QuickPickItem } from "vscode";
|
||||
|
||||
export class ResourceGroupItem implements QuickPickItem {
|
||||
public readonly label: string;
|
||||
public readonly description: string;
|
||||
constructor(public readonly resourceGroup: ResourceModels.ResourceGroup) {
|
||||
constructor(public readonly resourceGroup: ResourceManagementModels.ResourceGroup) {
|
||||
this.label = resourceGroup.name;
|
||||
this.description = resourceGroup.location;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { SubscriptionModels } from "azure-arm-resource";
|
||||
import { SubscriptionModels } from "@azure/arm-subscriptions";
|
||||
import { QuickPickItem } from "vscode";
|
||||
import { AzureSession } from "../azure-account.api";
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { IotDpsModels } from "azure-arm-deviceprovisioningservices";
|
||||
import { IotDpsModels } from "@azure/arm-deviceprovisioningservices";
|
||||
import { AzureParentTreeItem, AzureTreeItem, TreeItemIconPath } from "vscode-azureextensionui";
|
||||
import { TreeUtils } from "../../Utility/treeUtils";
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { IotDpsClient, IotDpsModels } from "azure-arm-deviceprovisioningservices";
|
||||
import { IotDpsClient, IotDpsModels } from "@azure/arm-deviceprovisioningservices";
|
||||
import { createAzureClient, IActionContext, SubscriptionTreeItemBase } from "vscode-azureextensionui";
|
||||
import { DpsResourceTreeItem } from "./DpsResourceTreeItem";
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ export class DeviceLabelNode implements INode {
|
|||
try {
|
||||
const deviceList: vscode.TreeItem[] = await Utility.getDeviceList(this.iotHubConnectionString, Constants.ExtensionContext);
|
||||
|
||||
let deviceNode: INode[] = deviceList.map((item) => new DeviceNode(item as DeviceItem));
|
||||
const deviceNode: INode[] = deviceList.map((item) => new DeviceNode(item as DeviceItem));
|
||||
|
||||
if (deviceNode.length === 0) {
|
||||
deviceNode.push(new InfoNode(`No devices in ${Utility.getHostName(this.iotHubConnectionString)}`));
|
||||
|
|
|
@ -22,7 +22,7 @@ export class DeviceNode implements INode {
|
|||
}
|
||||
|
||||
public async getChildren(context: vscode.ExtensionContext, iotHubConnectionString: string): Promise<INode[]> {
|
||||
let nodeList: INode[] = [];
|
||||
const nodeList: INode[] = [];
|
||||
nodeList.push(new ModuleLabelNode(this));
|
||||
if (this.deviceItem.contextValue === "device" && iotHubConnectionString.toLowerCase().indexOf("azure-devices.cn;") < 0) {
|
||||
nodeList.push(new DistributedTracingLabelNode(this));
|
||||
|
|
|
@ -23,7 +23,7 @@ export class DistributedTracingLabelNode implements INode {
|
|||
}
|
||||
|
||||
public getChildren(): INode[] {
|
||||
let twinNodeList: INode[] = [];
|
||||
const twinNodeList: INode[] = [];
|
||||
twinNodeList.push(new TwinNode(new TwinItem("Desired", DeviceTwinPropertyType.Desired), this.deviceNode));
|
||||
twinNodeList.push(new TwinNode(new TwinItem("Reported", DeviceTwinPropertyType.Reported), this.deviceNode));
|
||||
return twinNodeList;
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import IotHubClient from "azure-arm-iothub";
|
||||
import { IotHubClient } from "@azure/arm-iothub";
|
||||
import * as vscode from "vscode";
|
||||
import { createAzureClient} from "vscode-azureextensionui";
|
||||
import { Constants } from "../../constants";
|
||||
import { TelemetryClient } from "../../telemetryClient";
|
||||
import { Utility } from "../../utility";
|
||||
|
@ -35,7 +36,11 @@ export class EndpointsLabelNode implements INode {
|
|||
}
|
||||
|
||||
const subscription = accountApi.subscriptions.find((element) => element.subscription.subscriptionId === subscriptionId);
|
||||
const client = new IotHubClient(subscription.session.credentials, subscription.subscription.subscriptionId, subscription.session.environment.resourceManagerEndpointUrl);
|
||||
const client = createAzureClient({
|
||||
credentials: subscription.session.credentials2,
|
||||
subscriptionId: subscription.subscription.subscriptionId,
|
||||
environment: subscription.session.environment
|
||||
}, IotHubClient);
|
||||
const iotHubs = await client.iotHubResource.listBySubscription();
|
||||
const iothub = iotHubs.find((element) =>
|
||||
element.id === Constants.ExtensionContext.globalState.get(Constants.StateKeyIoTHubID));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { RoutingEventHubProperties } from "azure-arm-iothub/lib/models";
|
||||
import { IotHubModels } from "@azure/arm-iothub";
|
||||
import * as vscode from "vscode";
|
||||
import { AzureSubscription } from "../../azure-account.api";
|
||||
import { EventHubItem } from "../../Model/EventHubItem";
|
||||
|
@ -9,7 +9,7 @@ import { INode } from "../INode";
|
|||
import { EventHubItemNode } from "./EventHubItemNode";
|
||||
|
||||
export class EventHubLabelNode implements INode {
|
||||
constructor(private azureSubscription: AzureSubscription, private eventHubProperties: RoutingEventHubProperties[]) {
|
||||
constructor(private azureSubscription: AzureSubscription, private eventHubProperties: IotHubModels.RoutingEventHubProperties[]) {
|
||||
}
|
||||
|
||||
public getTreeItem(): vscode.TreeItem {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { IotHubModels } from "azure-arm-iothub";
|
||||
import { IotHubModels } from "@azure/arm-iothub";
|
||||
import { AzureParentTreeItem, AzureTreeItem, TreeItemIconPath } from "vscode-azureextensionui";
|
||||
import { TreeUtils } from "../../Utility/treeUtils";
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { IotHubClient, IotHubModels } from "azure-arm-iothub";
|
||||
import { IotHubClient, IotHubModels } from "@azure/arm-iothub";
|
||||
import { createAzureClient, IActionContext, SubscriptionTreeItemBase } from "vscode-azureextensionui";
|
||||
import { IoTHubResourceTreeItem } from "./IoTHubResourceTreeItem";
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ export class ModuleLabelNode implements INode {
|
|||
const moduleList: vscode.TreeItem[] = await Utility.getModuleItemsForEdge(iotHubConnectionString, this.deviceNode.deviceItem, context);
|
||||
TelemetryClient.sendEvent(Constants.IoTHubAILoadEdgeModuleTreeDoneEvent, { Result: "Success" });
|
||||
|
||||
let moduleNodeList: INode[] = [];
|
||||
const moduleNodeList: INode[] = [];
|
||||
moduleList.forEach((item) => {
|
||||
moduleNodeList.push(new ModuleItemNode(item as ModuleItem, this));
|
||||
});
|
||||
|
@ -50,7 +50,7 @@ export class ModuleLabelNode implements INode {
|
|||
moduleList.push(new vscode.TreeItem(`No Modules`));
|
||||
}
|
||||
|
||||
let moduleNodeList: INode[] = [];
|
||||
const moduleNodeList: INode[] = [];
|
||||
moduleList.forEach((item) => {
|
||||
moduleNodeList.push(new ModuleItemNode(item as ModuleItem, this));
|
||||
});
|
||||
|
|
|
@ -25,13 +25,13 @@ export class TwinNode implements INode {
|
|||
}
|
||||
|
||||
public async getChildren(context: vscode.ExtensionContext, iotHubConnectionString: string): Promise<INode[]> {
|
||||
let registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
const registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
|
||||
TelemetryClient.sendEvent(Constants.IoTHubAILoadDistributedTracingSettingTreeStartEvent, null, iotHubConnectionString);
|
||||
const items: INode[] = [];
|
||||
|
||||
try {
|
||||
let twin = await Utility.getTwin(registry, this.deviceNode.deviceId);
|
||||
const twin = await Utility.getTwin(registry, this.deviceNode.deviceId);
|
||||
let samplingRate = null;
|
||||
let enabled = null;
|
||||
if (this.twinItem.type === DeviceTwinPropertyType.Desired) {
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Event, Terminal, Progress, CancellationToken } from 'vscode';
|
||||
import { ServiceClientCredentials } from 'ms-rest';
|
||||
import { AzureEnvironment } from 'ms-rest-azure';
|
||||
import { SubscriptionModels } from 'azure-arm-resource';
|
||||
import { SubscriptionModels } from "@azure/arm-subscriptions";
|
||||
import { Environment } from "@azure/ms-rest-azure-env";
|
||||
import { ReadStream } from 'fs';
|
||||
import { TokenCredentialsBase } from '@azure/ms-rest-nodeauth';
|
||||
|
||||
export type AzureLoginStatus = 'Initializing' | 'LoggingIn' | 'LoggedIn' | 'LoggedOut';
|
||||
|
||||
|
@ -27,10 +27,10 @@ export interface AzureAccount {
|
|||
}
|
||||
|
||||
export interface AzureSession {
|
||||
readonly environment: AzureEnvironment;
|
||||
readonly environment: Environment;
|
||||
readonly userId: string;
|
||||
readonly tenantId: string;
|
||||
readonly credentials: ServiceClientCredentials;
|
||||
readonly credentials2: TokenCredentialsBase;
|
||||
}
|
||||
|
||||
export interface AzureSubscription {
|
||||
|
|
|
@ -63,7 +63,7 @@ export class CodeManager {
|
|||
}
|
||||
const folder = folderUri[0].fsPath;
|
||||
await fs.copy(template, folder);
|
||||
await replace({
|
||||
await replace.replaceInFile({
|
||||
files: `${folder}/**/*`,
|
||||
from: [...replacements.keys()],
|
||||
to: [...replacements.values()],
|
||||
|
|
|
@ -17,13 +17,13 @@ export class DeviceExplorer extends BaseExplorer {
|
|||
}
|
||||
|
||||
public async listDevice() {
|
||||
let label = "Device";
|
||||
let iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
const label = "Device";
|
||||
const iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
if (!iotHubConnectionString) {
|
||||
return;
|
||||
}
|
||||
|
||||
let registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
const registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
this._outputChannel.show();
|
||||
this.outputLine(label, "Querying devices...");
|
||||
TelemetryClient.sendEvent(`AZ.${label}.List`);
|
||||
|
@ -36,7 +36,7 @@ export class DeviceExplorer extends BaseExplorer {
|
|||
}
|
||||
|
||||
public async getDevice(deviceItem: DeviceItem, iotHubConnectionString?: string, outputChannel: vscode.OutputChannel = this._outputChannel) {
|
||||
let label = "Device";
|
||||
const label = "Device";
|
||||
if (!iotHubConnectionString) {
|
||||
iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
if (!iotHubConnectionString) {
|
||||
|
@ -49,8 +49,8 @@ export class DeviceExplorer extends BaseExplorer {
|
|||
return;
|
||||
}
|
||||
|
||||
let hostName = Utility.getHostName(iotHubConnectionString);
|
||||
let registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
const hostName = Utility.getHostName(iotHubConnectionString);
|
||||
const registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
outputChannel.show();
|
||||
this.outputLine(label, `Querying device [${deviceItem.deviceId}]...`, outputChannel);
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -92,12 +92,12 @@ export class DeviceExplorer extends BaseExplorer {
|
|||
}
|
||||
|
||||
public async deleteDevice(deviceItem?: DeviceItem) {
|
||||
let label = "Device";
|
||||
let iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
const label = "Device";
|
||||
const iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
if (!iotHubConnectionString) {
|
||||
return;
|
||||
}
|
||||
let registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
const registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
|
||||
deviceItem = await Utility.getInputDevice(deviceItem, "AZ.Device.Delete.Start");
|
||||
if (deviceItem && deviceItem.label) {
|
||||
|
|
|
@ -37,7 +37,7 @@ export class DeviceTree implements vscode.TreeDataProvider<INode> {
|
|||
}
|
||||
|
||||
public async getChildren(element?: INode): Promise<INode[]> {
|
||||
let iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle, false);
|
||||
const iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle, false);
|
||||
if (!iotHubConnectionString) {
|
||||
return Utility.getDefaultTreeItems();
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ export class DeviceTree implements vscode.TreeDataProvider<INode> {
|
|||
}
|
||||
|
||||
private generateAutoRefreshInterval(): NodeJS.Timer {
|
||||
let treeViewAutoRefreshEnable = Utility.getConfig<boolean>(Constants.TreeViewAutoRefreshEnableKey);
|
||||
const treeViewAutoRefreshEnable = Utility.getConfig<boolean>(Constants.TreeViewAutoRefreshEnableKey);
|
||||
if (treeViewAutoRefreshEnable) {
|
||||
let treeViewAutoRefreshIntervalInSeconds = Utility.getConfig<number>(Constants.TreeViewAutoRefreshIntervalInSecondsKey);
|
||||
const treeViewAutoRefreshIntervalInSeconds = Utility.getConfig<number>(Constants.TreeViewAutoRefreshIntervalInSecondsKey);
|
||||
return setInterval(() => {
|
||||
this._onDidChangeTreeData.fire();
|
||||
}, treeViewAutoRefreshIntervalInSeconds * 1000);
|
||||
|
|
|
@ -18,7 +18,7 @@ export class DistributedTracingManager extends BaseExplorer {
|
|||
}
|
||||
|
||||
public async updateDistributedTracingSetting(node, updateType: DistributedSettingUpdateType) {
|
||||
let iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
const iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
if (!iotHubConnectionString) {
|
||||
return;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ export class DistributedTracingManager extends BaseExplorer {
|
|||
|
||||
let deviceIds: string[] = [];
|
||||
if (!node || !node.deviceNode) {
|
||||
let selectedDeviceIds: string[] = await vscode.window.showQuickPick(
|
||||
const selectedDeviceIds: string[] = await vscode.window.showQuickPick(
|
||||
Utility.getNoneEdgeDeviceIdList(iotHubConnectionString),
|
||||
{ placeHolder: "Select devices...", ignoreFocusOut: true, canPickMany: true },
|
||||
);
|
||||
|
@ -47,10 +47,10 @@ export class DistributedTracingManager extends BaseExplorer {
|
|||
}
|
||||
|
||||
public async updateDistributedTracingSettingForDevices(deviceIds: string[], iotHubConnectionString: string, updateType: DistributedSettingUpdateType, node) {
|
||||
let registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
const registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
|
||||
let mode: boolean = undefined;
|
||||
let samplingRate: number = undefined;
|
||||
let mode: boolean;
|
||||
let samplingRate: number;
|
||||
let twin;
|
||||
|
||||
if (deviceIds.length === 1) {
|
||||
|
@ -76,7 +76,7 @@ export class DistributedTracingManager extends BaseExplorer {
|
|||
}
|
||||
|
||||
if (updateType !== DistributedSettingUpdateType.OnlySamplingRate) {
|
||||
let selectedItem: SamplingModeItem = await vscode.window.showQuickPick(
|
||||
const selectedItem: SamplingModeItem = await vscode.window.showQuickPick(
|
||||
this.getSamplingModePickupItems(),
|
||||
{ placeHolder: "Select whether to enable/disable the distributed tracing...", ignoreFocusOut: true },
|
||||
);
|
||||
|
@ -134,7 +134,7 @@ export class DistributedTracingManager extends BaseExplorer {
|
|||
}
|
||||
|
||||
private async updateDeviceTwin(enable: boolean, samplingRate: number, iotHubConnectionString: string, deviceIds: string[]): Promise<any> {
|
||||
let twinPatch = {
|
||||
const twinPatch = {
|
||||
etag: "*",
|
||||
properties: {
|
||||
desired: {},
|
||||
|
@ -158,7 +158,7 @@ export class DistributedTracingManager extends BaseExplorer {
|
|||
}
|
||||
|
||||
if (deviceIds.length === 1) {
|
||||
let registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
const registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
await registry.updateTwin(deviceIds[0], JSON.stringify(twinPatch), twinPatch.etag);
|
||||
return;
|
||||
}
|
||||
|
@ -167,12 +167,12 @@ export class DistributedTracingManager extends BaseExplorer {
|
|||
}
|
||||
|
||||
private async scheduleTwinUpdate(twinPatch, iotHubConnectionString: string, deviceIds: string[]): Promise<any> {
|
||||
let twinJobId = uuid.v4();
|
||||
let jobClient = iothub.JobClient.fromConnectionString(iotHubConnectionString);
|
||||
const twinJobId = uuid.v4();
|
||||
const jobClient = iothub.JobClient.fromConnectionString(iotHubConnectionString);
|
||||
|
||||
let queryCondition = this.generateQureyCondition(deviceIds);
|
||||
let startTime = new Date();
|
||||
let maxExecutionTimeInSeconds = 300;
|
||||
const queryCondition = this.generateQureyCondition(deviceIds);
|
||||
const startTime = new Date();
|
||||
const maxExecutionTimeInSeconds = 300;
|
||||
|
||||
await jobClient.scheduleTwinUpdate(twinJobId, queryCondition, twinPatch, startTime, maxExecutionTimeInSeconds);
|
||||
return this.monitorJob(twinJobId, jobClient);
|
||||
|
@ -185,7 +185,7 @@ export class DistributedTracingManager extends BaseExplorer {
|
|||
|
||||
private async monitorJob(jobId, jobClient): Promise<any> {
|
||||
return new Promise<any>(async (resolve, reject) => {
|
||||
let jobMonitorInterval = setInterval(async () => {
|
||||
const jobMonitorInterval = setInterval(async () => {
|
||||
try {
|
||||
const result = await jobClient.getJob(jobId);
|
||||
if (result.jobStatus.status === "completed" || result.jobStatus.status === "failed" || result.jobStatus.status === "cancelled") {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
import { IotDpsClient, IotDpsModels } from "azure-arm-deviceprovisioningservices";
|
||||
import { IotDpsClient, IotDpsModels } from "@azure/arm-deviceprovisioningservices";
|
||||
import * as vscode from "vscode";
|
||||
import { AzExtTreeDataProvider, AzureTreeItem, createAzureClient, IActionContext, openReadOnlyJson } from "vscode-azureextensionui";
|
||||
import { BaseExplorer } from "./baseExplorer";
|
||||
|
@ -21,15 +21,15 @@ export class DpsResourceExplorer extends BaseExplorer {
|
|||
}
|
||||
|
||||
const client: IotDpsClient = createAzureClient(node.root, IotDpsClient);
|
||||
let matchResult = Constants.DpsResourceGroupNameRegex.exec(node.fullId);
|
||||
const matchResult = Constants.DpsResourceGroupNameRegex.exec(node.fullId);
|
||||
let dpsInfo: IotDpsModels.ProvisioningServiceDescription = null;
|
||||
if (matchResult != null) {
|
||||
let resourecGroupName = matchResult[1];
|
||||
const resourecGroupName = matchResult[1];
|
||||
dpsInfo = await client.iotDpsResource.get(node.dps.name, resourecGroupName);
|
||||
} else {
|
||||
dpsInfo = node.dps; // Fallback to use cached properties if regex match fails
|
||||
}
|
||||
let propertyInfo = {
|
||||
const propertyInfo = {
|
||||
label: dpsInfo.name + "-properties",
|
||||
fullId: dpsInfo.id,
|
||||
};
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { EventData, EventHubClient, EventPosition, MessagingError, OnError, OnMessage } from "@azure/event-hubs";
|
||||
import EventHubManagementClient from "azure-arm-eventhub";
|
||||
import { ReceivedEventData, EventHubConsumerClient, MessagingError } from "@azure/event-hubs";
|
||||
import { EventHubManagementClient } from "@azure/arm-eventhub";
|
||||
import * as vscode from "vscode";
|
||||
import { Constants } from "./constants";
|
||||
import { IoTHubMessageBaseExplorer } from "./iotHubMessageBaseExplorer";
|
||||
import { EventHubItem } from "./Model/EventHubItem";
|
||||
import { TelemetryClient } from "./telemetryClient";
|
||||
import { Utility } from "./utility";
|
||||
import { createAzureClient } from "vscode-azureextensionui";
|
||||
|
||||
export class EventHubManager extends IoTHubMessageBaseExplorer {
|
||||
private _eventHubClient: EventHubClient;
|
||||
private _eventHubClient: EventHubConsumerClient;
|
||||
|
||||
constructor(outputChannel: vscode.OutputChannel) {
|
||||
super(outputChannel, "$(primitive-square) Stop Monitoring Custom Event Hub Endpoint", "azure-iot-toolkit.stopMonitorCustomEventHubEndpoint");
|
||||
|
@ -29,19 +30,28 @@ export class EventHubManager extends IoTHubMessageBaseExplorer {
|
|||
this._outputChannel.show();
|
||||
this.outputLine(Constants.EventHubMonitorLabel, `Start monitoring message arrived in custom Event Hub endpoint [${eventHubItem.eventHubProperty.name}] ...`);
|
||||
|
||||
const eventHubClient = new EventHubManagementClient(
|
||||
eventHubItem.azureSubscription.session.credentials,
|
||||
eventHubItem.azureSubscription.subscription.subscriptionId,
|
||||
eventHubItem.azureSubscription.session.environment.resourceManagerEndpointUrl);
|
||||
const eventHubClient = createAzureClient({
|
||||
credentials: eventHubItem.azureSubscription.session.credentials2,
|
||||
environment: eventHubItem.azureSubscription.session.environment,
|
||||
subscriptionId: eventHubItem.azureSubscription.subscription.subscriptionId
|
||||
}, EventHubManagementClient);
|
||||
|
||||
const connectionString = (await eventHubClient.namespaces.listKeys(eventHubItem.eventHubProperty.resourceGroup,
|
||||
this.getNamespacefromConnectionString(eventHubItem.eventHubProperty.connectionString), "RootManageSharedAccessKey")).primaryConnectionString;
|
||||
this._eventHubClient = EventHubClient.createFromConnectionString(connectionString, this.getEntityPathfromConnectionString(eventHubItem.eventHubProperty.connectionString));
|
||||
this._eventHubClient = new EventHubConsumerClient("$Default", connectionString, this.getEntityPathfromConnectionString(eventHubItem.eventHubProperty.connectionString));
|
||||
const partitionIds = await this._eventHubClient.getPartitionIds();
|
||||
this.updateMonitorStatus(true);
|
||||
partitionIds.forEach((partitionId) => {
|
||||
this.outputLine(Constants.EventHubMonitorLabel, `Created partition receiver [${partitionId}]`);
|
||||
this._eventHubClient.receive(partitionId, this.onMessage, this.onError, { eventPosition: EventPosition.fromEnqueuedTime(Date.now()) });
|
||||
this._eventHubClient.subscribe(partitionId,
|
||||
{
|
||||
processEvents: this.onMessage,
|
||||
processError: this.onError
|
||||
},
|
||||
{
|
||||
startPosition: {enqueuedOn: Date.now()}
|
||||
}
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
this.updateMonitorStatus(false);
|
||||
|
@ -54,14 +64,17 @@ export class EventHubManager extends IoTHubMessageBaseExplorer {
|
|||
this.stopMonitorEventHubEndpoint(Constants.EventHubMonitorLabel, Constants.IoTHubAIEHStopMonitorEvent, this._eventHubClient, "custom Event Hub endpoint");
|
||||
}
|
||||
|
||||
private onMessage: OnMessage = (message: EventData) => {
|
||||
const result = Utility.getMessageFromEventData(message);
|
||||
const timeMessage = Utility.getTimeMessageFromEventData(message);
|
||||
this.outputLine(Constants.EventHubMonitorLabel, `${timeMessage}Message received:`);
|
||||
this._outputChannel.appendLine(JSON.stringify(result, null, 2));
|
||||
private onMessage = async (messages: ReceivedEventData[]) => {
|
||||
messages.forEach(message => {
|
||||
|
||||
const result = Utility.getMessageFromEventData(message);
|
||||
const timeMessage = Utility.getTimeMessageFromEventData(message);
|
||||
this.outputLine(Constants.EventHubMonitorLabel, `${timeMessage}Message received:`);
|
||||
this._outputChannel.appendLine(JSON.stringify(result, null, 2));
|
||||
});
|
||||
}
|
||||
|
||||
private onError: OnError = (error: MessagingError | Error) => {
|
||||
private onError = async (error: MessagingError | Error) => {
|
||||
this.outputLine(Constants.EventHubMonitorLabel, error.message);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,43 +49,43 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
return azureIoTExplorer.getDevice(deviceNode ? deviceNode.deviceItem : undefined);
|
||||
}));
|
||||
|
||||
let sendD2CMessage = vscode.commands.registerCommand("azure-iot-toolkit.sendD2CMessage", async (deviceNode: DeviceNode) => {
|
||||
const sendD2CMessage = vscode.commands.registerCommand("azure-iot-toolkit.sendD2CMessage", async (deviceNode: DeviceNode) => {
|
||||
await azureIoTExplorer.showSimulatorWebview(deviceNode ? deviceNode.deviceItem : undefined);
|
||||
});
|
||||
|
||||
let startMonitorIoTHubMessage = vscode.commands.registerCommand("azure-iot-toolkit.startMonitorIoTHubMessage", (deviceNode: DeviceNode) => {
|
||||
const startMonitorIoTHubMessage = vscode.commands.registerCommand("azure-iot-toolkit.startMonitorIoTHubMessage", (deviceNode: DeviceNode) => {
|
||||
azureIoTExplorer.startMonitorIoTHubMessage(deviceNode ? deviceNode.deviceItem : undefined);
|
||||
});
|
||||
|
||||
let stopMonitorIoTHubMessage = vscode.commands.registerCommand("azure-iot-toolkit.stopMonitorIoTHubMessage", () => {
|
||||
const stopMonitorIoTHubMessage = vscode.commands.registerCommand("azure-iot-toolkit.stopMonitorIoTHubMessage", () => {
|
||||
azureIoTExplorer.stopMonitorIoTHubMessage();
|
||||
});
|
||||
|
||||
let sendC2DMessage = vscode.commands.registerCommand("azure-iot-toolkit.sendC2DMessage", (deviceNode: DeviceNode) => {
|
||||
const sendC2DMessage = vscode.commands.registerCommand("azure-iot-toolkit.sendC2DMessage", (deviceNode: DeviceNode) => {
|
||||
azureIoTExplorer.sendC2DMessage(deviceNode ? deviceNode.deviceItem : undefined);
|
||||
});
|
||||
|
||||
let startMonitorC2DMessage = vscode.commands.registerCommand("azure-iot-toolkit.startMonitorC2DMessage", (deviceNode: DeviceNode) => {
|
||||
const startMonitorC2DMessage = vscode.commands.registerCommand("azure-iot-toolkit.startMonitorC2DMessage", (deviceNode: DeviceNode) => {
|
||||
azureIoTExplorer.startMonitorC2DMessage(deviceNode ? deviceNode.deviceItem : undefined);
|
||||
});
|
||||
|
||||
let stopMonitorC2DMessage = vscode.commands.registerCommand("azure-iot-toolkit.stopMonitorC2DMessage", () => {
|
||||
const stopMonitorC2DMessage = vscode.commands.registerCommand("azure-iot-toolkit.stopMonitorC2DMessage", () => {
|
||||
azureIoTExplorer.stopMonitorC2DMessage();
|
||||
});
|
||||
|
||||
let listDevice = vscode.commands.registerCommand("azure-iot-toolkit.listDevice", () => {
|
||||
const listDevice = vscode.commands.registerCommand("azure-iot-toolkit.listDevice", () => {
|
||||
azureIoTExplorer.listDevice();
|
||||
});
|
||||
|
||||
let createDevice = vscode.commands.registerCommand("azure-iot-toolkit.createDevice", async () => {
|
||||
const createDevice = vscode.commands.registerCommand("azure-iot-toolkit.createDevice", async () => {
|
||||
return azureIoTExplorer.createDevice();
|
||||
});
|
||||
|
||||
let deleteDevice = vscode.commands.registerCommand("azure-iot-toolkit.deleteDevice", async (deviceNode: DeviceNode) => {
|
||||
const deleteDevice = vscode.commands.registerCommand("azure-iot-toolkit.deleteDevice", async (deviceNode: DeviceNode) => {
|
||||
await azureIoTExplorer.deleteDevice(deviceNode ? deviceNode.deviceItem : undefined);
|
||||
});
|
||||
|
||||
let invokeDeviceMethod = vscode.commands.registerCommand("azure-iot-toolkit.invokeDeviceMethod", (deviceNode: DeviceNode) => {
|
||||
const invokeDeviceMethod = vscode.commands.registerCommand("azure-iot-toolkit.invokeDeviceMethod", (deviceNode: DeviceNode) => {
|
||||
azureIoTExplorer.invokeDeviceDirectMethod(deviceNode ? deviceNode.deviceItem : undefined);
|
||||
});
|
||||
|
||||
|
@ -93,25 +93,25 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
azureIoTExplorer.invokeModuleDirectMethod(moduleItemNode ? moduleItemNode.moduleItem : undefined);
|
||||
}));
|
||||
|
||||
let getDeviceTwin = vscode.commands.registerCommand("azure-iot-toolkit.getDeviceTwin", (deviceNode: DeviceNode) => {
|
||||
const getDeviceTwin = vscode.commands.registerCommand("azure-iot-toolkit.getDeviceTwin", (deviceNode: DeviceNode) => {
|
||||
azureIoTExplorer.getDeviceTwin(deviceNode ? deviceNode.deviceItem : undefined);
|
||||
});
|
||||
|
||||
let updateDistributedTracingSetting = vscode.commands.registerCommand("azure-iot-toolkit.updateDistributedTracingSetting", (node) => {
|
||||
const updateDistributedTracingSetting = vscode.commands.registerCommand("azure-iot-toolkit.updateDistributedTracingSetting", (node) => {
|
||||
// Todo: Determine why the parameter is not null when triggered from context menu of custom panel
|
||||
// https://github.com/microsoft/vscode/issues/94872
|
||||
azureIoTExplorer.updateDistributedTracingSetting(node);
|
||||
});
|
||||
|
||||
let editDistributedTracingMode = vscode.commands.registerCommand("azure-iot-toolkit.editDistributedTracingMode", (node) => {
|
||||
const editDistributedTracingMode = vscode.commands.registerCommand("azure-iot-toolkit.editDistributedTracingMode", (node) => {
|
||||
azureIoTExplorer.updateDistributedTracingSetting(node, DistributedSettingUpdateType.OnlyMode);
|
||||
});
|
||||
|
||||
let editDistributedTracingSamplingRate = vscode.commands.registerCommand("azure-iot-toolkit.editDistributedTracingSamplingRate", (node) => {
|
||||
const editDistributedTracingSamplingRate = vscode.commands.registerCommand("azure-iot-toolkit.editDistributedTracingSamplingRate", (node) => {
|
||||
azureIoTExplorer.updateDistributedTracingSetting(node, DistributedSettingUpdateType.OnlySamplingRate);
|
||||
});
|
||||
|
||||
let updateDeviceTwin = vscode.commands.registerCommand("azure-iot-toolkit.updateDeviceTwin", () => {
|
||||
const updateDeviceTwin = vscode.commands.registerCommand("azure-iot-toolkit.updateDeviceTwin", () => {
|
||||
azureIoTExplorer.updateDeviceTwin();
|
||||
});
|
||||
|
||||
|
@ -119,15 +119,15 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
azureIoTExplorer.createIoTHub();
|
||||
}));
|
||||
|
||||
let selectIoTHub = vscode.commands.registerCommand("azure-iot-toolkit.selectIoTHub", () => {
|
||||
const selectIoTHub = vscode.commands.registerCommand("azure-iot-toolkit.selectIoTHub", () => {
|
||||
azureIoTExplorer.selectIoTHub();
|
||||
});
|
||||
|
||||
let copyIoTHubConnectionString = vscode.commands.registerCommand("azure-iot-toolkit.copyIoTHubConnectionString", async () => {
|
||||
const copyIoTHubConnectionString = vscode.commands.registerCommand("azure-iot-toolkit.copyIoTHubConnectionString", async () => {
|
||||
await azureIoTExplorer.copyIoTHubConnectionString();
|
||||
});
|
||||
|
||||
let copyDeviceConnectionString = vscode.commands.registerCommand("azure-iot-toolkit.copyDeviceConnectionString", async (deviceNode: DeviceNode) => {
|
||||
const copyDeviceConnectionString = vscode.commands.registerCommand("azure-iot-toolkit.copyDeviceConnectionString", async (deviceNode: DeviceNode) => {
|
||||
await azureIoTExplorer.copyDeviceConnectionString(deviceNode ? deviceNode.deviceItem : undefined);
|
||||
});
|
||||
|
||||
|
@ -135,7 +135,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
await azureIoTExplorer.createDevice(true);
|
||||
}));
|
||||
|
||||
let createDeployment = vscode.commands.registerCommand("azure-iot-toolkit.createDeployment", (input) => {
|
||||
const createDeployment = vscode.commands.registerCommand("azure-iot-toolkit.createDeployment", (input) => {
|
||||
azureIoTExplorer.createDeployment(input);
|
||||
});
|
||||
|
||||
|
@ -251,13 +251,13 @@ function initializeTreeView(context: vscode.ExtensionContext) {
|
|||
}
|
||||
|
||||
function activateDps(context: vscode.ExtensionContext, outputChannel: vscode.OutputChannel) {
|
||||
let dpsTreeItem = new DpsAccountTreeItem();
|
||||
let dpsExtTreeDataProvider = new AzExtTreeDataProvider(dpsTreeItem, "azure-iot-dps.loadMore");
|
||||
const dpsTreeItem = new DpsAccountTreeItem();
|
||||
const dpsExtTreeDataProvider = new AzExtTreeDataProvider(dpsTreeItem, "azure-iot-dps.loadMore");
|
||||
|
||||
context.subscriptions.push(dpsTreeItem);
|
||||
context.subscriptions.push(vscode.window.createTreeView("iotDpsExplorer", { treeDataProvider: dpsExtTreeDataProvider, showCollapseAll: true }));
|
||||
|
||||
let azureDpsExplorer = new AzureDpsExplorer(outputChannel, dpsExtTreeDataProvider);
|
||||
const azureDpsExplorer = new AzureDpsExplorer(outputChannel, dpsExtTreeDataProvider);
|
||||
|
||||
registerCommand("azure-iot-dps.viewProperties", async (actionContext: IActionContext, node?: DpsResourceTreeItem) => {
|
||||
await azureDpsExplorer.viewProperties(actionContext, node);
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
"use strict";
|
||||
import * as Ajv from "ajv";
|
||||
import Ajv from "ajv";
|
||||
import axios from "axios";
|
||||
import * as iothub from "azure-iothub";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import * as stripJsonComments from "strip-json-comments";
|
||||
import stripJsonComments from "strip-json-comments";
|
||||
import * as vscode from "vscode";
|
||||
import { BaseExplorer } from "./baseExplorer";
|
||||
import { Constants } from "./constants";
|
||||
|
@ -24,7 +24,7 @@ export class IoTEdgeExplorer extends BaseExplorer {
|
|||
public async createDeployment(input?: DeviceNode | vscode.Uri) {
|
||||
TelemetryClient.sendEvent(Constants.IoTHubAIEdgeDeployStartEvent);
|
||||
|
||||
let iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
const iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
if (!iotHubConnectionString) {
|
||||
return;
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ export class IoTEdgeExplorer extends BaseExplorer {
|
|||
|
||||
let content = stripJsonComments(fs.readFileSync(filePath, "utf8"));
|
||||
try {
|
||||
let contentJson = JSON.parse(content);
|
||||
const contentJson = JSON.parse(content);
|
||||
// Backward compatibility for old schema using 'moduleContent'
|
||||
if (!contentJson.modulesContent && contentJson.moduleContent) {
|
||||
contentJson.modulesContent = contentJson.moduleContent;
|
||||
|
|
|
@ -21,7 +21,7 @@ export class IotHubC2DMessageExplorer extends IoTHubMessageBaseExplorer {
|
|||
}
|
||||
|
||||
public async sendC2DMessage(deviceItem?: DeviceItem) {
|
||||
let iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
const iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
if (!iotHubConnectionString) {
|
||||
return;
|
||||
}
|
||||
|
@ -66,13 +66,13 @@ export class IotHubC2DMessageExplorer extends IoTHubMessageBaseExplorer {
|
|||
private sendC2DMessageById(iotHubConnectionString: string, deviceId: string): void {
|
||||
vscode.window.showInputBox({ prompt: `Enter message to send to device` }).then((messageBody) => {
|
||||
if (messageBody !== undefined) {
|
||||
let serviceClient = ServiceClient.fromConnectionString(iotHubConnectionString);
|
||||
const serviceClient = ServiceClient.fromConnectionString(iotHubConnectionString);
|
||||
this._outputChannel.show();
|
||||
serviceClient.open((err) => {
|
||||
if (err) {
|
||||
this.outputLine(Constants.IoTHubC2DMessageLabel, err.message);
|
||||
} else {
|
||||
let message = new Message(messageBody);
|
||||
const message = new Message(messageBody);
|
||||
serviceClient.send(deviceId, message.getData(),
|
||||
this.sendEventDone(serviceClient, Constants.IoTHubC2DMessageLabel, deviceId, Constants.IoTHubAIC2DMessageDoneEvent));
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ export class IotHubC2DMessageExplorer extends IoTHubMessageBaseExplorer {
|
|||
TelemetryClient.sendEvent(Constants.IoTHubAIStartMonitorC2DEvent, { Result: "Exception", [Constants.errorProperties.Message]: err });
|
||||
} else {
|
||||
this.updateMonitorStatus(true);
|
||||
let deviceId = ConnectionString.parse(deviceConnectionString).DeviceId;
|
||||
const deviceId = ConnectionString.parse(deviceConnectionString).DeviceId;
|
||||
this.outputLine(Constants.IoTHubC2DMessageMonitorLabel, `Start receiving C2D message for [${deviceId}]...`);
|
||||
TelemetryClient.sendEvent(Constants.IoTHubAIStartMonitorC2DEvent);
|
||||
this._deviceClient.on("message", (msg) => {
|
||||
|
|
|
@ -24,13 +24,13 @@ export class IotHubDeviceTwinExplorer extends BaseExplorer {
|
|||
}
|
||||
|
||||
public async getDeviceTwinById(deviceId: string) {
|
||||
let iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
const iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
if (!iotHubConnectionString) {
|
||||
return;
|
||||
}
|
||||
|
||||
TelemetryClient.sendEvent(Constants.IoTHubAIGetDeviceTwinDoneEvent);
|
||||
let registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
const registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
this._outputChannel.show();
|
||||
this.outputLine(Constants.IoTHubDeviceTwinLabel, `Get Device Twin for [${deviceId}]...`);
|
||||
registry.getTwin(deviceId, (err, twin) => {
|
||||
|
@ -52,20 +52,20 @@ export class IotHubDeviceTwinExplorer extends BaseExplorer {
|
|||
|
||||
public async updateDeviceTwin() {
|
||||
TelemetryClient.sendEvent(Constants.IoTHubAIUpdateDeviceTwinEvent);
|
||||
let iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
const iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
if (!iotHubConnectionString) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this._outputChannel.show();
|
||||
let deviceTwinContent = await Utility.readFromActiveFile(Constants.DeviceTwinJosnFileName);
|
||||
const deviceTwinContent = await Utility.readFromActiveFile(Constants.DeviceTwinJosnFileName);
|
||||
if (!deviceTwinContent) {
|
||||
return;
|
||||
}
|
||||
let deviceTwinJson = JSON.parse(deviceTwinContent);
|
||||
const deviceTwinJson = JSON.parse(deviceTwinContent);
|
||||
this.outputLine(Constants.IoTHubDeviceTwinLabel, `Update Device Twin for [${deviceTwinJson.deviceId}]...`);
|
||||
let registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
const registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
|
||||
registry.updateTwin(deviceTwinJson.deviceId, deviceTwinContent, deviceTwinJson.etag, (err) => {
|
||||
if (err) {
|
||||
this.outputLine(Constants.IoTHubDeviceTwinLabel, `Failed to update Device Twin: ${err.message}`);
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
"use strict";
|
||||
import { Client as ServiceClient, DeviceMethodParams } from "azure-iothub";
|
||||
import { IncomingMessageCallback } from "azure-iothub/lib/interfaces";
|
||||
import * as vscode from "vscode";
|
||||
import { IncomingMessageCallback } from "azure-iothub/dist/interfaces";
|
||||
import { BaseExplorer } from "./baseExplorer";
|
||||
import { Constants } from "./constants";
|
||||
import { DeviceItem } from "./Model/DeviceItem";
|
||||
|
@ -18,7 +18,7 @@ export class IotHubDirectMethodExplorer extends BaseExplorer {
|
|||
}
|
||||
|
||||
public async invokeDeviceDirectMethod(deviceItem: DeviceItem) {
|
||||
let iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
const iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
if (!iotHubConnectionString) {
|
||||
return;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ export class IotHubDirectMethodExplorer extends BaseExplorer {
|
|||
}
|
||||
|
||||
public async invokeModuleDirectMethod(moduleItem: ModuleItem) {
|
||||
let iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
const iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
if (!iotHubConnectionString) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
"use strict";
|
||||
import { EventHubClient } from "@azure/event-hubs";
|
||||
import { EventHubConsumerClient } from "@azure/event-hubs";
|
||||
import * as vscode from "vscode";
|
||||
import { BaseExplorer } from "./baseExplorer";
|
||||
import { TelemetryClient } from "./telemetryClient";
|
||||
|
@ -29,7 +29,7 @@ export class IoTHubMessageBaseExplorer extends BaseExplorer {
|
|||
}
|
||||
}
|
||||
|
||||
protected async stopMonitorEventHubEndpoint(label: string, aiEvent: string, eventHubClient: EventHubClient, endpointType: string) {
|
||||
protected async stopMonitorEventHubEndpoint(label: string, aiEvent: string, eventHubClient: EventHubConsumerClient, endpointType: string) {
|
||||
TelemetryClient.sendEvent(aiEvent);
|
||||
this._outputChannel.show();
|
||||
if (this._isMonitoring) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
"use strict";
|
||||
import { EventData, EventHubClient, EventPosition } from "@azure/event-hubs";
|
||||
import { EventHubConsumerClient, ReceivedEventData, EventPosition } from "@azure/event-hubs";
|
||||
import { Message } from "azure-iot-device";
|
||||
import { clientFromConnectionString } from "azure-iot-device-mqtt";
|
||||
import * as vscode from "vscode";
|
||||
|
@ -13,8 +13,8 @@ import { TelemetryClient } from "./telemetryClient";
|
|||
import { Utility } from "./utility";
|
||||
|
||||
export class IoTHubMessageExplorer extends IoTHubMessageBaseExplorer {
|
||||
private _eventHubClient: EventHubClient;
|
||||
|
||||
private _iotHubConnectionString: string;
|
||||
private _eventHubClient: EventHubConsumerClient;
|
||||
constructor(outputChannel: vscode.OutputChannel) {
|
||||
super(outputChannel, "$(primitive-square) Stop Monitoring built-in event endpoint", "azure-iot-toolkit.stopMonitorIoTHubMessage");
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ export class IoTHubMessageExplorer extends IoTHubMessageBaseExplorer {
|
|||
if (message !== undefined) {
|
||||
this._outputChannel.show();
|
||||
try {
|
||||
let client = clientFromConnectionString(deviceConnectionString);
|
||||
let stringify = Utility.getConfig<boolean>(Constants.IoTHubD2CMessageStringifyKey);
|
||||
const client = clientFromConnectionString(deviceConnectionString);
|
||||
const stringify = Utility.getConfig<boolean>(Constants.IoTHubD2CMessageStringifyKey);
|
||||
client.sendEvent(new Message(stringify ? JSON.stringify(message) : message),
|
||||
this.sendEventDone(client, Constants.IoTHubMessageLabel, Constants.IoTHub, Constants.IoTHubAIMessageDoneEvent));
|
||||
} catch (e) {
|
||||
|
@ -47,18 +47,18 @@ export class IoTHubMessageExplorer extends IoTHubMessageBaseExplorer {
|
|||
return;
|
||||
}
|
||||
|
||||
let iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
const iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
|
||||
if (!iotHubConnectionString) {
|
||||
return;
|
||||
}
|
||||
let config = Utility.getConfiguration();
|
||||
let consumerGroup = config.get<string>(Constants.IoTHubConsumerGroup);
|
||||
const config = Utility.getConfiguration();
|
||||
const consumerGroup = config.get<string>(Constants.IoTHubConsumerGroup);
|
||||
|
||||
try {
|
||||
this._iotHubConnectionString = iotHubConnectionString
|
||||
this._outputChannel.show();
|
||||
const deviceLabel = deviceItem ? `device [${deviceItem.deviceId}]` : "all devices";
|
||||
this.outputLine(Constants.IoTHubMonitorLabel, `Start monitoring message arrived in built-in endpoint for ${deviceLabel} ...`);
|
||||
this._eventHubClient = await EventHubClient.createFromIotHubConnectionString(iotHubConnectionString);
|
||||
TelemetryClient.sendEvent(Constants.IoTHubAIStartMonitorEvent, { deviceType: deviceItem ? deviceItem.contextValue : "" });
|
||||
await this.startMonitor(Constants.IoTHubMonitorLabel, consumerGroup, deviceItem);
|
||||
this.updateMonitorStatus(true);
|
||||
|
@ -74,24 +74,26 @@ export class IoTHubMessageExplorer extends IoTHubMessageBaseExplorer {
|
|||
}
|
||||
|
||||
private async startMonitor(label: string, consumerGroup: string, deviceItem?: DeviceItem) {
|
||||
if (this._eventHubClient) {
|
||||
if (this._iotHubConnectionString) {
|
||||
this._eventHubClient = new EventHubConsumerClient(consumerGroup, this._iotHubConnectionString);
|
||||
const monitorD2CBeforeNowInMinutes = Utility.getConfiguration().get<number>("monitorD2CBeforeNowInMinutes");
|
||||
const startAfterTime = new Date(Date.now() - 1000 * 60 * monitorD2CBeforeNowInMinutes);
|
||||
const partitionIds = await this._eventHubClient.getPartitionIds();
|
||||
partitionIds.forEach((partitionId) => {
|
||||
this.outputLine(label, `Created partition receiver [${partitionId}] for consumerGroup [${consumerGroup}]`);
|
||||
this._eventHubClient.receive(partitionId,
|
||||
this.printMessage(this._outputChannel, label, deviceItem),
|
||||
this.printError(this._outputChannel, label),
|
||||
this._eventHubClient.subscribe(partitionId,
|
||||
{
|
||||
eventPosition: EventPosition.fromEnqueuedTime(startAfterTime),
|
||||
consumerGroup,
|
||||
processEvents: this.printMessage(label, deviceItem),
|
||||
processError: this.printError(label)
|
||||
},
|
||||
{
|
||||
startPosition: {enqueuedOn: startAfterTime }
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private printError(outputChannel: vscode.OutputChannel, label: string) {
|
||||
private printError(label: string) {
|
||||
return async (err) => {
|
||||
this.outputLine(label, err.message);
|
||||
if (this._isMonitoring) {
|
||||
|
@ -102,18 +104,20 @@ export class IoTHubMessageExplorer extends IoTHubMessageBaseExplorer {
|
|||
};
|
||||
};
|
||||
|
||||
private printMessage(outputChannel: vscode.OutputChannel, label: string, deviceItem?: DeviceItem) {
|
||||
return async (message: EventData) => {
|
||||
const deviceId = message.annotations["iothub-connection-device-id"];
|
||||
const moduleId = message.annotations["iothub-connection-module-id"];
|
||||
if (deviceItem && deviceItem.deviceId !== deviceId) {
|
||||
return;
|
||||
}
|
||||
const result = Utility.getMessageFromEventData(message);
|
||||
const timeMessage = Utility.getTimeMessageFromEventData(message);
|
||||
const messageSource = moduleId ? `${deviceId}/${moduleId}` : deviceId;
|
||||
this.outputLine(label, `${timeMessage}Message received from [${messageSource}]:`);
|
||||
this._outputChannel.appendLine(JSON.stringify(result, null, 2));
|
||||
private printMessage(label: string, deviceItem?: DeviceItem) {
|
||||
return async (messages: ReceivedEventData[]) => {
|
||||
messages.forEach(message => {
|
||||
const deviceId = (message as any).annotations["iothub-connection-device-id"];
|
||||
const moduleId = (message as any).annotations["iothub-connection-module-id"];
|
||||
if (deviceItem && deviceItem.deviceId !== deviceId) {
|
||||
return;
|
||||
}
|
||||
const result = Utility.getMessageFromEventData(message);
|
||||
const timeMessage = Utility.getTimeMessageFromEventData(message);
|
||||
const messageSource = moduleId ? `${deviceId}/${moduleId}` : deviceId;
|
||||
this.outputLine(label, `${timeMessage}Message received from [${messageSource}]:`);
|
||||
this._outputChannel.appendLine(JSON.stringify(result, null, 2));
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,13 +2,11 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
"use strict";
|
||||
import { IotHubClient } from "azure-arm-iothub";
|
||||
import { ResourceManagementClient, ResourceModels, SubscriptionClient } from "azure-arm-resource";
|
||||
import { ServiceClientCredentials } from "ms-rest";
|
||||
import { AzureEnvironment } from "ms-rest-azure";
|
||||
import { ResourceManagementClient, ResourceManagementModels } from "@azure/arm-resources";
|
||||
import { SubscriptionClient } from "@azure/arm-subscriptions";
|
||||
import * as vscode from "vscode";
|
||||
import { AzExtTreeDataProvider, AzureTreeItem, IActionContext } from "vscode-azureextensionui";
|
||||
import { IotHubDescription } from "../node_modules/azure-arm-iothub/lib/models";
|
||||
import { AzExtTreeDataProvider, AzureTreeItem, IActionContext, createAzureClient, createAzureSubscriptionClient } from "vscode-azureextensionui";
|
||||
import { IotHubModels, IotHubClient } from "@azure/arm-iothub";
|
||||
import { AzureAccount } from "./azure-account.api";
|
||||
import { BaseExplorer } from "./baseExplorer";
|
||||
import { Constants } from "./constants";
|
||||
|
@ -21,6 +19,7 @@ import { SubscriptionItem } from "./Model/SubscriptionItem";
|
|||
import { IoTHubResourceTreeItem } from "./Nodes/IoTHub/IoTHubResourceTreeItem";
|
||||
import { TelemetryClient } from "./telemetryClient";
|
||||
import { Utility } from "./utility";
|
||||
import { Environment } from "@azure/ms-rest-azure-env";
|
||||
|
||||
export class IoTHubResourceExplorer extends BaseExplorer {
|
||||
private readonly accountApi: AzureAccount;
|
||||
|
@ -30,7 +29,7 @@ export class IoTHubResourceExplorer extends BaseExplorer {
|
|||
this.accountApi = Utility.getAzureAccountApi();
|
||||
}
|
||||
|
||||
public async createIoTHub(outputChannel: vscode.OutputChannel = this._outputChannel, subscriptionId?: string, resourceGroupName?: string): Promise<IotHubDescription> {
|
||||
public async createIoTHub(outputChannel: vscode.OutputChannel = this._outputChannel, subscriptionId?: string, resourceGroupName?: string): Promise<IotHubModels.IotHubDescription> {
|
||||
TelemetryClient.sendEvent(Constants.IoTHubAICreateStartEvent);
|
||||
if (!(await this.waitForLogin())) {
|
||||
return;
|
||||
|
@ -94,7 +93,11 @@ export class IoTHubResourceExplorer extends BaseExplorer {
|
|||
}, 1000);
|
||||
|
||||
const { session, subscription } = subscriptionItem;
|
||||
const client = new IotHubClient(session.credentials, subscription.subscriptionId, session.environment.resourceManagerEndpointUrl);
|
||||
const client = createAzureClient({
|
||||
credentials: session.credentials2,
|
||||
subscriptionId: subscription.subscriptionId,
|
||||
environment: session.environment
|
||||
}, IotHubClient);
|
||||
const iotHubCreateParams = {
|
||||
location: locationItem.location.name,
|
||||
subscriptionid: subscription.subscriptionId,
|
||||
|
@ -109,7 +112,7 @@ export class IoTHubResourceExplorer extends BaseExplorer {
|
|||
.then(async (iotHubDescription) => {
|
||||
clearInterval(intervalID);
|
||||
outputChannel.appendLine("");
|
||||
const newIotHubConnectionString = await this.updateAndStoreIoTHubInfo(subscriptionItem.session.credentials,
|
||||
const newIotHubConnectionString = await this.updateAndStoreIoTHubInfo(subscriptionItem.session.credentials2,
|
||||
subscriptionItem.subscription.subscriptionId, subscriptionItem.session.environment , iotHubDescription);
|
||||
outputChannel.appendLine(`IoT Hub '${name}' is created.`);
|
||||
(iotHubDescription as any).iotHubConnectionString = newIotHubConnectionString;
|
||||
|
@ -134,7 +137,7 @@ export class IoTHubResourceExplorer extends BaseExplorer {
|
|||
});
|
||||
}
|
||||
|
||||
public async selectIoTHub(outputChannel: vscode.OutputChannel = this._outputChannel, subscriptionId?: string): Promise<IotHubDescription> {
|
||||
public async selectIoTHub(outputChannel: vscode.OutputChannel = this._outputChannel, subscriptionId?: string): Promise<IotHubModels.IotHubDescription> {
|
||||
TelemetryClient.sendEvent("General.Select.IoTHub.Start");
|
||||
if (!(await this.waitForLogin())) {
|
||||
return;
|
||||
|
@ -149,7 +152,7 @@ export class IoTHubResourceExplorer extends BaseExplorer {
|
|||
if (iotHubItem) {
|
||||
outputChannel.show();
|
||||
outputChannel.appendLine(`IoT Hub selected: ${iotHubItem.label}`);
|
||||
const iotHubConnectionString = await this.updateAndStoreIoTHubInfo(subscriptionItem.session.credentials,
|
||||
const iotHubConnectionString = await this.updateAndStoreIoTHubInfo(subscriptionItem.session.credentials2,
|
||||
subscriptionItem.subscription.subscriptionId, subscriptionItem.session.environment , iotHubItem.iotHubDescription);
|
||||
(iotHubItem.iotHubDescription as any).iotHubConnectionString = iotHubConnectionString;
|
||||
TelemetryClient.sendEvent("AZ.Select.IoTHub.Done", undefined, iotHubConnectionString);
|
||||
|
@ -244,10 +247,14 @@ export class IoTHubResourceExplorer extends BaseExplorer {
|
|||
return subscriptionItems;
|
||||
}
|
||||
|
||||
private async loadIoTHubItems(subscriptionItem: SubscriptionItem) {
|
||||
private async loadIoTHubItems(subscriptionItem: SubscriptionItem): Promise<IotHubItem[]> {
|
||||
const iotHubItems: IotHubItem[] = [];
|
||||
const { session, subscription } = subscriptionItem;
|
||||
const client = new IotHubClient(session.credentials, subscription.subscriptionId, session.environment.resourceManagerEndpointUrl);
|
||||
const client = createAzureClient({
|
||||
credentials: session.credentials2,
|
||||
subscriptionId: subscription.subscriptionId,
|
||||
environment: session.environment
|
||||
}, IotHubClient);
|
||||
const iotHubs = await client.iotHubResource.listBySubscription();
|
||||
iotHubItems.push(...iotHubs.map((iotHub) => new IotHubItem(iotHub)));
|
||||
iotHubItems.sort((a, b) => a.label.localeCompare(b.label));
|
||||
|
@ -275,7 +282,12 @@ export class IoTHubResourceExplorer extends BaseExplorer {
|
|||
return iotHubItem;
|
||||
}
|
||||
|
||||
private async updateAndStoreIoTHubInfo(credentials: ServiceClientCredentials, subscriptionId: string, environment: AzureEnvironment, iotHubDescription: IotHubDescription): Promise<string> {
|
||||
private async updateAndStoreIoTHubInfo(
|
||||
credentials: any,
|
||||
subscriptionId: string,
|
||||
environment: Environment,
|
||||
iotHubDescription: IotHubModels.IotHubDescription): Promise<string>
|
||||
{
|
||||
const iotHubConnectionString = await this.getIoTHubConnectionString(credentials,
|
||||
subscriptionId, environment, iotHubDescription);
|
||||
await this.updateIoTHubConnectionString(iotHubConnectionString);
|
||||
|
@ -288,8 +300,12 @@ export class IoTHubResourceExplorer extends BaseExplorer {
|
|||
vscode.commands.executeCommand("azure-iot-toolkit.refresh");
|
||||
}
|
||||
|
||||
private async getIoTHubConnectionString(credentials: ServiceClientCredentials, subscriptionId: string, environment: AzureEnvironment, iotHubDescription: IotHubDescription) {
|
||||
const client = new IotHubClient(credentials, subscriptionId, environment.resourceManagerEndpointUrl);
|
||||
private async getIoTHubConnectionString(credentials: any, subscriptionId: string, environment: Environment, iotHubDescription: IotHubModels.IotHubDescription) {
|
||||
const client = createAzureClient({
|
||||
credentials,
|
||||
subscriptionId,
|
||||
environment
|
||||
}, IotHubClient);
|
||||
return client.iotHubResource.getKeysForKeyName(Utility.getResourceGroupNameFromId(iotHubDescription.id), iotHubDescription.name, "iothubowner").then((result) => {
|
||||
return `HostName=${iotHubDescription.properties.hostName};SharedAccessKeyName=${result.keyName};SharedAccessKey=${result.primaryKey}`;
|
||||
});
|
||||
|
@ -297,7 +313,7 @@ export class IoTHubResourceExplorer extends BaseExplorer {
|
|||
|
||||
private async getOrSelectSubscriptionItem(outputChannel: vscode.OutputChannel, subscriptionId: string): Promise<SubscriptionItem> {
|
||||
if (subscriptionId) {
|
||||
let azureSubscription = this.accountApi.subscriptions.find((subscription) => subscription.subscription.subscriptionId === subscriptionId);
|
||||
const azureSubscription = this.accountApi.subscriptions.find((subscription) => subscription.subscription.subscriptionId === subscriptionId);
|
||||
if (azureSubscription) {
|
||||
return new SubscriptionItem(azureSubscription.subscription, azureSubscription.session);
|
||||
}
|
||||
|
@ -335,10 +351,13 @@ export class IoTHubResourceExplorer extends BaseExplorer {
|
|||
}
|
||||
|
||||
private async getResourceGroupItems(subscriptionItem: SubscriptionItem): Promise<vscode.QuickPickItem[]> {
|
||||
const resourceManagementClient = new ResourceManagementClient(subscriptionItem.session.credentials,
|
||||
subscriptionItem.subscription.subscriptionId, subscriptionItem.session.environment.resourceManagerEndpointUrl);
|
||||
const resourceManagementClient = createAzureClient({
|
||||
credentials: subscriptionItem.session.credentials2,
|
||||
subscriptionId: subscriptionItem.subscription.subscriptionId,
|
||||
environment: subscriptionItem.session.environment
|
||||
}, ResourceManagementClient);
|
||||
const resourceGroups = await resourceManagementClient.resourceGroups.list();
|
||||
let resourceGroupItems: vscode.QuickPickItem[] = [{
|
||||
const resourceGroupItems: vscode.QuickPickItem[] = [{
|
||||
label: "$(plus) Create Resource Group",
|
||||
description: null,
|
||||
}];
|
||||
|
@ -346,13 +365,19 @@ export class IoTHubResourceExplorer extends BaseExplorer {
|
|||
}
|
||||
|
||||
private async getLocationItems(subscriptionItem: SubscriptionItem): Promise<LocationItem[]> {
|
||||
const subscriptionClient = new SubscriptionClient(subscriptionItem.session.credentials, subscriptionItem.session.environment.resourceManagerEndpointUrl);
|
||||
const subscriptionClient = createAzureSubscriptionClient({
|
||||
credentials: subscriptionItem.session.credentials2,
|
||||
environment: subscriptionItem.session.environment}, SubscriptionClient);
|
||||
const locations = await subscriptionClient.subscriptions.listLocations(subscriptionItem.subscription.subscriptionId);
|
||||
return locations.map((location) => new LocationItem(location));
|
||||
}
|
||||
|
||||
private async getIoTHubName(subscriptionItem: SubscriptionItem): Promise<string> {
|
||||
const client = new IotHubClient(subscriptionItem.session.credentials, subscriptionItem.subscription.subscriptionId, subscriptionItem.session.environment.resourceManagerEndpointUrl);
|
||||
const client = createAzureClient({
|
||||
credentials: subscriptionItem.session.credentials2,
|
||||
subscriptionId: subscriptionItem.subscription.subscriptionId,
|
||||
environment: subscriptionItem.session.environment
|
||||
}, IotHubClient);
|
||||
|
||||
while (true) {
|
||||
const accountName = await vscode.window.showInputBox({
|
||||
|
@ -398,7 +423,7 @@ export class IoTHubResourceExplorer extends BaseExplorer {
|
|||
return null;
|
||||
}
|
||||
|
||||
private async createResourceGroup(subscriptionItem: SubscriptionItem): Promise<ResourceModels.ResourceGroup> {
|
||||
private async createResourceGroup(subscriptionItem: SubscriptionItem): Promise<ResourceManagementModels.ResourceGroup> {
|
||||
const resourceGroupName = await vscode.window.showInputBox({
|
||||
placeHolder: "Resource Group Name",
|
||||
prompt: "Provide a resource group name",
|
||||
|
@ -417,8 +442,11 @@ export class IoTHubResourceExplorer extends BaseExplorer {
|
|||
title: `Creating resource group '${resourceGroupName}'`,
|
||||
location: vscode.ProgressLocation.Notification,
|
||||
}, async (progress) => {
|
||||
const resourceManagementClient = new ResourceManagementClient(subscriptionItem.session.credentials,
|
||||
subscriptionItem.subscription.subscriptionId, subscriptionItem.session.environment.resourceManagerEndpointUrl);
|
||||
const resourceManagementClient = createAzureClient({
|
||||
credentials: subscriptionItem.session.credentials2,
|
||||
subscriptionId: subscriptionItem.subscription.subscriptionId,
|
||||
environment: subscriptionItem.session.environment
|
||||
}, ResourceManagementClient);
|
||||
return resourceManagementClient.resourceGroups.createOrUpdate(resourceGroupName, { location: locationItem.location.name });
|
||||
});
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ export class Simulator {
|
|||
}
|
||||
|
||||
public async launch(deviceItem: DeviceItem): Promise<void> {
|
||||
let deviceConnectionStrings = [];
|
||||
const deviceConnectionStrings = [];
|
||||
if (this.isProcessing()) {
|
||||
this.closeDuration = 3500;
|
||||
await this.showWebview(false);
|
||||
|
@ -157,7 +157,7 @@ export class Simulator {
|
|||
} else {
|
||||
// Exit when no connection string found or the connection string is invalid.
|
||||
if (!this.iotHubConnectionString) {
|
||||
let errorMessage = "Failed to launch Send D2C Messages webview: No IoT Hub Connection String Found.";
|
||||
const errorMessage = "Failed to launch Send D2C Messages webview: No IoT Hub Connection String Found.";
|
||||
vscode.window.showErrorMessage(errorMessage);
|
||||
this.telemetry(Constants.SimulatorLaunchEvent, false, {
|
||||
error: errorMessage,
|
||||
|
@ -292,7 +292,7 @@ export class Simulator {
|
|||
status: SendStatus,
|
||||
totalStatus: SendStatus,
|
||||
) {
|
||||
let stringify = Utility.getConfig<boolean>(
|
||||
const stringify = Utility.getConfig<boolean>(
|
||||
Constants.IoTHubD2CMessageStringifyKey,
|
||||
);
|
||||
await client.sendEvent(
|
||||
|
@ -341,9 +341,9 @@ export class Simulator {
|
|||
this.output(
|
||||
`Start sending messages from ${deviceCount} device(s) to IoT Hub.`,
|
||||
);
|
||||
let clients = [];
|
||||
let statuses = [];
|
||||
let ids = [];
|
||||
const clients = [];
|
||||
const statuses = [];
|
||||
const ids = [];
|
||||
this.totalStatus = new SendStatus("Total", total);
|
||||
for (let i = 0; i < deviceCount; i++) {
|
||||
clients.push(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as bodyParser from "body-parser";
|
||||
import * as express from "express";
|
||||
import express from "express";
|
||||
import * as http from "http";
|
||||
import { AddressInfo } from "net";
|
||||
import * as vscode from "vscode";
|
||||
|
@ -234,7 +234,7 @@ export class LocalServer {
|
|||
const messageType = data.messageType;
|
||||
const messageBodyType = data.messageBodyType;
|
||||
const deviceConnectionStrings: string[] = data.deviceConnectionStrings;
|
||||
let template: string = data.message;
|
||||
const template: string = data.message;
|
||||
const numbers: number = Number(data.numbers);
|
||||
const interval: number = Number(data.interval);
|
||||
switch (messageType) {
|
||||
|
|
|
@ -19,17 +19,17 @@ export class SnippetManager extends BaseExplorer {
|
|||
if (!event.contentChanges[0]) {
|
||||
return;
|
||||
}
|
||||
let changedText = event.contentChanges[0].text;
|
||||
const changedText = event.contentChanges[0].text;
|
||||
if (/\r|\n/.exec(changedText) && event.document.uri.scheme.indexOf("git") === -1) {
|
||||
let editor = vscode.window.activeTextEditor;
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
let document = editor.document;
|
||||
let text = document.getText();
|
||||
const document = editor.document;
|
||||
const text = document.getText();
|
||||
this.connectionStringKeys.forEach(async (connectionStringKey) => {
|
||||
let connectionStringValue = await Utility.getConnectionStringWithId(connectionStringKey);
|
||||
let connectionStringKeyWithAngleBracket = this.getTextWithAngleBracket(connectionStringKey);
|
||||
const connectionStringValue = await Utility.getConnectionStringWithId(connectionStringKey);
|
||||
const connectionStringKeyWithAngleBracket = this.getTextWithAngleBracket(connectionStringKey);
|
||||
if (changedText.indexOf(connectionStringKeyWithAngleBracket) > -1
|
||||
&& connectionStringValue && !connectionStringValue.startsWith("<<insert")) {
|
||||
let offset = text.indexOf(connectionStringKeyWithAngleBracket);
|
||||
|
|
|
@ -38,7 +38,7 @@ export class TelemetryClient {
|
|||
private static _isInternal: boolean = TelemetryClient.isInternalUser();
|
||||
|
||||
private static async addCommonProperties(properties?: { [key: string]: string; }, iotHubConnectionString?: string) {
|
||||
let newProperties = properties ? properties : {};
|
||||
const newProperties = properties ? properties : {};
|
||||
if (!iotHubConnectionString) {
|
||||
iotHubConnectionString = await Utility.getConnectionStringWithId(Constants.IotHubConnectionStringKey);
|
||||
if (!iotHubConnectionString) {
|
||||
|
@ -47,7 +47,7 @@ export class TelemetryClient {
|
|||
}
|
||||
|
||||
if (iotHubConnectionString) {
|
||||
let iotHubHostName = Utility.getHostName(iotHubConnectionString);
|
||||
const iotHubHostName = Utility.getHostName(iotHubConnectionString);
|
||||
if (iotHubHostName) {
|
||||
newProperties.IoTHubHostName = Utility.hash(iotHubHostName);
|
||||
newProperties.IoTHubHostNamePostfix = Utility.getPostfixFromHostName(iotHubHostName);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
import { ResultWithHttpResponse } from "azure-iot-common";
|
||||
import { ConnectionString as DeviceConnectionString, SharedAccessSignature as DeviceSharedAccessSignature } from "azure-iot-device";
|
||||
import { ConnectionString, Registry, SharedAccessSignature, Twin } from "azure-iothub";
|
||||
import { ResultWithIncomingMessage } from "azure-iothub/lib/interfaces";
|
||||
import { IotHubModels} from "@azure/arm-iothub";
|
||||
import * as crypto from "crypto";
|
||||
import * as fs from "fs";
|
||||
import * as os from "os";
|
||||
|
@ -18,13 +18,11 @@ import { CommandNode } from "./Nodes/CommandNode";
|
|||
import { InfoNode } from "./Nodes/InfoNode";
|
||||
import { INode } from "./Nodes/INode";
|
||||
import { TelemetryClient } from "./telemetryClient";
|
||||
import iothub = require("azure-iothub");
|
||||
import { EventData } from "@azure/event-hubs";
|
||||
import { AxiosRequestConfig } from "axios";
|
||||
import { IotHubDescription } from "azure-arm-iothub/lib/models";
|
||||
import { ReceivedEventData, EventData } from "@azure/event-hubs";
|
||||
import { AxiosRequestConfig, Method } from "axios";
|
||||
import { AzureAccount } from "./azure-account.api";
|
||||
import { CredentialStore } from "./credentialStore";
|
||||
import { SubscriptionItem } from "./Model/SubscriptionItem";
|
||||
import { ResultWithIncomingMessage } from "azure-iothub/dist/interfaces";
|
||||
|
||||
export class Utility {
|
||||
public static getConfiguration(): vscode.WorkspaceConfiguration {
|
||||
|
@ -86,22 +84,22 @@ export class Utility {
|
|||
}
|
||||
|
||||
public static getConfig<T>(id: string): T {
|
||||
let config = Utility.getConfiguration();
|
||||
const config = Utility.getConfiguration();
|
||||
return config.get<T>(id);
|
||||
}
|
||||
|
||||
public static getHostName(iotHubConnectionString: string): string {
|
||||
let result = /^HostName=([^=]+);/.exec(iotHubConnectionString);
|
||||
const result = /^HostName=([^=]+);/.exec(iotHubConnectionString);
|
||||
return result ? result[1] : "";
|
||||
}
|
||||
|
||||
public static getIoTHubName(iotHubConnectionString: string): string {
|
||||
let result = /^HostName=([^.]+)./.exec(iotHubConnectionString);
|
||||
const result = /^HostName=([^.]+)./.exec(iotHubConnectionString);
|
||||
return result ? result[1] : "";
|
||||
}
|
||||
|
||||
public static getPostfixFromHostName(hostName: string): string {
|
||||
let result = /^[^.]+\.(.+)$/.exec(hostName);
|
||||
const result = /^[^.]+\.(.+)$/.exec(hostName);
|
||||
return result ? result[1] : "";
|
||||
}
|
||||
|
||||
|
@ -137,7 +135,7 @@ export class Utility {
|
|||
if (terminalRoot) {
|
||||
return filePath.replace(/^([A-Za-z]):/, (match, p1) => `${terminalRoot}${p1.toLowerCase()}`).replace(/\\/g, "/");
|
||||
}
|
||||
let winshellLowercase = windowsShell.toLowerCase();
|
||||
const winshellLowercase = windowsShell.toLowerCase();
|
||||
if (winshellLowercase.indexOf("bash") > -1 && winshellLowercase.indexOf("git") > -1) {
|
||||
// Git Bash
|
||||
return filePath.replace(/^([A-Za-z]):/, (match, p1) => `/${p1.toLowerCase()}`).replace(/\\/g, "/");
|
||||
|
@ -327,7 +325,7 @@ export class Utility {
|
|||
}
|
||||
|
||||
public static getResourceGroupNameFromId(resourceId: string): string {
|
||||
let result = /resourceGroups\/([^/]+)\//.exec(resourceId);
|
||||
const result = /resourceGroups\/([^/]+)\//.exec(resourceId);
|
||||
return result[1];
|
||||
}
|
||||
|
||||
|
@ -381,7 +379,7 @@ export class Utility {
|
|||
return twin.properties.desired[Constants.DISTRIBUTED_TWIN_NAME].sampling_rate;
|
||||
}
|
||||
|
||||
public static async getTwin(registry: iothub.Registry, deviceId: string): Promise<any> {
|
||||
public static async getTwin(registry: Registry, deviceId: string): Promise<any> {
|
||||
const result = await registry.getTwin(deviceId);
|
||||
return result.responseBody;
|
||||
}
|
||||
|
@ -390,7 +388,7 @@ export class Utility {
|
|||
return vscode.extensions.getExtension<AzureAccount>("ms-vscode.azure-account")!.exports;
|
||||
}
|
||||
|
||||
public static getMessageFromEventData(message: EventData): any {
|
||||
public static getMessageFromEventData(message: any): any {
|
||||
const config = Utility.getConfiguration();
|
||||
const showVerboseMessage = config.get<boolean>("showVerboseMessage");
|
||||
let result;
|
||||
|
@ -413,11 +411,11 @@ export class Utility {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static getTimeMessageFromEventData(message: EventData): string {
|
||||
public static getTimeMessageFromEventData(message: ReceivedEventData): string {
|
||||
return message.enqueuedTimeUtc ? `[${message.enqueuedTimeUtc.toLocaleTimeString("en-US")}] ` : "";
|
||||
}
|
||||
|
||||
public static async storeIoTHubInfo(subscriptionId: string, iotHubDescription: IotHubDescription) {
|
||||
public static async storeIoTHubInfo(subscriptionId: string, iotHubDescription: IotHubModels.IotHubDescription) {
|
||||
await Constants.ExtensionContext.globalState.update(Constants.StateKeySubsID, subscriptionId);
|
||||
await Constants.ExtensionContext.globalState.update(Constants.StateKeyIoTHubID, iotHubDescription.id);
|
||||
}
|
||||
|
@ -436,7 +434,7 @@ export class Utility {
|
|||
}
|
||||
}
|
||||
|
||||
public static generateIoTHubAxiosRequestConfig(iotHubConnectionString: string, url: string, method: string, data?: any): AxiosRequestConfig {
|
||||
public static generateIoTHubAxiosRequestConfig(iotHubConnectionString: string, url: string, method: Method, data?: any): AxiosRequestConfig {
|
||||
return {
|
||||
url,
|
||||
method,
|
||||
|
@ -519,8 +517,8 @@ export class Utility {
|
|||
}
|
||||
|
||||
private static showIoTHubInformationMessage(): void {
|
||||
let config = Utility.getConfiguration();
|
||||
let showIoTHubInfo = config.get<boolean>(Constants.ShowIoTHubInfoKey);
|
||||
const config = Utility.getConfiguration();
|
||||
const showIoTHubInfo = config.get<boolean>(Constants.ShowIoTHubInfoKey);
|
||||
if (showIoTHubInfo) {
|
||||
const GoToAzureRegistrationPage = "Go to Azure registration page";
|
||||
const GoToAzureIoTHubPage = "Go to Azure IoT Hub page";
|
||||
|
|
|
@ -10,7 +10,7 @@ import { TestConstants } from "./constants";
|
|||
suite("Utility Tests ", () => {
|
||||
|
||||
test("should be able to get hostname", () => {
|
||||
let hostname = Utility.getHostName(TestConstants.IotHubConnectionString);
|
||||
const hostname = Utility.getHostName(TestConstants.IotHubConnectionString);
|
||||
assert.equal(hostname, TestConstants.IotHubHostName);
|
||||
});
|
||||
|
||||
|
@ -19,27 +19,27 @@ suite("Utility Tests ", () => {
|
|||
});
|
||||
|
||||
test("should be able to get config", () => {
|
||||
let iotHubD2CMessageStringify = Utility.getConfig<boolean>(Constants.IoTHubD2CMessageStringifyKey);
|
||||
const iotHubD2CMessageStringify = Utility.getConfig<boolean>(Constants.IoTHubD2CMessageStringifyKey);
|
||||
assert.equal(iotHubD2CMessageStringify, false);
|
||||
});
|
||||
|
||||
test("should be able to get auto refresh enable flag", () => {
|
||||
let autoRefreshEnable = Utility.getConfig<boolean>(Constants.TreeViewAutoRefreshEnableKey);
|
||||
const autoRefreshEnable = Utility.getConfig<boolean>(Constants.TreeViewAutoRefreshEnableKey);
|
||||
assert.equal(autoRefreshEnable, false);
|
||||
});
|
||||
|
||||
test("should be able to get auto refresh interval", () => {
|
||||
let autoRefreshIntervalInSeconds = Utility.getConfig<boolean>(Constants.TreeViewAutoRefreshIntervalInSecondsKey);
|
||||
const autoRefreshIntervalInSeconds = Utility.getConfig<boolean>(Constants.TreeViewAutoRefreshIntervalInSecondsKey);
|
||||
assert.equal(autoRefreshIntervalInSeconds, 60);
|
||||
});
|
||||
|
||||
test("should be able to generate SAS Token for IoT Hub", () => {
|
||||
let sasTokenForService = Utility.generateSasTokenForService(TestConstants.IotHubConnectionString, 10);
|
||||
const sasTokenForService = Utility.generateSasTokenForService(TestConstants.IotHubConnectionString, 10);
|
||||
assert.equal(/^SharedAccessSignature sr=iot-hub-test.azure-devices.net&sig=.+&skn=iothubowner&se=.+$/.test(sasTokenForService), true);
|
||||
});
|
||||
|
||||
test("should be able to generate SAS Token for Device", () => {
|
||||
let sasTokenForDevice = Utility.generateSasTokenForDevice(TestConstants.DeviceConnectionString, 10);
|
||||
const sasTokenForDevice = Utility.generateSasTokenForDevice(TestConstants.DeviceConnectionString, 10);
|
||||
assert.equal(/^SharedAccessSignature sr=iot-hub-test.azure-devices.net%2Fdevices%2Fdevice1&sig=.+&se=.+$/.test(sasTokenForDevice), true);
|
||||
});
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
"es2017"
|
||||
],
|
||||
"sourceMap": true,
|
||||
"rootDir": "."
|
||||
"rootDir": ".",
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
|
|
|
@ -105,9 +105,13 @@ const config = {
|
|||
/$^/
|
||||
),
|
||||
// Copy required resources for Azure treeview
|
||||
new copyPlugin([
|
||||
path.join('node_modules', 'vscode-azureextensionui', 'resources', '**', '*.svg')
|
||||
]),
|
||||
new copyPlugin({
|
||||
patterns: [
|
||||
{
|
||||
from: 'node_modules/vscode-azureextensionui/resources/**/*.svg'
|
||||
}
|
||||
]
|
||||
}),
|
||||
// Fail on warnings so that CI can report new warnings which require attention
|
||||
new failOnErrorsPlugin({
|
||||
failOnErrors: true,
|
||||
|
|
Загрузка…
Ссылка в новой задаче