-
Notifications
You must be signed in to change notification settings - Fork 77
azure: Change the typings of the created clients #2193
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
base: main
Are you sure you want to change the base?
Changes from all commits
83ba6d2
e9838e8
df2195f
1d56077
80087c5
fd19440
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,44 +4,55 @@ | |
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import type { AuthorizationManagementClient } from '@azure/arm-authorization'; | ||
| import type { AuthorizationManagementClient as PAMC } from '@azure/arm-authorization-profile-2020-09-01-hybrid'; | ||
| import type { ManagedServiceIdentityClient } from '@azure/arm-msi'; | ||
| import type { ResourceManagementClient } from '@azure/arm-resources'; | ||
| import type { ResourceManagementClient as PRMC } from '@azure/arm-resources-profile-2020-09-01-hybrid'; | ||
| import type { SubscriptionClient } from '@azure/arm-resources-subscriptions'; | ||
| import type { StorageManagementClient } from '@azure/arm-storage'; | ||
| import type { StorageManagementClient as PSMC } from '@azure/arm-storage-profile-2020-09-01-hybrid'; | ||
| import type { AzExtClientType } from '../index'; | ||
| import { createAzureClient, createAzureSubscriptionClient, InternalAzExtClientContext, parseClientContext } from './createAzureClient'; | ||
|
|
||
| export type CommonAuthorizationManagementClient = AuthorizationManagementClient | PAMC; | ||
| export type CommonResourcesClient = ResourceManagementClient | PRMC; | ||
| export type CommonStorageManagementClient = StorageManagementClient | PSMC; | ||
|
|
||
| // Lazy-load @azure packages to improve startup performance. | ||
| // NOTE: The client is the only import that matters, the rest of the types disappear when compiled to JavaScript | ||
|
|
||
| export async function createStorageClient(context: InternalAzExtClientContext): Promise<StorageManagementClient> { | ||
| export async function createStorageClient(context: InternalAzExtClientContext): Promise<CommonStorageManagementClient> { | ||
| if (parseClientContext(context).isCustomCloud) { | ||
| return <StorageManagementClient><unknown>createAzureClient(context, (await import('@azure/arm-storage-profile-2020-09-01-hybrid')).StorageManagementClient); | ||
| return createAzureClient(context, (await import('@azure/arm-storage-profile-2020-09-01-hybrid')).StorageManagementClient); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The casts become unnecessary, by declaring that the return type is a union of the two--that way the callers don't use something that exists on the normal SDK but not on the Azure Stack one. |
||
| } else { | ||
| return createAzureClient(context, (await import('@azure/arm-storage')).StorageManagementClient as unknown as AzExtClientType<StorageManagementClient>); | ||
| } | ||
| } | ||
|
|
||
| export async function createResourcesClient(context: InternalAzExtClientContext): Promise<ResourceManagementClient> { | ||
| export async function createResourcesClient(context: InternalAzExtClientContext): Promise<CommonResourcesClient> { | ||
| if (parseClientContext(context).isCustomCloud) { | ||
| return <ResourceManagementClient><unknown>createAzureClient(context, (await import('@azure/arm-resources-profile-2020-09-01-hybrid')).ResourceManagementClient); | ||
| return createAzureClient(context, (await import('@azure/arm-resources-profile-2020-09-01-hybrid')).ResourceManagementClient); | ||
| } else { | ||
| return createAzureClient(context, (await import('@azure/arm-resources')).ResourceManagementClient); | ||
| return createAzureClient(context, (await import('@azure/arm-resources')).ResourceManagementClient as unknown as AzExtClientType<ResourceManagementClient>); | ||
| } | ||
| } | ||
|
|
||
| export async function createManagedServiceIdentityClient(context: InternalAzExtClientContext): Promise<ManagedServiceIdentityClient> { | ||
| return createAzureClient(context, (await import('@azure/arm-msi')).ManagedServiceIdentityClient as unknown as AzExtClientType<ManagedServiceIdentityClient>); | ||
| } | ||
|
|
||
| export async function createAuthorizationManagementClient(context: InternalAzExtClientContext): Promise<AuthorizationManagementClient> { | ||
| export async function createAuthorizationManagementClient(context: InternalAzExtClientContext): Promise<CommonAuthorizationManagementClient> { | ||
| if (parseClientContext(context).isCustomCloud) { | ||
| return <AuthorizationManagementClient><unknown>createAzureClient(context, (await import('@azure/arm-authorization-profile-2020-09-01-hybrid')).AuthorizationManagementClient); | ||
| return createAzureClient(context, (await import('@azure/arm-authorization-profile-2020-09-01-hybrid')).AuthorizationManagementClient); | ||
| } else { | ||
| return createAzureClient(context, (await import('@azure/arm-authorization')).AuthorizationManagementClient); | ||
| } | ||
| } | ||
|
|
||
| export function isProfileAuthorizationManagementClient(client: CommonAuthorizationManagementClient): client is PAMC { | ||
| return !('listForSubscription' in client.roleAssignments); | ||
| } | ||
|
|
||
| export async function createSubscriptionsClient(context: InternalAzExtClientContext): Promise<SubscriptionClient> { | ||
| return createAzureSubscriptionClient(context, (await import('@azure/arm-resources-subscriptions')).SubscriptionClient); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ import { AzExtParentTreeItem, AzExtTreeItem, createGenericElement, createSubscri | |
| import { AzExtResourceType, AzureSubscription, getAzExtResourceType } from "@microsoft/vscode-azureresources-api"; | ||
| import { ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from "vscode"; | ||
| import * as types from '../../index'; | ||
| import { createAuthorizationManagementClient, createSubscriptionsClient } from "../clients"; | ||
| import { createAuthorizationManagementClient, createSubscriptionsClient, isProfileAuthorizationManagementClient } from "../clients"; | ||
| import { createPortalUri } from "../utils/createPortalUri"; | ||
| import { parseAzureResourceGroupId, parseAzureResourceId } from "../utils/parseAzureResourceId"; | ||
| import { uiUtils } from "../utils/uiUtils"; | ||
|
|
@@ -18,6 +18,11 @@ import { getAzureIconPath } from "./IconPath"; | |
| export async function createRoleDefinitionsItems(context: IActionContext, subscription: AzureSubscription | ISubscriptionContext, msi: Identity, parentResourceId: string): Promise<RoleDefinitionsItem[]> { | ||
| const subContext = isAzureSubscription(subscription) ? createSubscriptionContext(subscription) : subscription; | ||
| const authClient = await createAuthorizationManagementClient([context, subContext]); | ||
|
|
||
| if (isProfileAuthorizationManagementClient(authClient)) { | ||
| throw new Error('TODO: no can do boss'); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: Do. The Azure Stack SDK does not have the |
||
| } | ||
|
|
||
| const roleAssignment = await uiUtils.listAllIterator(authClient.roleAssignments.listForSubscription()); | ||
| // filter the role assignments to only show the ones that are assigned to the msi | ||
| const roleAssignments = roleAssignment.filter((ra) => ra.principalId === msi.principalId); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,7 +81,18 @@ class SingleRoleAssignmentExecuteStep<T extends types.IResourceGroupWizardContex | |
| const roleDefinitionId = this.role.roleDefinitionId; | ||
| const principalId = nonNullValueAndProp(wizardContext.managedIdentity, 'principalId'); | ||
|
|
||
| await amClient.roleAssignments.create(scope, guid, { roleDefinitionId, principalId }); | ||
| await amClient.roleAssignments.create( | ||
| scope, | ||
| guid, | ||
| { | ||
| roleDefinitionId, // Regular SDK wants this | ||
| principalId, // Regular SDK wants this | ||
| properties: { // Azure Stack SDK wants this instead | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So does this mean the regular SDK doesn't care about having the Stack SDK properties present (in that shape) and vice versa?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope so! I expect that either they won't get serialized into the request or the service will ignore them. |
||
| roleDefinitionId, | ||
| principalId | ||
| }, | ||
| } | ||
| ); | ||
| } catch (error) { | ||
| const parsedError = parseError(error); | ||
| const maxRetries = 5; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't in
index.d.ts, should add them...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just murder
index.d.ts: #2194