@@ -53,13 +53,13 @@ wherever JavaScript can be used, including [bash on Windows 10](/windows/wsl/ins
53
53
1 . Add a reference to the Azure authentication library.
54
54
55
55
``` bash
56
- npm install @azure/ms-rest-nodeauth
56
+ npm install @azure/identity
57
57
```
58
58
59
59
> [ !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.
63
63
64
64
## Create a policy assignment
65
65
@@ -71,17 +71,16 @@ identifies resources that aren't compliant to the conditions set in the policy d
71
71
72
72
``` javascript
73
73
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" );
76
76
77
77
if (argv .subID && argv .name && argv .displayName && argv .policyDefID && argv .scope && argv .description ) {
78
78
79
79
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 );
83
82
84
- const result = await assignments .create (
83
+ const result = await client . policyAssignments .create (
85
84
argv .scope ,
86
85
argv .name ,
87
86
{
@@ -140,17 +139,16 @@ Now that your policy assignment is created, you can identify resources that aren
140
139
141
140
``` javascript
142
141
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" );
145
144
146
145
if (argv .subID && argv .name ) {
147
146
148
147
const getStates = async () => {
149
148
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 (
154
152
" latest" ,
155
153
argv .subID ,
156
154
{
@@ -202,7 +200,7 @@ Azure portal view.
202
200
- If you wish to remove the installed libraries from your application, run the following command.
203
201
204
202
``` 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
206
204
```
207
205
208
206
## Next steps
0 commit comments