Skip to content

Commit 9346507

Browse files
pulumi-renovate[bot]rshade
authored andcommitted
Update dependency @azure/arm-authorization to v9
1 parent 45715de commit 9346507

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

azure-ts-call-azure-sdk/index.ts

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,52 @@ import * as resources from "@pulumi/azure-native/resources";
66
import * as pulumi from "@pulumi/pulumi";
77

88
import { AuthorizationManagementClient } from "@azure/arm-authorization";
9-
import { TokenCredentials } from "@azure/ms-rest-js";
9+
import { DefaultAzureCredential } from "@azure/identity";
1010

1111
async function getAuthorizationManagementClient(): Promise<AuthorizationManagementClient> {
12-
const config = await authorization.getClientConfig();
13-
const token = await authorization.getClientToken();
14-
const credentials = new TokenCredentials(token.token);
15-
// Note: reuse the credentials and/or the client in case your scenario needs
16-
// multiple calls to Azure SDKs.
17-
return new AuthorizationManagementClient(credentials, config.subscriptionId);
12+
const config = await authorization.getClientConfig();
13+
const credentials = new DefaultAzureCredential();
14+
// Note: reuse the credentials and/or the client in case your scenario needs
15+
// multiple calls to Azure SDKs.
16+
return new AuthorizationManagementClient(credentials, config.subscriptionId);
1817
}
1918

2019
async function getRoleIdByName(roleName: string, scope?: string): Promise<string> {
21-
const client = await getAuthorizationManagementClient();
22-
const roles = await client.roleDefinitions.list(
23-
scope || "",
24-
{
25-
filter: `roleName eq '${roleName}'`,
26-
},
27-
);
28-
if (roles.length === 0) {
29-
throw new Error(`role "${roleName}" not found at scope "${scope}"`);
30-
}
31-
if (roles.length > 1) {
32-
throw new Error(`too many roles "${roleName}" found at scope "${scope}". Found: ${roles.length}`);
33-
}
34-
const role = roles[0];
35-
return role.id!;
20+
const client = await getAuthorizationManagementClient();
21+
const roles = [];
22+
for await (const role of client.roleDefinitions.list(
23+
scope || "",
24+
{
25+
filter: `roleName eq '${roleName}'`,
26+
},
27+
)) {
28+
roles.push(role);
29+
}
30+
if (roles.length === 0) {
31+
throw new Error(`role "${roleName}" not found at scope "${scope}"`);
32+
}
33+
if (roles.length > 1) {
34+
throw new Error(`too many roles "${roleName}" found at scope "${scope}". Found: ${roles.length}`);
35+
}
36+
const role = roles[0];
37+
return role.id!;
3638
}
3739

3840
const resourceGroup = new resources.ResourceGroup("registryrg");
3941

4042
const registry = new containerregistry.Registry("registry", {
41-
resourceGroupName: resourceGroup.name,
42-
sku: {
43-
name: "Basic",
44-
},
45-
adminUserEnabled: true,
43+
resourceGroupName: resourceGroup.name,
44+
sku: {
45+
name: "Basic",
46+
},
47+
adminUserEnabled: true,
4648
});
4749

4850
const currentServicePrincipalId = pulumi.output(authorization.getClientConfig()).objectId;
4951

5052
const grantPull = new authorization.RoleAssignment("access-from-cluster", {
51-
principalId: currentServicePrincipalId,
52-
principalType: authorization.PrincipalType.ServicePrincipal, // adjust the type if you are running as a user
53-
roleDefinitionId: getRoleIdByName("AcrPull"),
54-
scope: registry.id,
53+
principalId: currentServicePrincipalId,
54+
principalType: authorization.PrincipalType.ServicePrincipal, // adjust the type if you are running as a user
55+
roleDefinitionId: getRoleIdByName("AcrPull"),
56+
scope: registry.id,
5557
});

azure-ts-call-azure-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"@types/node": "22.13.5"
66
},
77
"dependencies": {
8-
"@azure/arm-authorization": "^8.3.3",
8+
"@azure/arm-authorization": "^9.0.0",
99
"@azure/ms-rest-js": "^2.4.0",
1010
"@pulumi/azure-native": "2.89.3",
1111
"@pulumi/pulumi": "3.157.0"

0 commit comments

Comments
 (0)