-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* tmp * Basic version * Store/delete IoT Hub info * Stop Monitoring Custom Event Hub Endpoint * Refresh button; Built-in ednpoint; Other Custom Endpoint * Add BI * Add more BI * Add BI for built-in-events * Fix security vulnerability * Not show welcome page when azure-iot-tools is installed * Handle there is no iot hub
- Loading branch information
1 parent
5ede282
commit 285c0a7
Showing
23 changed files
with
687 additions
and
952 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import { TreeItem } from "vscode"; | ||
|
||
export class CustomEndpointItem extends TreeItem { | ||
constructor(name: string) { | ||
super(name); | ||
this.contextValue = "custom-endpoint"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import { RoutingEventHubProperties } from "azure-arm-iothub/lib/models"; | ||
import { TreeItem } from "vscode"; | ||
import { AzureSubscription } from "../azure-account.api"; | ||
|
||
export class EventHubItem extends TreeItem { | ||
constructor( | ||
public readonly azureSubscription: AzureSubscription, | ||
public readonly eventHubProperty: RoutingEventHubProperties) { | ||
super(eventHubProperty.name); | ||
this.contextValue = "event-hub"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import * as vscode from "vscode"; | ||
import { Constants } from "../constants"; | ||
import { DeviceItem } from "../Model/DeviceItem"; | ||
import { TelemetryClient } from "../telemetryClient"; | ||
import { Utility } from "../utility"; | ||
import { DeviceNode } from "./DeviceNode"; | ||
import { InfoNode } from "./InfoNode"; | ||
import { INode } from "./INode"; | ||
|
||
export class DeviceLabelNode implements INode { | ||
constructor(private iotHubConnectionString: string) { | ||
} | ||
|
||
public getTreeItem(): vscode.TreeItem { | ||
return { | ||
label: "Devices", | ||
collapsibleState: vscode.TreeItemCollapsibleState.Expanded, | ||
contextValue: "devices-label", | ||
}; | ||
} | ||
|
||
public async getChildren(): Promise<INode[]> { | ||
TelemetryClient.sendEvent(Constants.IoTHubAIStartLoadDeviceTreeEvent); | ||
|
||
try { | ||
const deviceList: vscode.TreeItem[] = await Utility.getDeviceList(this.iotHubConnectionString, Constants.ExtensionContext); | ||
|
||
let 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)}`)); | ||
} | ||
|
||
TelemetryClient.sendEvent(Constants.IoTHubAILoadDeviceTreeEvent, { Result: "Success", DeviceCount: deviceList.length.toString() }); | ||
|
||
return deviceNode; | ||
} catch (err) { | ||
TelemetryClient.sendEvent(Constants.IoTHubAILoadDeviceTreeEvent, { Result: "Fail", Message: err.message }); | ||
return Utility.getErrorMessageTreeItems("IoT Hub devices", err.message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import * as vscode from "vscode"; | ||
import { INode } from "../INode"; | ||
|
||
export class BuiltInEndpointItemNode implements INode { | ||
constructor() { | ||
} | ||
|
||
public getTreeItem(): vscode.TreeItem { | ||
return { | ||
label: "events", | ||
contextValue: "events", | ||
}; | ||
} | ||
|
||
public getChildren(): INode[] { | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import * as vscode from "vscode"; | ||
import { INode } from "../INode"; | ||
import { BuiltInEndpointItemNode } from "./BuiltInEndpointItemNode"; | ||
|
||
export class BuiltInEndpointLabelNode implements INode { | ||
constructor() { | ||
} | ||
|
||
public getTreeItem(): vscode.TreeItem { | ||
return { | ||
label: "Built-in endpints", | ||
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed, | ||
contextValue: "built-in-endpoint-label", | ||
}; | ||
} | ||
|
||
public getChildren(): INode[] { | ||
return [new BuiltInEndpointItemNode()]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import * as vscode from "vscode"; | ||
import { CustomEndpointItem } from "../../Model/CustomEndpointItem"; | ||
import { INode } from "../INode"; | ||
|
||
export class CustomEndpointItemNode implements INode { | ||
constructor(private name: string) { | ||
} | ||
|
||
public getTreeItem(): vscode.TreeItem { | ||
return new CustomEndpointItem(this.name); | ||
} | ||
|
||
public getChildren(): INode[] { | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import * as vscode from "vscode"; | ||
import { INode } from "../INode"; | ||
import { CustomEndpointItemNode } from "./CustomEndpointItemNode"; | ||
|
||
export class CustomEndpointLabelNode implements INode { | ||
constructor(private label: string, private properties: any[]) { | ||
} | ||
|
||
public getTreeItem(): vscode.TreeItem { | ||
return { | ||
label: this.label, | ||
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed, | ||
contextValue: "custom-endpoint-label", | ||
}; | ||
} | ||
|
||
public getChildren(): INode[] { | ||
return this.properties.map((property) => new CustomEndpointItemNode(property.name)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import IotHubClient from "azure-arm-iothub"; | ||
import * as vscode from "vscode"; | ||
import { Constants } from "../../constants"; | ||
import { TelemetryClient } from "../../telemetryClient"; | ||
import { Utility } from "../../utility"; | ||
import { CommandNode } from "../CommandNode"; | ||
import { INode } from "../INode"; | ||
import { BuiltInEndpointLabelNode } from "./BuiltInEndpointLabelNode"; | ||
import { CustomEndpointLabelNode } from "./CustomEndpointLabelNode"; | ||
import { EventHubLabelNode } from "./EventHubLabelNode"; | ||
|
||
export class EndpointsLabelNode implements INode { | ||
constructor() { | ||
} | ||
|
||
public getTreeItem(): vscode.TreeItem { | ||
return { | ||
label: "Endpoints", | ||
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed, | ||
contextValue: "endpoints-label", | ||
}; | ||
} | ||
|
||
public async getChildren(): Promise<INode[]> { | ||
TelemetryClient.sendEvent(Constants.IoTHubAILoadEndpointsTreeStartEvent); | ||
|
||
try { | ||
const accountApi = Utility.getAzureAccountApi(); | ||
const subscriptionId = Constants.ExtensionContext.globalState.get(Constants.StateKeySubsID); | ||
if (!subscriptionId || !(await accountApi.waitForLogin())) { | ||
return [this.getSelectIoTHubCommandNode()]; | ||
} | ||
|
||
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 iotHubs = await client.iotHubResource.listBySubscription(); | ||
const iothub = iotHubs.find((element) => | ||
element.id === Constants.ExtensionContext.globalState.get(Constants.StateKeyIoTHubID)); | ||
TelemetryClient.sendEvent(Constants.IoTHubAILoadEndpointsTreeDoneEvent, { Result: "Success" }); | ||
|
||
if (!iothub) { | ||
return [this.getSelectIoTHubCommandNode()]; | ||
} | ||
|
||
return [new BuiltInEndpointLabelNode(), | ||
new EventHubLabelNode(subscription, iothub.properties.routing.endpoints.eventHubs), | ||
new CustomEndpointLabelNode("Service Bus queue", iothub.properties.routing.endpoints.serviceBusQueues), | ||
new CustomEndpointLabelNode("Service Bus topic", iothub.properties.routing.endpoints.serviceBusTopics), | ||
new CustomEndpointLabelNode("Blob storage", iothub.properties.routing.endpoints.storageContainers)]; | ||
} catch (err) { | ||
TelemetryClient.sendEvent(Constants.IoTHubAILoadEndpointsTreeDoneEvent, { Result: "Fail", Message: err.message }); | ||
return Utility.getErrorMessageTreeItems("endpoints", err.message); | ||
} | ||
} | ||
|
||
private getSelectIoTHubCommandNode(): CommandNode { | ||
return new CommandNode("-> Please select an IoT Hub", "azure-iot-toolkit.selectIoTHub"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import * as vscode from "vscode"; | ||
import { EventHubItem } from "../../Model/EventHubItem"; | ||
import { INode } from "../INode"; | ||
|
||
export class EventHubItemNode implements INode { | ||
constructor(public eventHubItem: EventHubItem) { | ||
} | ||
|
||
public getTreeItem(): vscode.TreeItem { | ||
return this.eventHubItem; | ||
} | ||
|
||
public getChildren(): INode[] { | ||
return []; | ||
} | ||
} |
Oops, something went wrong.