Skip to content

Commit

Permalink
Decoupling from Azure Account extension (#212)
Browse files Browse the repository at this point in the history
* #178

* version 6.5.1

* review fixes
  • Loading branch information
scale-tone authored Oct 5, 2024
1 parent 55e7874 commit 9a99d06
Show file tree
Hide file tree
Showing 10 changed files with 430 additions and 404 deletions.
4 changes: 4 additions & 0 deletions durablefunctionsmonitor-vscodeext/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

# Version 6.5.1

- Decoupled from (soon deprecated) [Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account). NOTE: you might need to re-authenticate to Azure.

# Version 6.5

- New feature - `Execute Batch Operations...` (https://github.com/microsoft/DurableFunctionsMonitor/issues/169). Prepare a list of instances in the main screen, and then use this context menu to execute operations against all of them:
Expand Down
511 changes: 300 additions & 211 deletions durablefunctionsmonitor-vscodeext/package-lock.json

Large diffs are not rendered by default.

52 changes: 28 additions & 24 deletions durablefunctionsmonitor-vscodeext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "durablefunctionsmonitor",
"displayName": "Durable Functions Monitor",
"description": "Monitoring/debugging UI tool for Azure Durable Functions",
"version": "6.5.0",
"version": "6.5.1",
"engines": {
"vscode": "^1.39.0"
},
Expand Down Expand Up @@ -30,13 +30,13 @@
"license": "MIT",
"activationEvents": [
"onView:durableFunctionsMonitorTreeView",
"onCommand:extension.durableFunctionsMonitor",
"onCommand:extension.durableFunctionsMonitorPurgeHistory",
"onCommand:extension.durableFunctionsMonitorCleanEntityStorage",
"onCommand:extension.durableFunctionsMonitorBatchOps",
"onCommand:durable-functions-monitor.durableFunctionsMonitor",
"onCommand:durable-functions-monitor.durableFunctionsMonitorPurgeHistory",
"onCommand:durable-functions-monitor.durableFunctionsMonitorCleanEntityStorage",
"onCommand:durable-functions-monitor.durableFunctionsMonitorBatchOps",
"onCommand:durableFunctionsMonitorTreeView.attachToAnotherTaskHub",
"onCommand:extension.durableFunctionsMonitorGotoInstanceId",
"onCommand:extension.durableFunctionsMonitorVisualizeAsGraph",
"onCommand:durable-functions-monitor.durableFunctionsMonitorGotoInstanceId",
"onCommand:durable-functions-monitor.durableFunctionsMonitorVisualizeAsGraph",
"onCommand:durableFunctionsMonitorTreeView.startNewInstance",
"onDebug"
],
Expand All @@ -52,27 +52,31 @@
},
"commands": [
{
"command": "extension.durableFunctionsMonitor",
"command": "durable-functions-monitor.signInToAzure",
"title": "Sign in to Azure..."
},
{
"command": "durable-functions-monitor.durableFunctionsMonitor",
"title": "Durable Functions Monitor"
},
{
"command": "extension.durableFunctionsMonitorPurgeHistory",
"command": "durable-functions-monitor.durableFunctionsMonitorPurgeHistory",
"title": "Durable Functions Monitor: Purge History..."
},
{
"command": "extension.durableFunctionsMonitorCleanEntityStorage",
"command": "durable-functions-monitor.durableFunctionsMonitorCleanEntityStorage",
"title": "Durable Functions Monitor: Clean Entity Storage..."
},
{
"command": "extension.durableFunctionsMonitorBatchOps",
"command": "durable-functions-monitor.durableFunctionsMonitorBatchOps",
"title": "Durable Functions Monitor: Execute Batch Operations..."
},
{
"command": "extension.durableFunctionsMonitorGotoInstanceId",
"command": "durable-functions-monitor.durableFunctionsMonitorGotoInstanceId",
"title": "Durable Functions Monitor: Go to instanceId..."
},
{
"command": "extension.durableFunctionsMonitorVisualizeAsGraph",
"command": "durable-functions-monitor.durableFunctionsMonitorVisualizeAsGraph",
"title": "Visualize Functions as a Graph..."
},
{
Expand Down Expand Up @@ -147,32 +151,32 @@
"menus": {
"explorer/context": [
{
"command": "extension.durableFunctionsMonitor",
"command": "durable-functions-monitor.durableFunctionsMonitor",
"when": "resourceFilename == host.json",
"group": "DurableFunctionMonitorGroup@1"
},
{
"command": "extension.durableFunctionsMonitorPurgeHistory",
"command": "durable-functions-monitor.durableFunctionsMonitorPurgeHistory",
"when": "resourceFilename == host.json",
"group": "DurableFunctionMonitorGroup@2"
},
{
"command": "extension.durableFunctionsMonitorCleanEntityStorage",
"command": "durable-functions-monitor.durableFunctionsMonitorCleanEntityStorage",
"when": "resourceFilename == host.json",
"group": "DurableFunctionMonitorGroup@3"
},
{
"command": "extension.durableFunctionsMonitorBatchOps",
"command": "durable-functions-monitor.durableFunctionsMonitorBatchOps",
"when": "resourceFilename == host.json",
"group": "DurableFunctionMonitorGroup@4"
},
{
"command": "extension.durableFunctionsMonitorGotoInstanceId",
"command": "durable-functions-monitor.durableFunctionsMonitorGotoInstanceId",
"when": "resourceFilename == host.json",
"group": "DurableFunctionMonitorGroup@5"
},
{
"command": "extension.durableFunctionsMonitorVisualizeAsGraph",
"command": "durable-functions-monitor.durableFunctionsMonitorVisualizeAsGraph",
"when": "resourceFilename == host.json",
"group": "DurableFunctionMonitorGroup@6"
}
Expand Down Expand Up @@ -341,16 +345,18 @@
"@types/node": "^14.6.4",
"@types/vscode": "^1.39.0",
"@vscode/test-electron": "^2.3.5",
"@vscode/vsce": "^2.26.1",
"glob": "^7.1.4",
"mocha": "^10.0.0",
"tslint": "^5.12.1",
"typescript": "^4.4.4",
"@vscode/vsce": "^2.26.1"
"typescript": "^4.4.4"
},
"dependencies": {
"@azure/arm-resourcegraph": "^4.2.1",
"@azure/arm-storage": "^18.1.0",
"@azure/identity": "^4.4.1",
"@azure/ms-rest-nodeauth": "^3.1.0",
"@microsoft/vscode-azext-azureauth": "^2.5.0",
"@types/crypto-js": "^3.1.47",
"@types/rimraf": "^3.0.0",
"axios": "1.6.2",
Expand All @@ -360,7 +366,5 @@
"portscanner": "^2.2.0",
"rimraf": "^3.0.2"
},
"extensionDependencies": [
"ms-vscode.azure-account"
]
"extensionDependencies": []
}
14 changes: 2 additions & 12 deletions durablefunctionsmonitor-vscodeext/src/ConnStringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { StorageAccount } from '@azure/arm-storage';
import { Settings } from './Settings';
import { ResourceGraphClient } from '@azure/arm-resourcegraph';
import { DeviceTokenCredentials } from '@azure/ms-rest-nodeauth';
import { TokenCredential } from '@azure/identity';

export class ConnStringUtils {

Expand Down Expand Up @@ -105,7 +105,7 @@ export class ConnStringUtils {
}

// Queries Azure Resource Manager API for the list of resources of a given type
static async getAzureResources(creds: DeviceTokenCredentials, subscriptionId: string, resourceType: string, resourceName?: string): Promise<any[]>{
static async getAzureResources(creds: TokenCredential, subscriptionId: string, resourceType: string, resourceName?: string): Promise<any[]>{

const resourceGraphClient = new ResourceGraphClient(creds);
const response = await resourceGraphClient.resources({
Expand All @@ -115,14 +115,4 @@ export class ConnStringUtils {

return response.data ?? [];
}

// Polyfills ADAL's and MSAL's getToken()
static async getAccessTokenForAzureResourceManager(creds: any): Promise<string>{

const tokenWrapper = await creds.getToken();
// Depending on whether ADAL or MSAL is used, the field is called either 'accessToken' or 'token'
const accessToken = tokenWrapper.accessToken ?? tokenWrapper.token;

return accessToken;
}
}
12 changes: 5 additions & 7 deletions durablefunctionsmonitor-vscodeext/src/EventHubPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

import * as vscode from 'vscode';
import axios from 'axios';
import { ConnStringUtils } from './ConnStringUtils';
import { AzureSubscription } from '@microsoft/vscode-azext-azureauth';

// Full typings for this can be found here: https://github.com/microsoft/vscode-azure-account/blob/master/src/azure-account.api.d.ts
export type AzureSubscription = { session: { credentials2: any }, subscription: { subscriptionId: string, displayName: string } };
import { ConnStringUtils } from './ConnStringUtils';

export class EventHubPicker {

Expand All @@ -15,9 +14,8 @@ export class EventHubPicker {
// Asks user to choose an Event Hub connection string
async pickEventHubConnectionString(subscription: AzureSubscription): Promise<string | undefined> {

// Depending on whether ADAL or MSAL is used, this will contain either DeviceTokenCredentials or TokenCredential
const creds: any = subscription.session.credentials2;
const subscriptionId = subscription.subscription.subscriptionId;
const creds = subscription.credential;
const subscriptionId = subscription.subscriptionId;

const namespaces = await ConnStringUtils.getAzureResources(
creds,
Expand Down Expand Up @@ -46,7 +44,7 @@ export class EventHubPicker {
return;
}

const accessToken = await ConnStringUtils.getAccessTokenForAzureResourceManager(creds);
const accessToken = (await creds.getToken(['https://management.core.windows.net/user_impersonation']))!.token;

let authRule: string | undefined = '';

Expand Down
Loading

0 comments on commit 9a99d06

Please sign in to comment.