Skip to content

Commit 69e58cf

Browse files
authored
Merge pull request #200241 from v-jiaodi/jd/workitem-1766073
Update file with latest SDK
2 parents c8406c1 + 82fac91 commit 69e58cf

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

articles/governance/policy/assign-policy-javascript.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ wherever JavaScript can be used, including [bash on Windows 10](/windows/wsl/ins
5353
1. Add a reference to the Azure authentication library.
5454

5555
```bash
56-
npm install @azure/ms-rest-nodeauth
56+
npm install @azure/identity
5757
```
5858

5959
> [!NOTE]
60-
> Verify in _package.json_ `@azure/arm-policy` is version **3.1.0** or higher,
61-
> `@azure/arm-policyinsights` is version **3.2.0** or higher, and `@azure/ms-rest-nodeauth` is
62-
> version **3.0.5** or higher.
60+
> Verify in _package.json_ `@azure/arm-policy` is version **5.0.1** or higher,
61+
> `@azure/arm-policyinsights` is version **5.0.0** or higher, and `@azure/identity` is
62+
> version **2.0.4** or higher.
6363
6464
## Create a policy assignment
6565

@@ -71,17 +71,16 @@ identifies resources that aren't compliant to the conditions set in the policy d
7171

7272
```javascript
7373
const argv = require("yargs").argv;
74-
const authenticator = require("@azure/ms-rest-nodeauth");
75-
const policyObjects = require("@azure/arm-policy");
74+
const { DefaultAzureCredential } = require("@azure/identity");
75+
const { PolicyClient } = require("@azure/arm-policy");
7676

7777
if (argv.subID && argv.name && argv.displayName && argv.policyDefID && argv.scope && argv.description) {
7878

7979
const createAssignment = async () => {
80-
const credentials = await authenticator.interactiveLogin();
81-
const client = new policyObjects.PolicyClient(credentials, argv.subID);
82-
const assignments = new policyObjects.PolicyAssignments(client);
80+
const credentials = new DefaultAzureCredential();
81+
const client = new PolicyClient(credentials, argv.subID);
8382

84-
const result = await assignments.create(
83+
const result = await client.policyAssignments.create(
8584
argv.scope,
8685
argv.name,
8786
{
@@ -140,17 +139,16 @@ Now that your policy assignment is created, you can identify resources that aren
140139

141140
```javascript
142141
const argv = require("yargs").argv;
143-
const authenticator = require("@azure/ms-rest-nodeauth");
144-
const policyInsights = require("@azure/arm-policyinsights");
142+
const { DefaultAzureCredential } = require("@azure/identity");
143+
const { PolicyInsightsClient } = require("@azure/arm-policyinsights");
145144

146145
if (argv.subID && argv.name) {
147146

148147
const getStates = async () => {
149148

150-
const credentials = await authenticator.interactiveLogin();
151-
const client = new policyInsights.PolicyInsightsClient(credentials);
152-
const policyStates = new policyInsights.PolicyStates(client);
153-
const result = await policyStates.listQueryResultsForSubscription(
149+
const credentials = new DefaultAzureCredential();
150+
const client = new PolicyInsightsClient(credentials);
151+
const result = client.policyStates.listQueryResultsForSubscription(
154152
"latest",
155153
argv.subID,
156154
{
@@ -202,7 +200,7 @@ Azure portal view.
202200
- If you wish to remove the installed libraries from your application, run the following command.
203201

204202
```bash
205-
npm uninstall @azure/arm-policy @azure/arm-policyinsights @azure/ms-rest-nodeauth yargs
203+
npm uninstall @azure/arm-policy @azure/arm-policyinsights @azure/identity yargs
206204
```
207205

208206
## Next steps

0 commit comments

Comments
 (0)