Skip to content

Miscellaneous improvements related to Durable Task Hub #4641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1483,9 +1483,9 @@
"@azure/storage-blob": "^12.5.0",
"@microsoft/vscode-azext-azureappservice": "^3.6.4",
"@microsoft/vscode-azext-azureappsettings": "^0.2.8",
"@microsoft/vscode-azext-azureutils": "^3.4.7",
"@microsoft/vscode-azext-azureutils": "^3.4.8",
"@microsoft/vscode-azext-utils": "^3.3.3",
"@microsoft/vscode-azureresources-api": "^2.0.4",
"@microsoft/vscode-azureresources-api": "^2.5.1",
"@microsoft/vscode-container-client": "^0.1.2",
"cross-fetch": "^4.0.0",
"escape-string-regexp": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ const startingResourcesContext: string = 'startingResourcesLogStepItem';

export class DTSStartingResourcesLogStep<T extends IDTSAzureConnectionWizardContext> extends AzureWizardPromptStep<T> {
public hideStepCount: boolean = true;
protected hasLogged: boolean = false;

public async configureBeforePrompt(context: T): Promise<void> {
if (this.hasLogged) {
return;
}

if (context.resourceGroup) {
prependOrInsertAfterLastInfoChild(context,
new ActivityChildItem({
stepId: this.id,
contextValue: createContextValue([startingResourcesContext, activityInfoContext]),
label: localize('useResourceGroup', 'Use resource group "{0}"', context.resourceGroup.name),
activityType: ActivityChildType.Info,
Expand All @@ -34,6 +30,7 @@ export class DTSStartingResourcesLogStep<T extends IDTSAzureConnectionWizardCont
if (context.site) {
prependOrInsertAfterLastInfoChild(context,
new ActivityChildItem({
stepId: this.id,
label: localize('useFunctionApp', 'Use function app "{0}"', context.site.fullName),
contextValue: createContextValue([startingResourcesContext, activityInfoContext]),
activityType: ActivityChildType.Info,
Expand All @@ -46,6 +43,7 @@ export class DTSStartingResourcesLogStep<T extends IDTSAzureConnectionWizardCont
if (context.dts) {
prependOrInsertAfterLastInfoChild(context,
new ActivityChildItem({
stepId: this.id,
label: localize('useDTS', 'Use durable task scheduler "{0}"', context.dts.name),
contextValue: createContextValue([startingResourcesContext, activityInfoContext]),
activityType: ActivityChildType.Info,
Expand All @@ -58,6 +56,7 @@ export class DTSStartingResourcesLogStep<T extends IDTSAzureConnectionWizardCont
if (context.dtsHub) {
prependOrInsertAfterLastInfoChild(context,
new ActivityChildItem({
stepId: this.id,
label: localize('useDTSHub', 'Use durable task hub "{0}"', context.dtsHub.name),
contextValue: createContextValue([startingResourcesContext, activityInfoContext]),
activityType: ActivityChildType.Info,
Expand All @@ -74,8 +73,6 @@ export class DTSStartingResourcesLogStep<T extends IDTSAzureConnectionWizardCont
if (context.newDTSHubConnectionSettingKey) {
ext.outputChannel.appendLog(localize('dtsHubConnectionKey', 'Using DTS hub host connection key "{0}"', context.newDTSHubConnectionSettingKey));
}

this.hasLogged = true;
}

public async prompt(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { parseAzureResourceId } from '@microsoft/vscode-azext-azureutils';
import { AzureWizardPromptStep, nonNullProp, type IAzureQuickPickItem, type IWizardOptions } from '@microsoft/vscode-azext-utils';
import { CommonRoleDefinitions, createAuthorizationManagementClient, createRoleId, parseAzureResourceId, RoleAssignmentExecuteStep, uiUtils, type Role } from '@microsoft/vscode-azext-azureutils';
import { ActivityChildItem, ActivityChildType, activitySuccessContext, activitySuccessIcon, AzureWizardPromptStep, createContextValue, nonNullProp, type AzureWizardExecuteStep, type IAzureQuickPickItem, type IWizardOptions } from '@microsoft/vscode-azext-utils';
import { localSettingsDescription } from '../../../../../constants-nls';
import { ext } from '../../../../../extensionVariables';
import { localize } from '../../../../../localize';
import { HttpDurableTaskSchedulerClient, type DurableTaskHubResource, type DurableTaskSchedulerClient } from '../../../../../tree/durableTaskScheduler/DurableTaskSchedulerClient';
import { FunctionAppUserAssignedIdentitiesListStep } from '../../../../identity/FunctionAppUserAssignedIdentitiesListStep';
import { type IDTSAzureConnectionWizardContext } from '../IDTSConnectionWizardContext';
import { DurableTaskHubCreateStep } from './DurableTaskHubCreateStep';
import { DurableTaskHubNameStep } from './DurableTaskHubNameStep';
Expand All @@ -22,7 +24,7 @@ export class DurableTaskHubListStep<T extends IDTSAzureConnectionWizardContext>

public async prompt(context: T): Promise<void> {
context.dtsHub = (await context.ui.showQuickPick(await this.getPicks(context), {
placeHolder: localize('selectTaskScheduler', 'Select a Durable Task Scheduler'),
placeHolder: localize('selectTaskScheduler', 'Select a durable task hub'),
})).data;

if (context.dtsHub) {
Expand All @@ -35,17 +37,6 @@ export class DurableTaskHubListStep<T extends IDTSAzureConnectionWizardContext>
return !context.dtsHub;
}

public async getSubWizard(context: T): Promise<IWizardOptions<T> | undefined> {
if (context.dtsHub) {
return undefined;
}

return {
promptSteps: [new DurableTaskHubNameStep(this.schedulerClient)],
executeSteps: [new DurableTaskHubCreateStep(this.schedulerClient)],
};
}

private async getPicks(context: T): Promise<IAzureQuickPickItem<DurableTaskHubResource | undefined>[]> {
const taskHubs: DurableTaskHubResource[] = context.dts ?
await this.schedulerClient.getSchedulerTaskHubs(nonNullProp(context, 'subscription'), parseAzureResourceId(context.dts.id).resourceGroup, context.dts.name) : [];
Expand All @@ -66,4 +57,65 @@ export class DurableTaskHubListStep<T extends IDTSAzureConnectionWizardContext>
}),
];
}

public async getSubWizard(context: T): Promise<IWizardOptions<T> | undefined> {
const promptSteps: AzureWizardPromptStep<T>[] = [];
const executeSteps: AzureWizardExecuteStep<T>[] = [];

if (!context.dtsHub) {
promptSteps.push(new DurableTaskHubNameStep(this.schedulerClient));
executeSteps.push(new DurableTaskHubCreateStep(this.schedulerClient));
}

const dtsContributorRole: Role = {
scopeId: context.dtsHub?.id,
roleDefinitionId: createRoleId(context.subscriptionId, CommonRoleDefinitions.durableTaskDataContributor),
roleDefinitionName: CommonRoleDefinitions.durableTaskDataContributor.roleName,
};

promptSteps.push(new FunctionAppUserAssignedIdentitiesListStep(dtsContributorRole /** targetRole */, { identityAssignStepPriority: 180 }));
executeSteps.push(new RoleAssignmentExecuteStep(this.getDTSRoleAssignmentCallback(context, dtsContributorRole), { priority: 190 }));

return { promptSteps, executeSteps };
}

private getDTSRoleAssignmentCallback(context: T, role: Role): () => Promise<Role[]> {
return async () => {
const roleAssignment: Role = {
...role,
// This id may be missing when the role is initially passed in,
// but by the time we run the step, we should have the populated id ready.
scopeId: context.dtsHub?.id,
};

if (!roleAssignment.scopeId) {
return [];
}

const amClient = await createAuthorizationManagementClient(context);
const roleAssignments = await uiUtils.listAllIterator(amClient.roleAssignments.listForScope(
roleAssignment.scopeId,
{
// $filter=principalId eq {id}
filter: `principalId eq '{${context.managedIdentity?.principalId}}'`,
}
));

const hasRoleAssignment = roleAssignments.some(r => !!r.roleDefinitionId?.endsWith(role.roleDefinitionId));
if (hasRoleAssignment) {
context.activityChildren?.push(
new ActivityChildItem({
label: localize('verifyIdentityWithRoleLabel', 'Verify identity "{0}" has role "{1}"', context.managedIdentity?.name, role.roleDefinitionName),
description: '0s',
contextValue: createContextValue(['roleAssignmentExecuteStepItem', activitySuccessContext]),
activityType: ActivityChildType.Success,
iconPath: activitySuccessIcon,
}),
);
ext.outputChannel.appendLog(localize('verifyIdentity', 'Successfully verified identity "{0}" has role "{1}".', context.managedIdentity?.name, role.roleDefinitionName));
}

return hasRoleAssignment ? [] : [roleAssignment];
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class DurableTaskHubNameStep<T extends IDTSAzureConnectionWizardContext>
public async prompt(context: T): Promise<void> {
context.newDTSHubName = (await context.ui.showInputBox({
prompt: localize('taskSchedulerName', 'Enter a name for the durable task hub'),
value: context.suggestedDTSHubNameLocalSettings,
value: context.suggestedDTSHubNameLocalSettings ?? 'default',
validateInput: this.validateInput,
asyncValidationTask: (name: string) => this.validateNameAvailable(context, name),
})).trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { CommonRoleDefinitions, createAuthorizationManagementClient, createRoleId, LocationListStep, parseAzureResourceId, RoleAssignmentExecuteStep, uiUtils, type ILocationWizardContext, type Role } from '@microsoft/vscode-azext-azureutils';
import { LocationListStep, parseAzureResourceId, type ILocationWizardContext } from '@microsoft/vscode-azext-azureutils';
import { AzureWizardPromptStep, nonNullProp, type AzureWizardExecuteStep, type IAzureQuickPickItem, type IWizardOptions } from '@microsoft/vscode-azext-utils';
import { localSettingsDescription } from '../../../../../constants-nls';
import { localize } from '../../../../../localize';
import { HttpDurableTaskSchedulerClient, type DurableTaskSchedulerClient, type DurableTaskSchedulerResource } from '../../../../../tree/durableTaskScheduler/DurableTaskSchedulerClient';
import { FunctionAppUserAssignedIdentitiesListStep } from '../../../../identity/FunctionAppUserAssignedIdentitiesListStep';
import { type IDTSAzureConnectionWizardContext } from '../IDTSConnectionWizardContext';
import { DurableTaskHubListStep } from './DurableTaskHubListStep';
import { DurableTaskSchedulerCreateStep } from './DurableTaskSchedulerCreateStep';
Expand Down Expand Up @@ -52,43 +51,7 @@ export class DurableTaskSchedulerListStep<T extends IDTSAzureConnectionWizardCon
promptSteps.push(new DurableTaskHubListStep(this._schedulerClient));
}

const dtsContributorRole: Role = {
scopeId: context.dts?.id,
roleDefinitionId: createRoleId(context.subscriptionId, CommonRoleDefinitions.durableTaskDataContributor),
roleDefinitionName: CommonRoleDefinitions.durableTaskDataContributor.roleName,
};

promptSteps.push(new FunctionAppUserAssignedIdentitiesListStep(dtsContributorRole /** targetRole */, { identityAssignStepPriority: 180 }));
executeSteps.push(new RoleAssignmentExecuteStep(getDTSRoleAssignmentCallback(context, dtsContributorRole), { priority: 190 }));

return { promptSteps, executeSteps };

function getDTSRoleAssignmentCallback(context: T, role: Role): () => Promise<Role[]> {
return async () => {
const roleAssignment: Role = {
...role,
// This id may be missing when the role is initially passed in,
// but by the time we run the step, we should have the populated id ready.
scopeId: context.dts?.id,
};

if (!roleAssignment.scopeId) {
return [];
}

const amClient = await createAuthorizationManagementClient(context);
const roleAssignments = await uiUtils.listAllIterator(amClient.roleAssignments.listForScope(
roleAssignment.scopeId,
{
// $filter=principalId eq {id}
filter: `principalId eq '{${context.managedIdentity?.principalId}}'`,
}
));

const hasRoleAssignment = roleAssignments.some(r => !!r.roleDefinitionId?.endsWith(role.roleDefinitionId));
return hasRoleAssignment ? [] : [roleAssignment];
};
}
}

private async getPicks(context: T): Promise<IAzureQuickPickItem<DurableTaskSchedulerResource | undefined>[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import { type ManagedServiceIdentityClient } from '@azure/arm-msi';
import { type ParsedSite } from '@microsoft/vscode-azext-azureappservice';
import { createAuthorizationManagementClient, createManagedServiceIdentityClient, parseAzureResourceId, uiUtils, UserAssignedIdentityListStep, type ParsedAzureResourceId, type Role } from '@microsoft/vscode-azext-azureutils';
import { ActivityChildItem, ActivityChildType, activityInfoContext, activityInfoIcon, AzureWizardPromptStep, createContextValue, nonNullProp, prependOrInsertAfterLastInfoChild, type ActivityInfoChild, type IAzureQuickPickItem, type IWizardOptions } from '@microsoft/vscode-azext-utils';
import { ext } from '../../extensionVariables';
import { AzureWizardPromptStep, nonNullProp, type IAzureQuickPickItem, type IWizardOptions } from '@microsoft/vscode-azext-utils';
import { localize } from '../../localize';
import { type ManagedIdentityAssignContext } from './ManagedIdentityAssignContext';
import { ManagedIdentityAssignStep } from './ManagedIdentityAssignStep';
Expand Down Expand Up @@ -65,21 +64,6 @@ export class FunctionAppUserAssignedIdentitiesListStep<T extends ManagedIdentity
}

context.telemetry.properties.functionAppHasIdentityWithTargetRole = String(hasTargetRole);

if (hasTargetRole) {
prependOrInsertAfterLastInfoChild(context,
new ActivityChildItem({
stepId: this.id,
label: localize('useIdentityWithRole', 'Use identity "{0}" with role "{1}"', context.managedIdentity?.name, this.targetRole.roleDefinitionName),
contextValue: createContextValue(['functionAppUserAssignedIdentitiesListStepItem', activityInfoContext]),
activityType: ActivityChildType.Info,
iconPath: activityInfoIcon,
}) as ActivityInfoChild,
);
ext.outputChannel.appendLog(localize('foundIdentity', 'Located existing user assigned identity "{0}" with role "{1}".', context.managedIdentity?.name, this.targetRole.roleDefinitionName));
} else {
ext.outputChannel.appendLog(localize('foundNoIdentity', 'Found no existing user assigned identity with role "{0}".', this.targetRole.roleDefinitionName));
}
}

public async prompt(context: T): Promise<void> {
Expand Down