From 5f326d05ac5448b28dcf21d767240ab2364029d7 Mon Sep 17 00:00:00 2001 From: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Date: Wed, 24 May 2023 15:23:29 +0800 Subject: [PATCH] [Mgmt][arm-policy] Fix issue #25857 (#25889) https://github.com/Azure/azure-sdk-for-js/issues/25857 --- common/config/rush/pnpm-lock.yaml | 4 +- sdk/policy/arm-policy/CHANGELOG.md | 40 ++++++-- sdk/policy/arm-policy/LICENSE | 2 +- sdk/policy/arm-policy/_meta.json | 8 +- sdk/policy/arm-policy/assets.json | 2 +- sdk/policy/arm-policy/package.json | 9 +- .../arm-policy/review/arm-policy.api.md | 28 +----- ...ataPolicyManifestsGetByPolicyModeSample.ts | 13 ++- .../dataPolicyManifestsListSample.ts | 20 +++- .../policyAssignmentsCreateByIdSample.ts | 20 +++- .../policyAssignmentsCreateSample.ts | 47 +++++---- .../policyAssignmentsDeleteByIdSample.ts | 13 ++- .../policyAssignmentsDeleteSample.ts | 13 ++- .../policyAssignmentsGetByIdSample.ts | 20 +++- .../samples-dev/policyAssignmentsGetSample.ts | 27 ++++-- ...AssignmentsListForManagementGroupSample.ts | 13 ++- ...cyAssignmentsListForResourceGroupSample.ts | 16 +++- .../policyAssignmentsListForResourceSample.ts | 16 +++- .../policyAssignmentsListSample.ts | 13 ++- .../policyAssignmentsUpdateByIdSample.ts | 13 ++- .../policyAssignmentsUpdateSample.ts | 20 +++- ...nsCreateOrUpdateAtManagementGroupSample.ts | 13 ++- .../policyDefinitionsCreateOrUpdateSample.ts | 20 +++- ...efinitionsDeleteAtManagementGroupSample.ts | 13 ++- .../policyDefinitionsDeleteSample.ts | 13 ++- ...cyDefinitionsGetAtManagementGroupSample.ts | 13 ++- .../policyDefinitionsGetBuiltInSample.ts | 13 ++- .../samples-dev/policyDefinitionsGetSample.ts | 13 ++- .../policyDefinitionsListBuiltInSample.ts | 13 ++- ...yDefinitionsListByManagementGroupSample.ts | 13 ++- .../policyDefinitionsListSample.ts | 13 ++- .../policyExemptionsCreateOrUpdateSample.ts | 13 ++- .../policyExemptionsDeleteSample.ts | 13 ++- .../samples-dev/policyExemptionsGetSample.ts | 13 ++- ...yExemptionsListForManagementGroupSample.ts | 13 ++- ...icyExemptionsListForResourceGroupSample.ts | 16 +++- .../policyExemptionsListForResourceSample.ts | 16 +++- .../samples-dev/policyExemptionsListSample.ts | 13 ++- ...nsCreateOrUpdateAtManagementGroupSample.ts | 22 +++-- ...olicySetDefinitionsCreateOrUpdateSample.ts | 20 +++- ...efinitionsDeleteAtManagementGroupSample.ts | 13 ++- .../policySetDefinitionsDeleteSample.ts | 13 ++- ...etDefinitionsGetAtManagementGroupSample.ts | 13 ++- .../policySetDefinitionsGetBuiltInSample.ts | 13 ++- .../policySetDefinitionsGetSample.ts | 13 ++- .../policySetDefinitionsListBuiltInSample.ts | 13 ++- ...tDefinitionsListByManagementGroupSample.ts | 13 ++- .../policySetDefinitionsListSample.ts | 13 ++- .../samples/v5/javascript/README.md | 2 +- ...ataPolicyManifestsGetByPolicyModeSample.js | 10 +- .../dataPolicyManifestsListSample.js | 16 +++- .../policyAssignmentsCreateByIdSample.js | 16 +++- .../policyAssignmentsCreateSample.js | 36 +++---- .../policyAssignmentsDeleteByIdSample.js | 10 +- .../policyAssignmentsDeleteSample.js | 10 +- .../policyAssignmentsGetByIdSample.js | 16 +++- .../javascript/policyAssignmentsGetSample.js | 22 +++-- ...AssignmentsListForManagementGroupSample.js | 10 +- ...cyAssignmentsListForResourceGroupSample.js | 12 ++- .../policyAssignmentsListForResourceSample.js | 12 ++- .../javascript/policyAssignmentsListSample.js | 10 +- .../policyAssignmentsUpdateByIdSample.js | 10 +- .../policyAssignmentsUpdateSample.js | 16 +++- ...nsCreateOrUpdateAtManagementGroupSample.js | 10 +- .../policyDefinitionsCreateOrUpdateSample.js | 16 +++- ...efinitionsDeleteAtManagementGroupSample.js | 10 +- .../policyDefinitionsDeleteSample.js | 10 +- ...cyDefinitionsGetAtManagementGroupSample.js | 10 +- .../policyDefinitionsGetBuiltInSample.js | 10 +- .../javascript/policyDefinitionsGetSample.js | 10 +- .../policyDefinitionsListBuiltInSample.js | 10 +- ...yDefinitionsListByManagementGroupSample.js | 10 +- .../javascript/policyDefinitionsListSample.js | 10 +- .../policyExemptionsCreateOrUpdateSample.js | 10 +- .../policyExemptionsDeleteSample.js | 10 +- .../javascript/policyExemptionsGetSample.js | 10 +- ...yExemptionsListForManagementGroupSample.js | 10 +- ...icyExemptionsListForResourceGroupSample.js | 12 ++- .../policyExemptionsListForResourceSample.js | 12 ++- .../javascript/policyExemptionsListSample.js | 10 +- ...nsCreateOrUpdateAtManagementGroupSample.js | 16 +++- ...olicySetDefinitionsCreateOrUpdateSample.js | 16 +++- ...efinitionsDeleteAtManagementGroupSample.js | 10 +- .../policySetDefinitionsDeleteSample.js | 10 +- ...etDefinitionsGetAtManagementGroupSample.js | 10 +- .../policySetDefinitionsGetBuiltInSample.js | 10 +- .../policySetDefinitionsGetSample.js | 10 +- .../policySetDefinitionsListBuiltInSample.js | 10 +- ...tDefinitionsListByManagementGroupSample.js | 10 +- .../policySetDefinitionsListSample.js | 10 +- .../samples/v5/typescript/README.md | 2 +- ...ataPolicyManifestsGetByPolicyModeSample.ts | 13 ++- .../src/dataPolicyManifestsListSample.ts | 20 +++- .../src/policyAssignmentsCreateByIdSample.ts | 20 +++- .../src/policyAssignmentsCreateSample.ts | 47 +++++---- .../src/policyAssignmentsDeleteByIdSample.ts | 13 ++- .../src/policyAssignmentsDeleteSample.ts | 13 ++- .../src/policyAssignmentsGetByIdSample.ts | 20 +++- .../src/policyAssignmentsGetSample.ts | 27 ++++-- ...AssignmentsListForManagementGroupSample.ts | 13 ++- ...cyAssignmentsListForResourceGroupSample.ts | 16 +++- .../policyAssignmentsListForResourceSample.ts | 16 +++- .../src/policyAssignmentsListSample.ts | 13 ++- .../src/policyAssignmentsUpdateByIdSample.ts | 13 ++- .../src/policyAssignmentsUpdateSample.ts | 20 +++- ...nsCreateOrUpdateAtManagementGroupSample.ts | 13 ++- .../policyDefinitionsCreateOrUpdateSample.ts | 20 +++- ...efinitionsDeleteAtManagementGroupSample.ts | 13 ++- .../src/policyDefinitionsDeleteSample.ts | 13 ++- ...cyDefinitionsGetAtManagementGroupSample.ts | 13 ++- .../src/policyDefinitionsGetBuiltInSample.ts | 13 ++- .../src/policyDefinitionsGetSample.ts | 13 ++- .../src/policyDefinitionsListBuiltInSample.ts | 13 ++- ...yDefinitionsListByManagementGroupSample.ts | 13 ++- .../src/policyDefinitionsListSample.ts | 13 ++- .../policyExemptionsCreateOrUpdateSample.ts | 13 ++- .../src/policyExemptionsDeleteSample.ts | 13 ++- .../src/policyExemptionsGetSample.ts | 13 ++- ...yExemptionsListForManagementGroupSample.ts | 13 ++- ...icyExemptionsListForResourceGroupSample.ts | 16 +++- .../policyExemptionsListForResourceSample.ts | 16 +++- .../src/policyExemptionsListSample.ts | 13 ++- ...nsCreateOrUpdateAtManagementGroupSample.ts | 22 +++-- ...olicySetDefinitionsCreateOrUpdateSample.ts | 20 +++- ...efinitionsDeleteAtManagementGroupSample.ts | 13 ++- .../src/policySetDefinitionsDeleteSample.ts | 13 ++- ...etDefinitionsGetAtManagementGroupSample.ts | 13 ++- .../policySetDefinitionsGetBuiltInSample.ts | 13 ++- .../src/policySetDefinitionsGetSample.ts | 13 ++- .../policySetDefinitionsListBuiltInSample.ts | 13 ++- ...tDefinitionsListByManagementGroupSample.ts | 13 ++- .../src/policySetDefinitionsListSample.ts | 13 ++- .../samples/v5/typescript/tsconfig.json | 2 +- sdk/policy/arm-policy/src/models/index.ts | 95 +++---------------- .../src/operations/dataPolicyManifests.ts | 1 - .../src/operations/policyAssignments.ts | 4 - .../src/operations/policyDefinitions.ts | 3 - .../src/operations/policyExemptions.ts | 4 - .../src/operations/policySetDefinitions.ts | 3 - sdk/policy/arm-policy/src/pagingHelper.ts | 8 +- sdk/policy/arm-policy/src/policyClient.ts | 23 ++++- sdk/policy/arm-policy/test/policy_examples.ts | 17 +++- 142 files changed, 1494 insertions(+), 549 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 552fd8ab695e..e17b6aadc570 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -13492,7 +13492,7 @@ packages: dev: false file:projects/arm-policy.tgz: - resolution: {integrity: sha512-+wk1hJhnsWwnOXefGyaH8WkAGjGwe4fwturWRn35Gn45Qy8N4SC3ZviOrOmcWu+PDZTl9HajkJ3/p7AcAicH1w==, tarball: file:projects/arm-policy.tgz} + resolution: {integrity: sha512-bujYRtPnaCJrOaM96o1BN+dxqTmJGCCm/ZlHwohsY2oPVk0AqYiw68MefDKBYLD6mw7VZARX9AUqHoAHaFMz6w==, tarball: file:projects/arm-policy.tgz} name: '@rush-temp/arm-policy' version: 0.0.0 dependencies: @@ -13507,7 +13507,7 @@ packages: chai: 4.3.7 cross-env: 7.0.3 dotenv: 16.0.3 - mkdirp: 1.0.4 + mkdirp: 2.1.6 mocha: 7.2.0 rimraf: 3.0.2 rollup: 2.79.1 diff --git a/sdk/policy/arm-policy/CHANGELOG.md b/sdk/policy/arm-policy/CHANGELOG.md index 6f1461494737..021271f131b7 100644 --- a/sdk/policy/arm-policy/CHANGELOG.md +++ b/sdk/policy/arm-policy/CHANGELOG.md @@ -1,15 +1,35 @@ # Release History + +## 5.1.0 (2023-05-18) + +**Features** -## 5.0.4 (Unreleased) - -### Features Added - -### Breaking Changes - -### Bugs Fixed - -### Other Changes - + - Interface DataPolicyManifestsListNextOptionalParams no longer has parameter filter + - Interface PolicyAssignmentsListForManagementGroupNextOptionalParams no longer has parameter filter + - Interface PolicyAssignmentsListForManagementGroupNextOptionalParams no longer has parameter top + - Interface PolicyAssignmentsListForResourceGroupNextOptionalParams no longer has parameter filter + - Interface PolicyAssignmentsListForResourceGroupNextOptionalParams no longer has parameter top + - Interface PolicyAssignmentsListForResourceNextOptionalParams no longer has parameter filter + - Interface PolicyAssignmentsListForResourceNextOptionalParams no longer has parameter top + - Interface PolicyAssignmentsListNextOptionalParams no longer has parameter filter + - Interface PolicyAssignmentsListNextOptionalParams no longer has parameter top + - Interface PolicyDefinitionsListBuiltInNextOptionalParams no longer has parameter filter + - Interface PolicyDefinitionsListBuiltInNextOptionalParams no longer has parameter top + - Interface PolicyDefinitionsListByManagementGroupNextOptionalParams no longer has parameter filter + - Interface PolicyDefinitionsListByManagementGroupNextOptionalParams no longer has parameter top + - Interface PolicyDefinitionsListNextOptionalParams no longer has parameter filter + - Interface PolicyDefinitionsListNextOptionalParams no longer has parameter top + - Interface PolicyExemptionsListForManagementGroupNextOptionalParams no longer has parameter filter + - Interface PolicyExemptionsListForResourceGroupNextOptionalParams no longer has parameter filter + - Interface PolicyExemptionsListForResourceNextOptionalParams no longer has parameter filter + - Interface PolicyExemptionsListNextOptionalParams no longer has parameter filter + - Interface PolicySetDefinitionsListBuiltInNextOptionalParams no longer has parameter filter + - Interface PolicySetDefinitionsListBuiltInNextOptionalParams no longer has parameter top + - Interface PolicySetDefinitionsListByManagementGroupNextOptionalParams no longer has parameter filter + - Interface PolicySetDefinitionsListByManagementGroupNextOptionalParams no longer has parameter top + - Interface PolicySetDefinitionsListNextOptionalParams no longer has parameter filter + - Interface PolicySetDefinitionsListNextOptionalParams no longer has parameter top + ## 5.0.3 (2022-11-28) **Features** diff --git a/sdk/policy/arm-policy/LICENSE b/sdk/policy/arm-policy/LICENSE index 5d1d36e0af80..3a1d9b6f24f7 100644 --- a/sdk/policy/arm-policy/LICENSE +++ b/sdk/policy/arm-policy/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2022 Microsoft +Copyright (c) 2023 Microsoft Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/sdk/policy/arm-policy/_meta.json b/sdk/policy/arm-policy/_meta.json index c7ad3e56f301..6878746ca206 100644 --- a/sdk/policy/arm-policy/_meta.json +++ b/sdk/policy/arm-policy/_meta.json @@ -1,8 +1,8 @@ { "commit": "a42f1b58607091c4f255ead152a8ef323fa0b280", - "readme": "specification/resources/resource-manager/readme.md", - "autorest_command": "autorest --version=3.8.4 --typescript --modelerfour.lenient-model-deduplication --azure-arm --head-as-boolean=true --license-header=MICROSOFT_MIT_NO_VERSION --generate-test --typescript-sdks-folder=D:\\Git\\azure-sdk-for-js ..\\azure-rest-api-specs\\specification\\resources\\resource-manager\\readme.md --use=@autorest/typescript@6.0.0-rc.3.20221108.1 --generate-sample=true", + "readme": "specification\\resources\\resource-manager\\readme.md", + "autorest_command": "autorest --version=3.9.3 --typescript --modelerfour.lenient-model-deduplication --azure-arm --head-as-boolean=true --license-header=MICROSOFT_MIT_NO_VERSION --generate-test --typescript-sdks-folder=D:\\Git\\azure-sdk-for-js ..\\azure-rest-api-specs\\specification\\resources\\resource-manager\\readme.md --use=@autorest/typescript@6.0.2 --generate-sample=true", "repository_url": "https://github.com/Azure/azure-rest-api-specs.git", - "release_tool": "@azure-tools/js-sdk-release-tools@2.4.2", - "use": "@autorest/typescript@6.0.0-rc.3.20221108.1" + "release_tool": "@azure-tools/js-sdk-release-tools@2.6.2", + "use": "@autorest/typescript@6.0.2" } \ No newline at end of file diff --git a/sdk/policy/arm-policy/assets.json b/sdk/policy/arm-policy/assets.json index fce1955244ba..209892512af6 100644 --- a/sdk/policy/arm-policy/assets.json +++ b/sdk/policy/arm-policy/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "js", "TagPrefix": "js/policy/arm-policy", - "Tag": "js/policy/arm-policy_f045afdc79" + "Tag": "js/policy/arm-policy_5cdf0369fd" } diff --git a/sdk/policy/arm-policy/package.json b/sdk/policy/arm-policy/package.json index 1285b9fd9b11..96d56b5c24aa 100644 --- a/sdk/policy/arm-policy/package.json +++ b/sdk/policy/arm-policy/package.json @@ -3,13 +3,13 @@ "sdk-type": "mgmt", "author": "Microsoft Corporation", "description": "A generated SDK for PolicyClient.", - "version": "5.0.4", + "version": "5.1.0", "engines": { "node": ">=14.0.0" }, "dependencies": { "@azure/core-paging": "^1.2.0", - "@azure/core-client": "^1.6.1", + "@azure/core-client": "^1.7.0", "@azure/core-auth": "^1.3.0", "@azure/core-rest-pipeline": "^1.8.0", "tslib": "^2.2.0" @@ -31,12 +31,13 @@ "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-multi-entry": "^6.0.0", "@rollup/plugin-node-resolve": "^13.1.3", - "mkdirp": "^1.0.4", + "mkdirp": "^2.1.2", "rollup": "^2.66.1", "rollup-plugin-sourcemaps": "^0.6.3", "typescript": "~5.0.0", "uglify-js": "^3.4.9", "rimraf": "^3.0.0", + "dotenv": "^16.0.0", "@azure/identity": "^2.0.1", "@azure-tools/test-recorder": "^3.0.0", "@azure-tools/test-credential": "^1.0.0", @@ -48,7 +49,6 @@ "@azure/dev-tool": "^1.0.0", "@azure/arm-managementgroups": "^2.0.1" }, - "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/policy/arm-policy", "repository": { "type": "git", "url": "https://github.com/Azure/azure-sdk-for-js.git" @@ -110,6 +110,7 @@ ] }, "autoPublish": true, + "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/policy/arm-policy", "//sampleConfiguration": { "productName": "", "productSlugs": [ diff --git a/sdk/policy/arm-policy/review/arm-policy.api.md b/sdk/policy/arm-policy/review/arm-policy.api.md index 25bb71105e59..906abdb54c43 100644 --- a/sdk/policy/arm-policy/review/arm-policy.api.md +++ b/sdk/policy/arm-policy/review/arm-policy.api.md @@ -109,7 +109,6 @@ export type DataPolicyManifestsGetByPolicyModeResponse = DataPolicyManifest; // @public export interface DataPolicyManifestsListNextOptionalParams extends coreClient.OperationOptions { - filter?: string; } // @public @@ -332,8 +331,6 @@ export type PolicyAssignmentsGetResponse = PolicyAssignment; // @public export interface PolicyAssignmentsListForManagementGroupNextOptionalParams extends coreClient.OperationOptions { - filter?: string; - top?: number; } // @public @@ -350,8 +347,6 @@ export type PolicyAssignmentsListForManagementGroupResponse = PolicyAssignmentLi // @public export interface PolicyAssignmentsListForResourceGroupNextOptionalParams extends coreClient.OperationOptions { - filter?: string; - top?: number; } // @public @@ -368,8 +363,6 @@ export type PolicyAssignmentsListForResourceGroupResponse = PolicyAssignmentList // @public export interface PolicyAssignmentsListForResourceNextOptionalParams extends coreClient.OperationOptions { - filter?: string; - top?: number; } // @public @@ -386,8 +379,6 @@ export type PolicyAssignmentsListForResourceResponse = PolicyAssignmentListResul // @public export interface PolicyAssignmentsListNextOptionalParams extends coreClient.OperationOptions { - filter?: string; - top?: number; } // @public @@ -427,6 +418,7 @@ export class PolicyClient extends coreClient.ServiceClient { // (undocumented) $host: string; constructor(credentials: coreAuth.TokenCredential, subscriptionId: string, options?: PolicyClientOptionalParams); + constructor(credentials: coreAuth.TokenCredential, options?: PolicyClientOptionalParams); // (undocumented) dataPolicyManifests: DataPolicyManifests; // (undocumented) @@ -438,7 +430,7 @@ export class PolicyClient extends coreClient.ServiceClient { // (undocumented) policySetDefinitions: PolicySetDefinitions; // (undocumented) - subscriptionId: string; + subscriptionId?: string; } // @public @@ -548,8 +540,6 @@ export type PolicyDefinitionsGetResponse = PolicyDefinition; // @public export interface PolicyDefinitionsListBuiltInNextOptionalParams extends coreClient.OperationOptions { - filter?: string; - top?: number; } // @public @@ -566,8 +556,6 @@ export type PolicyDefinitionsListBuiltInResponse = PolicyDefinitionListResult; // @public export interface PolicyDefinitionsListByManagementGroupNextOptionalParams extends coreClient.OperationOptions { - filter?: string; - top?: number; } // @public @@ -584,8 +572,6 @@ export type PolicyDefinitionsListByManagementGroupResponse = PolicyDefinitionLis // @public export interface PolicyDefinitionsListNextOptionalParams extends coreClient.OperationOptions { - filter?: string; - top?: number; } // @public @@ -652,7 +638,6 @@ export type PolicyExemptionsGetResponse = PolicyExemption; // @public export interface PolicyExemptionsListForManagementGroupNextOptionalParams extends coreClient.OperationOptions { - filter?: string; } // @public @@ -668,7 +653,6 @@ export type PolicyExemptionsListForManagementGroupResponse = PolicyExemptionList // @public export interface PolicyExemptionsListForResourceGroupNextOptionalParams extends coreClient.OperationOptions { - filter?: string; } // @public @@ -684,7 +668,6 @@ export type PolicyExemptionsListForResourceGroupResponse = PolicyExemptionListRe // @public export interface PolicyExemptionsListForResourceNextOptionalParams extends coreClient.OperationOptions { - filter?: string; } // @public @@ -700,7 +683,6 @@ export type PolicyExemptionsListForResourceResponse = PolicyExemptionListResult; // @public export interface PolicyExemptionsListNextOptionalParams extends coreClient.OperationOptions { - filter?: string; } // @public @@ -796,8 +778,6 @@ export type PolicySetDefinitionsGetResponse = PolicySetDefinition; // @public export interface PolicySetDefinitionsListBuiltInNextOptionalParams extends coreClient.OperationOptions { - filter?: string; - top?: number; } // @public @@ -814,8 +794,6 @@ export type PolicySetDefinitionsListBuiltInResponse = PolicySetDefinitionListRes // @public export interface PolicySetDefinitionsListByManagementGroupNextOptionalParams extends coreClient.OperationOptions { - filter?: string; - top?: number; } // @public @@ -832,8 +810,6 @@ export type PolicySetDefinitionsListByManagementGroupResponse = PolicySetDefinit // @public export interface PolicySetDefinitionsListNextOptionalParams extends coreClient.OperationOptions { - filter?: string; - top?: number; } // @public diff --git a/sdk/policy/arm-policy/samples-dev/dataPolicyManifestsGetByPolicyModeSample.ts b/sdk/policy/arm-policy/samples-dev/dataPolicyManifestsGetByPolicyModeSample.ts index 956226d4552c..0d90725e4556 100644 --- a/sdk/policy/arm-policy/samples-dev/dataPolicyManifestsGetByPolicyModeSample.ts +++ b/sdk/policy/arm-policy/samples-dev/dataPolicyManifestsGetByPolicyModeSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the data policy manifest with the given policy mode. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/getDataPolicyManifest.json */ async function retrieveADataPolicyManifestByPolicyMode() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyMode = "Microsoft.KeyVault.Data"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +31,8 @@ async function retrieveADataPolicyManifestByPolicyMode() { console.log(result); } -retrieveADataPolicyManifestByPolicyMode().catch(console.error); +async function main() { + retrieveADataPolicyManifestByPolicyMode(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/dataPolicyManifestsListSample.ts b/sdk/policy/arm-policy/samples-dev/dataPolicyManifestsListSample.ts index b9a1e68ed467..f2f7644f5e85 100644 --- a/sdk/policy/arm-policy/samples-dev/dataPolicyManifestsListSample.ts +++ b/sdk/policy/arm-policy/samples-dev/dataPolicyManifestsListSample.ts @@ -13,6 +13,9 @@ import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a list of all the data policy manifests that match the optional given $filter. Valid values for $filter are: "$filter=namespace eq '{0}'". If $filter is not provided, the unfiltered list includes all data policy manifests for data resource types. If $filter=namespace is provided, the returned list only includes all data policy manifests that have a namespace matching the provided value. @@ -21,7 +24,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/listDataPolicyManifests.json */ async function listDataPolicyManifests() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -31,8 +36,6 @@ async function listDataPolicyManifests() { console.log(resArray); } -listDataPolicyManifests().catch(console.error); - /** * This sample demonstrates how to This operation retrieves a list of all the data policy manifests that match the optional given $filter. Valid values for $filter are: "$filter=namespace eq '{0}'". If $filter is not provided, the unfiltered list includes all data policy manifests for data resource types. If $filter=namespace is provided, the returned list only includes all data policy manifests that have a namespace matching the provided value. * @@ -40,7 +43,9 @@ listDataPolicyManifests().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/listDataPolicyManifestsNamespaceFilter.json */ async function listDataPolicyManifestsWithNamespaceFilter() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const filter = "namespace eq 'Microsoft.KeyVault'"; const options: DataPolicyManifestsListOptionalParams = { filter }; const credential = new DefaultAzureCredential(); @@ -52,4 +57,9 @@ async function listDataPolicyManifestsWithNamespaceFilter() { console.log(resArray); } -listDataPolicyManifestsWithNamespaceFilter().catch(console.error); +async function main() { + listDataPolicyManifests(); + listDataPolicyManifestsWithNamespaceFilter(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyAssignmentsCreateByIdSample.ts b/sdk/policy/arm-policy/samples-dev/policyAssignmentsCreateByIdSample.ts index c4cf52a4165d..ac2ee1876dff 100644 --- a/sdk/policy/arm-policy/samples-dev/policyAssignmentsCreateByIdSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyAssignmentsCreateByIdSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyAssignment, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation creates or updates the policy assignment with the given ID. Policy assignments made on a scope apply to all resources contained in that scope. For example, when you assign a policy to a resource group that policy applies to all resources in the group. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentById.json */ async function createOrUpdatePolicyAssignmentById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const parameters: PolicyAssignment = { @@ -42,8 +47,6 @@ async function createOrUpdatePolicyAssignmentById() { console.log(result); } -createOrUpdatePolicyAssignmentById().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates the policy assignment with the given ID. Policy assignments made on a scope apply to all resources contained in that scope. For example, when you assign a policy to a resource group that policy applies to all resources in the group. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. * @@ -51,7 +54,9 @@ createOrUpdatePolicyAssignmentById().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithIdentityById.json */ async function createOrUpdatePolicyAssignmentWithAManagedIdentityById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const parameters: PolicyAssignment = { @@ -77,4 +82,9 @@ async function createOrUpdatePolicyAssignmentWithAManagedIdentityById() { console.log(result); } -createOrUpdatePolicyAssignmentWithAManagedIdentityById().catch(console.error); +async function main() { + createOrUpdatePolicyAssignmentById(); + createOrUpdatePolicyAssignmentWithAManagedIdentityById(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyAssignmentsCreateSample.ts b/sdk/policy/arm-policy/samples-dev/policyAssignmentsCreateSample.ts index 133bde87b7fb..37aee9e33096 100644 --- a/sdk/policy/arm-policy/samples-dev/policyAssignmentsCreateSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyAssignmentsCreateSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyAssignment, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignment.json */ async function createOrUpdateAPolicyAssignment() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters: PolicyAssignment = { @@ -43,8 +48,6 @@ async function createOrUpdateAPolicyAssignment() { console.log(result); } -createOrUpdateAPolicyAssignment().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -52,7 +55,9 @@ createOrUpdateAPolicyAssignment().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithIdentity.json */ async function createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters: PolicyAssignment = { @@ -77,10 +82,6 @@ async function createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity() { console.log(result); } -createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity().catch( - console.error -); - /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -88,7 +89,9 @@ createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity().catch( * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithUserAssignedIdentity.json */ async function createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters: PolicyAssignment = { @@ -118,8 +121,6 @@ async function createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity() { console.log(result); } -createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -127,7 +128,9 @@ createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentNonComplianceMessages.json */ async function createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "securityInitAssignment"; const parameters: PolicyAssignment = { @@ -159,10 +162,6 @@ async function createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages( console.log(result); } -createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages().catch( - console.error -); - /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -170,7 +169,9 @@ createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages().catch( * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithoutEnforcement.json */ async function createOrUpdateAPolicyAssignmentWithoutEnforcingPolicyEffectDuringResourceCreationOrUpdate() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters: PolicyAssignment = { @@ -193,6 +194,12 @@ async function createOrUpdateAPolicyAssignmentWithoutEnforcingPolicyEffectDuring console.log(result); } -createOrUpdateAPolicyAssignmentWithoutEnforcingPolicyEffectDuringResourceCreationOrUpdate().catch( - console.error -); +async function main() { + createOrUpdateAPolicyAssignment(); + createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity(); + createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity(); + createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages(); + createOrUpdateAPolicyAssignmentWithoutEnforcingPolicyEffectDuringResourceCreationOrUpdate(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyAssignmentsDeleteByIdSample.ts b/sdk/policy/arm-policy/samples-dev/policyAssignmentsDeleteByIdSample.ts index d35b62115dc8..0aa1ac4f69d2 100644 --- a/sdk/policy/arm-policy/samples-dev/policyAssignmentsDeleteByIdSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyAssignmentsDeleteByIdSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation deletes the policy with the given ID. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid formats for {scope} are: '/providers/Microsoft.Management/managementGroups/{managementGroup}' (management group), '/subscriptions/{subscriptionId}' (subscription), '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' (resource group), or '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}' (resource). @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyAssignmentById.json */ async function deleteAPolicyAssignmentById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const credential = new DefaultAzureCredential(); @@ -27,4 +32,8 @@ async function deleteAPolicyAssignmentById() { console.log(result); } -deleteAPolicyAssignmentById().catch(console.error); +async function main() { + deleteAPolicyAssignmentById(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyAssignmentsDeleteSample.ts b/sdk/policy/arm-policy/samples-dev/policyAssignmentsDeleteSample.ts index e2976b8ac214..196f29e55cc9 100644 --- a/sdk/policy/arm-policy/samples-dev/policyAssignmentsDeleteSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyAssignmentsDeleteSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation deletes a policy assignment, given its name and the scope it was created in. The scope of a policy assignment is the part of its ID preceding '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyAssignment.json */ async function deleteAPolicyAssignment() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const credential = new DefaultAzureCredential(); @@ -30,4 +35,8 @@ async function deleteAPolicyAssignment() { console.log(result); } -deleteAPolicyAssignment().catch(console.error); +async function main() { + deleteAPolicyAssignment(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyAssignmentsGetByIdSample.ts b/sdk/policy/arm-policy/samples-dev/policyAssignmentsGetByIdSample.ts index 1733f93e2cd9..78996c20c468 100644 --- a/sdk/policy/arm-policy/samples-dev/policyAssignmentsGetByIdSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyAssignmentsGetByIdSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to The operation retrieves the policy assignment with the given ID. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentById.json */ async function retrieveAPolicyAssignmentById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const credential = new DefaultAzureCredential(); @@ -27,8 +32,6 @@ async function retrieveAPolicyAssignmentById() { console.log(result); } -retrieveAPolicyAssignmentById().catch(console.error); - /** * This sample demonstrates how to The operation retrieves the policy assignment with the given ID. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. * @@ -36,7 +39,9 @@ retrieveAPolicyAssignmentById().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentWithIdentityById.json */ async function retrieveAPolicyAssignmentWithAManagedIdentityById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const credential = new DefaultAzureCredential(); @@ -45,4 +50,9 @@ async function retrieveAPolicyAssignmentWithAManagedIdentityById() { console.log(result); } -retrieveAPolicyAssignmentWithAManagedIdentityById().catch(console.error); +async function main() { + retrieveAPolicyAssignmentById(); + retrieveAPolicyAssignmentWithAManagedIdentityById(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyAssignmentsGetSample.ts b/sdk/policy/arm-policy/samples-dev/policyAssignmentsGetSample.ts index 0b98df70f83a..e513b65584b8 100644 --- a/sdk/policy/arm-policy/samples-dev/policyAssignmentsGetSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyAssignmentsGetSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a single policy assignment, given its name and the scope it was created at. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignment.json */ async function retrieveAPolicyAssignment() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const credential = new DefaultAzureCredential(); @@ -30,8 +35,6 @@ async function retrieveAPolicyAssignment() { console.log(result); } -retrieveAPolicyAssignment().catch(console.error); - /** * This sample demonstrates how to This operation retrieves a single policy assignment, given its name and the scope it was created at. * @@ -39,7 +42,9 @@ retrieveAPolicyAssignment().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentWithIdentity.json */ async function retrieveAPolicyAssignmentWithASystemAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const credential = new DefaultAzureCredential(); @@ -51,8 +56,6 @@ async function retrieveAPolicyAssignmentWithASystemAssignedIdentity() { console.log(result); } -retrieveAPolicyAssignmentWithASystemAssignedIdentity().catch(console.error); - /** * This sample demonstrates how to This operation retrieves a single policy assignment, given its name and the scope it was created at. * @@ -60,7 +63,9 @@ retrieveAPolicyAssignmentWithASystemAssignedIdentity().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentWithUserAssignedIdentity.json */ async function retrieveAPolicyAssignmentWithAUserAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const credential = new DefaultAzureCredential(); @@ -72,4 +77,10 @@ async function retrieveAPolicyAssignmentWithAUserAssignedIdentity() { console.log(result); } -retrieveAPolicyAssignmentWithAUserAssignedIdentity().catch(console.error); +async function main() { + retrieveAPolicyAssignment(); + retrieveAPolicyAssignmentWithASystemAssignedIdentity(); + retrieveAPolicyAssignmentWithAUserAssignedIdentity(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyAssignmentsListForManagementGroupSample.ts b/sdk/policy/arm-policy/samples-dev/policyAssignmentsListForManagementGroupSample.ts index dacf306881b2..a49056ffe7f2 100644 --- a/sdk/policy/arm-policy/samples-dev/policyAssignmentsListForManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyAssignmentsListForManagementGroupSample.ts @@ -13,6 +13,9 @@ import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy assignments applicable to the management group that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter=atScope() is provided, the returned list includes all policy assignments that are assigned to the management group or the management group's ancestors. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the management group. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value} that apply to the management group. @@ -21,7 +24,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignmentsForManagementGroup.json */ async function listPolicyAssignmentsThatApplyToAManagementGroup() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const managementGroupId = "TestManagementGroup"; const filter = "atScope()"; const options: PolicyAssignmentsListForManagementGroupOptionalParams = { @@ -39,4 +44,8 @@ async function listPolicyAssignmentsThatApplyToAManagementGroup() { console.log(resArray); } -listPolicyAssignmentsThatApplyToAManagementGroup().catch(console.error); +async function main() { + listPolicyAssignmentsThatApplyToAManagementGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyAssignmentsListForResourceGroupSample.ts b/sdk/policy/arm-policy/samples-dev/policyAssignmentsListForResourceGroupSample.ts index 43679b8ae4c8..83f6cff931cf 100644 --- a/sdk/policy/arm-policy/samples-dev/policyAssignmentsListForResourceGroupSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyAssignmentsListForResourceGroupSample.ts @@ -13,6 +13,9 @@ import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy assignments associated with the given resource group in the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments associated with the resource group, including those that apply directly or apply from containing scopes, as well as any applied to resources contained within the resource group. If $filter=atScope() is provided, the returned list includes all policy assignments that apply to the resource group, which is everything in the unfiltered list except those applied to resources contained within the resource group. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the resource group. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value} that apply to the resource group. @@ -21,8 +24,11 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignmentsForResourceGroup.json */ async function listPolicyAssignmentsThatApplyToAResourceGroup() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; - const resourceGroupName = "TestResourceGroup"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const resourceGroupName = + process.env["POLICY_RESOURCE_GROUP"] || "TestResourceGroup"; const filter = "atScope()"; const options: PolicyAssignmentsListForResourceGroupOptionalParams = { filter @@ -39,4 +45,8 @@ async function listPolicyAssignmentsThatApplyToAResourceGroup() { console.log(resArray); } -listPolicyAssignmentsThatApplyToAResourceGroup().catch(console.error); +async function main() { + listPolicyAssignmentsThatApplyToAResourceGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyAssignmentsListForResourceSample.ts b/sdk/policy/arm-policy/samples-dev/policyAssignmentsListForResourceSample.ts index 0d43e41446b9..4d7755b80551 100644 --- a/sdk/policy/arm-policy/samples-dev/policyAssignmentsListForResourceSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyAssignmentsListForResourceSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy assignments associated with the specified resource in the given resource group and subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments associated with the resource, including those that apply directly or from all containing scopes, as well as any applied to resources contained within the resource. If $filter=atScope() is provided, the returned list includes all policy assignments that apply to the resource, which is everything in the unfiltered list except those applied to resources contained within the resource. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the resource level. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value} that apply to the resource. Three parameters plus the resource name are used to identify a specific resource. If the resource is not part of a parent resource (the more common case), the parent resource path should not be provided (or provided as ''). For example a web app could be specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all parameters should be provided. For example a virtual machine DNS name could be specified as ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == 'MyComputerName'). A convenient alternative to providing the namespace and type name separately is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp'). @@ -18,8 +21,11 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignmentsForResource.json */ async function listAllPolicyAssignmentsThatApplyToAResource() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; - const resourceGroupName = "TestResourceGroup"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const resourceGroupName = + process.env["POLICY_RESOURCE_GROUP"] || "TestResourceGroup"; const resourceProviderNamespace = "Microsoft.Compute"; const parentResourcePath = "virtualMachines/MyTestVm"; const resourceType = "domainNames"; @@ -39,4 +45,8 @@ async function listAllPolicyAssignmentsThatApplyToAResource() { console.log(resArray); } -listAllPolicyAssignmentsThatApplyToAResource().catch(console.error); +async function main() { + listAllPolicyAssignmentsThatApplyToAResource(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyAssignmentsListSample.ts b/sdk/policy/arm-policy/samples-dev/policyAssignmentsListSample.ts index c3e9575f594c..225dc0e897d4 100644 --- a/sdk/policy/arm-policy/samples-dev/policyAssignmentsListSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyAssignmentsListSample.ts @@ -13,6 +13,9 @@ import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy assignments associated with the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments associated with the subscription, including those that apply directly or from management groups that contain the given subscription, as well as any applied to objects contained within the subscription. If $filter=atScope() is provided, the returned list includes all policy assignments that apply to the subscription, which is everything in the unfiltered list except those applied to objects contained within the subscription. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the subscription. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value}. @@ -21,7 +24,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignments.json */ async function listPolicyAssignmentsThatApplyToASubscription() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const filter = "atScope()"; const options: PolicyAssignmentsListOptionalParams = { filter }; const credential = new DefaultAzureCredential(); @@ -33,4 +38,8 @@ async function listPolicyAssignmentsThatApplyToASubscription() { console.log(resArray); } -listPolicyAssignmentsThatApplyToASubscription().catch(console.error); +async function main() { + listPolicyAssignmentsThatApplyToASubscription(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyAssignmentsUpdateByIdSample.ts b/sdk/policy/arm-policy/samples-dev/policyAssignmentsUpdateByIdSample.ts index 3f654336a500..a69a4a007801 100644 --- a/sdk/policy/arm-policy/samples-dev/policyAssignmentsUpdateByIdSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyAssignmentsUpdateByIdSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyAssignmentUpdate, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation updates the policy assignment with the given ID. Policy assignments made on a scope apply to all resources contained in that scope. For example, when you assign a policy to a resource group that policy applies to all resources in the group. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/updatePolicyAssignmentWithIdentityById.json */ async function updatePolicyAssignmentWithAManagedIdentityById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const parameters: PolicyAssignmentUpdate = { @@ -34,4 +39,8 @@ async function updatePolicyAssignmentWithAManagedIdentityById() { console.log(result); } -updatePolicyAssignmentWithAManagedIdentityById().catch(console.error); +async function main() { + updatePolicyAssignmentWithAManagedIdentityById(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyAssignmentsUpdateSample.ts b/sdk/policy/arm-policy/samples-dev/policyAssignmentsUpdateSample.ts index 2c5ad77e13d0..14052f66cd03 100644 --- a/sdk/policy/arm-policy/samples-dev/policyAssignmentsUpdateSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyAssignmentsUpdateSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyAssignmentUpdate, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/updatePolicyAssignmentWithIdentity.json */ async function updateAPolicyAssignmentWithASystemAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters: PolicyAssignmentUpdate = { @@ -35,8 +40,6 @@ async function updateAPolicyAssignmentWithASystemAssignedIdentity() { console.log(result); } -updateAPolicyAssignmentWithASystemAssignedIdentity().catch(console.error); - /** * This sample demonstrates how to This operation updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -44,7 +47,9 @@ updateAPolicyAssignmentWithASystemAssignedIdentity().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/updatePolicyAssignmentWithUserAssignedIdentity.json */ async function updateAPolicyAssignmentWithAUserAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters: PolicyAssignmentUpdate = { @@ -66,4 +71,9 @@ async function updateAPolicyAssignmentWithAUserAssignedIdentity() { console.log(result); } -updateAPolicyAssignmentWithAUserAssignedIdentity().catch(console.error); +async function main() { + updateAPolicyAssignmentWithASystemAssignedIdentity(); + updateAPolicyAssignmentWithAUserAssignedIdentity(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyDefinitionsCreateOrUpdateAtManagementGroupSample.ts b/sdk/policy/arm-policy/samples-dev/policyDefinitionsCreateOrUpdateAtManagementGroupSample.ts index eb6f78d43180..2bd9e6d06d21 100644 --- a/sdk/policy/arm-policy/samples-dev/policyDefinitionsCreateOrUpdateAtManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyDefinitionsCreateOrUpdateAtManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyDefinition, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation creates or updates a policy definition in the given management group with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinitionAtManagementGroup.json */ async function createOrUpdateAPolicyDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyDefinitionName = "ResourceNaming"; const managementGroupId = "MyManagementGroup"; const parameters: PolicyDefinition = { @@ -57,4 +62,8 @@ async function createOrUpdateAPolicyDefinitionAtManagementGroupLevel() { console.log(result); } -createOrUpdateAPolicyDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + createOrUpdateAPolicyDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyDefinitionsCreateOrUpdateSample.ts b/sdk/policy/arm-policy/samples-dev/policyDefinitionsCreateOrUpdateSample.ts index 73945549810e..ca2517d2e44d 100644 --- a/sdk/policy/arm-policy/samples-dev/policyDefinitionsCreateOrUpdateSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyDefinitionsCreateOrUpdateSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyDefinition, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation creates or updates a policy definition in the given subscription with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinition.json */ async function createOrUpdateAPolicyDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyDefinitionName = "ResourceNaming"; const parameters: PolicyDefinition = { description: @@ -55,8 +60,6 @@ async function createOrUpdateAPolicyDefinition() { console.log(result); } -createOrUpdateAPolicyDefinition().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy definition in the given subscription with the given name. * @@ -64,7 +67,9 @@ createOrUpdateAPolicyDefinition().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinitionAdvancedParams.json */ async function createOrUpdateAPolicyDefinitionWithAdvancedParameters() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyDefinitionName = "EventHubDiagnosticLogs"; const parameters: PolicyDefinition = { description: @@ -116,4 +121,9 @@ async function createOrUpdateAPolicyDefinitionWithAdvancedParameters() { console.log(result); } -createOrUpdateAPolicyDefinitionWithAdvancedParameters().catch(console.error); +async function main() { + createOrUpdateAPolicyDefinition(); + createOrUpdateAPolicyDefinitionWithAdvancedParameters(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyDefinitionsDeleteAtManagementGroupSample.ts b/sdk/policy/arm-policy/samples-dev/policyDefinitionsDeleteAtManagementGroupSample.ts index f21e0b672e3c..a558918f0922 100644 --- a/sdk/policy/arm-policy/samples-dev/policyDefinitionsDeleteAtManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyDefinitionsDeleteAtManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation deletes the policy definition in the given management group with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyDefinitionAtManagementGroup.json */ async function deleteAPolicyDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyDefinitionName = "ResourceNaming"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); @@ -30,4 +35,8 @@ async function deleteAPolicyDefinitionAtManagementGroupLevel() { console.log(result); } -deleteAPolicyDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + deleteAPolicyDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyDefinitionsDeleteSample.ts b/sdk/policy/arm-policy/samples-dev/policyDefinitionsDeleteSample.ts index ba4d5422c2ae..4e9a36a37d78 100644 --- a/sdk/policy/arm-policy/samples-dev/policyDefinitionsDeleteSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyDefinitionsDeleteSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation deletes the policy definition in the given subscription with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyDefinition.json */ async function deleteAPolicyDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyDefinitionName = "ResourceNaming"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +31,8 @@ async function deleteAPolicyDefinition() { console.log(result); } -deleteAPolicyDefinition().catch(console.error); +async function main() { + deleteAPolicyDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyDefinitionsGetAtManagementGroupSample.ts b/sdk/policy/arm-policy/samples-dev/policyDefinitionsGetAtManagementGroupSample.ts index 27fcab9e3087..eb82f1274580 100644 --- a/sdk/policy/arm-policy/samples-dev/policyDefinitionsGetAtManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyDefinitionsGetAtManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the policy definition in the given management group with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyDefinitionAtManagementGroup.json */ async function retrieveAPolicyDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyDefinitionName = "ResourceNaming"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); @@ -30,4 +35,8 @@ async function retrieveAPolicyDefinitionAtManagementGroupLevel() { console.log(result); } -retrieveAPolicyDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + retrieveAPolicyDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyDefinitionsGetBuiltInSample.ts b/sdk/policy/arm-policy/samples-dev/policyDefinitionsGetBuiltInSample.ts index f719a34a23bf..e9bd89dee326 100644 --- a/sdk/policy/arm-policy/samples-dev/policyDefinitionsGetBuiltInSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyDefinitionsGetBuiltInSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the built-in policy definition with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getBuiltinPolicyDefinition.json */ async function retrieveABuiltInPolicyDefinition() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyDefinitionName = "7433c107-6db4-4ad1-b57a-a76dce0154a1"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -28,4 +33,8 @@ async function retrieveABuiltInPolicyDefinition() { console.log(result); } -retrieveABuiltInPolicyDefinition().catch(console.error); +async function main() { + retrieveABuiltInPolicyDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyDefinitionsGetSample.ts b/sdk/policy/arm-policy/samples-dev/policyDefinitionsGetSample.ts index ce61f8060856..db3faf195693 100644 --- a/sdk/policy/arm-policy/samples-dev/policyDefinitionsGetSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyDefinitionsGetSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the policy definition in the given subscription with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyDefinition.json */ async function retrieveAPolicyDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyDefinitionName = "ResourceNaming"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +31,8 @@ async function retrieveAPolicyDefinition() { console.log(result); } -retrieveAPolicyDefinition().catch(console.error); +async function main() { + retrieveAPolicyDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyDefinitionsListBuiltInSample.ts b/sdk/policy/arm-policy/samples-dev/policyDefinitionsListBuiltInSample.ts index b565261b76cf..255a1d66f5ce 100644 --- a/sdk/policy/arm-policy/samples-dev/policyDefinitionsListBuiltInSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyDefinitionsListBuiltInSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a list of all the built-in policy definitions that match the optional given $filter. If $filter='policyType -eq {value}' is provided, the returned list only includes all built-in policy definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all built-in policy definitions whose category match the {value}. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listBuiltInPolicyDefinitions.json */ async function listBuiltInPolicyDefinitions() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -28,4 +33,8 @@ async function listBuiltInPolicyDefinitions() { console.log(resArray); } -listBuiltInPolicyDefinitions().catch(console.error); +async function main() { + listBuiltInPolicyDefinitions(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyDefinitionsListByManagementGroupSample.ts b/sdk/policy/arm-policy/samples-dev/policyDefinitionsListByManagementGroupSample.ts index 0d588d20df2b..4d2b83fb6c4c 100644 --- a/sdk/policy/arm-policy/samples-dev/policyDefinitionsListByManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyDefinitionsListByManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a list of all the policy definitions in a given management group that match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list includes all policy definitions associated with the management group, including those that apply directly or from management groups that contain the given management group. If $filter=atExactScope() is provided, the returned list only includes all policy definitions that at the given management group. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all policy definitions whose category match the {value}. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyDefinitionsByManagementGroup.json */ async function listPolicyDefinitionsByManagementGroup() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -31,4 +36,8 @@ async function listPolicyDefinitionsByManagementGroup() { console.log(resArray); } -listPolicyDefinitionsByManagementGroup().catch(console.error); +async function main() { + listPolicyDefinitionsByManagementGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyDefinitionsListSample.ts b/sdk/policy/arm-policy/samples-dev/policyDefinitionsListSample.ts index b98016d43e38..5909902eb1f6 100644 --- a/sdk/policy/arm-policy/samples-dev/policyDefinitionsListSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyDefinitionsListSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a list of all the policy definitions in a given subscription that match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list includes all policy definitions associated with the subscription, including those that apply directly or from management groups that contain the given subscription. If $filter=atExactScope() is provided, the returned list only includes all policy definitions that at the given subscription. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all policy definitions whose category match the {value}. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyDefinitions.json */ async function listPolicyDefinitionsBySubscription() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -28,4 +33,8 @@ async function listPolicyDefinitionsBySubscription() { console.log(resArray); } -listPolicyDefinitionsBySubscription().catch(console.error); +async function main() { + listPolicyDefinitionsBySubscription(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyExemptionsCreateOrUpdateSample.ts b/sdk/policy/arm-policy/samples-dev/policyExemptionsCreateOrUpdateSample.ts index d8baa98d0f63..fdf6492281f5 100644 --- a/sdk/policy/arm-policy/samples-dev/policyExemptionsCreateOrUpdateSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyExemptionsCreateOrUpdateSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyExemption, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation creates or updates a policy exemption with the given scope and name. Policy exemptions apply to all resources contained within their scope. For example, when you create a policy exemption at resource group scope for a policy assignment at the same or above level, the exemption exempts to all applicable resources in the resource group. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/createOrUpdatePolicyExemption.json */ async function createOrUpdateAPolicyExemption() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/demoCluster"; const policyExemptionName = "DemoExpensiveVM"; @@ -41,4 +46,8 @@ async function createOrUpdateAPolicyExemption() { console.log(result); } -createOrUpdateAPolicyExemption().catch(console.error); +async function main() { + createOrUpdateAPolicyExemption(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyExemptionsDeleteSample.ts b/sdk/policy/arm-policy/samples-dev/policyExemptionsDeleteSample.ts index 333235e2aff4..602f7ab210e6 100644 --- a/sdk/policy/arm-policy/samples-dev/policyExemptionsDeleteSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyExemptionsDeleteSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation deletes a policy exemption, given its name and the scope it was created in. The scope of a policy exemption is the part of its ID preceding '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/deletePolicyExemption.json */ async function deleteAPolicyExemption() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/demoCluster"; const policyExemptionName = "DemoExpensiveVM"; @@ -31,4 +36,8 @@ async function deleteAPolicyExemption() { console.log(result); } -deleteAPolicyExemption().catch(console.error); +async function main() { + deleteAPolicyExemption(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyExemptionsGetSample.ts b/sdk/policy/arm-policy/samples-dev/policyExemptionsGetSample.ts index 04416e7965c0..22bf6dc2ece5 100644 --- a/sdk/policy/arm-policy/samples-dev/policyExemptionsGetSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyExemptionsGetSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a single policy exemption, given its name and the scope it was created at. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/getPolicyExemption.json */ async function retrieveAPolicyExemption() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/demoCluster"; const policyExemptionName = "DemoExpensiveVM"; @@ -28,4 +33,8 @@ async function retrieveAPolicyExemption() { console.log(result); } -retrieveAPolicyExemption().catch(console.error); +async function main() { + retrieveAPolicyExemption(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyExemptionsListForManagementGroupSample.ts b/sdk/policy/arm-policy/samples-dev/policyExemptionsListForManagementGroupSample.ts index 7efc527ef9a4..ce67bd91fa66 100644 --- a/sdk/policy/arm-policy/samples-dev/policyExemptionsListForManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyExemptionsListForManagementGroupSample.ts @@ -13,6 +13,9 @@ import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy exemptions applicable to the management group that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter=atScope() is provided, the returned list includes all policy exemptions that are assigned to the management group or the management group's ancestors. @@ -21,7 +24,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForManagementGroup.json */ async function listPolicyExemptionsThatApplyToAManagementGroup() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const managementGroupId = "DevOrg"; const filter = "atScope()"; const options: PolicyExemptionsListForManagementGroupOptionalParams = { @@ -39,4 +44,8 @@ async function listPolicyExemptionsThatApplyToAManagementGroup() { console.log(resArray); } -listPolicyExemptionsThatApplyToAManagementGroup().catch(console.error); +async function main() { + listPolicyExemptionsThatApplyToAManagementGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyExemptionsListForResourceGroupSample.ts b/sdk/policy/arm-policy/samples-dev/policyExemptionsListForResourceGroupSample.ts index 71b11bd79266..89d134c5d28c 100644 --- a/sdk/policy/arm-policy/samples-dev/policyExemptionsListForResourceGroupSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyExemptionsListForResourceGroupSample.ts @@ -13,6 +13,9 @@ import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy exemptions associated with the given resource group in the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy exemptions associated with the resource group, including those that apply directly or apply from containing scopes, as well as any applied to resources contained within the resource group. @@ -21,8 +24,11 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForResourceGroup.json */ async function listPolicyExemptionsThatApplyToAResourceGroup() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; - const resourceGroupName = "TestResourceGroup"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const resourceGroupName = + process.env["POLICY_RESOURCE_GROUP"] || "TestResourceGroup"; const filter = "atScope()"; const options: PolicyExemptionsListForResourceGroupOptionalParams = { filter @@ -39,4 +45,8 @@ async function listPolicyExemptionsThatApplyToAResourceGroup() { console.log(resArray); } -listPolicyExemptionsThatApplyToAResourceGroup().catch(console.error); +async function main() { + listPolicyExemptionsThatApplyToAResourceGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyExemptionsListForResourceSample.ts b/sdk/policy/arm-policy/samples-dev/policyExemptionsListForResourceSample.ts index d244bccee220..d8b18e3d975f 100644 --- a/sdk/policy/arm-policy/samples-dev/policyExemptionsListForResourceSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyExemptionsListForResourceSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy exemptions associated with the specified resource in the given resource group and subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy exemptions associated with the resource, including those that apply directly or from all containing scopes, as well as any applied to resources contained within the resource. Three parameters plus the resource name are used to identify a specific resource. If the resource is not part of a parent resource (the more common case), the parent resource path should not be provided (or provided as ''). For example a web app could be specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all parameters should be provided. For example a virtual machine DNS name could be specified as ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == 'MyComputerName'). A convenient alternative to providing the namespace and type name separately is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp'). @@ -18,8 +21,11 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForResource.json */ async function listAllPolicyExemptionsThatApplyToAResource() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; - const resourceGroupName = "TestResourceGroup"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const resourceGroupName = + process.env["POLICY_RESOURCE_GROUP"] || "TestResourceGroup"; const resourceProviderNamespace = "Microsoft.Compute"; const parentResourcePath = "virtualMachines/MyTestVm"; const resourceType = "domainNames"; @@ -39,4 +45,8 @@ async function listAllPolicyExemptionsThatApplyToAResource() { console.log(resArray); } -listAllPolicyExemptionsThatApplyToAResource().catch(console.error); +async function main() { + listAllPolicyExemptionsThatApplyToAResource(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policyExemptionsListSample.ts b/sdk/policy/arm-policy/samples-dev/policyExemptionsListSample.ts index 60c1219dbbf3..26024134450b 100644 --- a/sdk/policy/arm-policy/samples-dev/policyExemptionsListSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policyExemptionsListSample.ts @@ -13,6 +13,9 @@ import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy exemptions associated with the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy exemptions associated with the subscription, including those that apply directly or from management groups that contain the given subscription, as well as any applied to objects contained within the subscription. @@ -21,7 +24,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForSubscription.json */ async function listPolicyExemptionsThatApplyToASubscription() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const filter = "atScope()"; const options: PolicyExemptionsListOptionalParams = { filter }; const credential = new DefaultAzureCredential(); @@ -33,4 +38,8 @@ async function listPolicyExemptionsThatApplyToASubscription() { console.log(resArray); } -listPolicyExemptionsThatApplyToASubscription().catch(console.error); +async function main() { + listPolicyExemptionsThatApplyToASubscription(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsCreateOrUpdateAtManagementGroupSample.ts b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsCreateOrUpdateAtManagementGroupSample.ts index e0d324f27db8..c8d68032ae6a 100644 --- a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsCreateOrUpdateAtManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsCreateOrUpdateAtManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicySetDefinition, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation creates or updates a policy set definition in the given management group with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionAtManagementGroup.json */ async function createOrUpdateAPolicySetDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "CostManagement"; const managementGroupId = "MyManagementGroup"; const parameters: PolicySetDefinition = { @@ -52,8 +57,6 @@ async function createOrUpdateAPolicySetDefinitionAtManagementGroupLevel() { console.log(result); } -createOrUpdateAPolicySetDefinitionAtManagementGroupLevel().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy set definition in the given management group with the given name. * @@ -61,7 +64,9 @@ createOrUpdateAPolicySetDefinitionAtManagementGroupLevel().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionWithGroupsAtManagementGroup.json */ async function createOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "CostManagement"; const managementGroupId = "MyManagementGroup"; const parameters: PolicySetDefinition = { @@ -111,6 +116,9 @@ async function createOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLeve console.log(result); } -createOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLevel().catch( - console.error -); +async function main() { + createOrUpdateAPolicySetDefinitionAtManagementGroupLevel(); + createOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsCreateOrUpdateSample.ts b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsCreateOrUpdateSample.ts index 8b66d516f5f0..cd07a37043c9 100644 --- a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsCreateOrUpdateSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsCreateOrUpdateSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicySetDefinition, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation creates or updates a policy set definition in the given subscription with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinition.json */ async function createOrUpdateAPolicySetDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policySetDefinitionName = "CostManagement"; const parameters: PolicySetDefinition = { description: "Policies to enforce low cost storage SKUs", @@ -60,8 +65,6 @@ async function createOrUpdateAPolicySetDefinition() { console.log(result); } -createOrUpdateAPolicySetDefinition().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy set definition in the given subscription with the given name. * @@ -69,7 +72,9 @@ createOrUpdateAPolicySetDefinition().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionWithGroups.json */ async function createOrUpdateAPolicySetDefinitionWithGroups() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policySetDefinitionName = "CostManagement"; const parameters: PolicySetDefinition = { description: "Policies to enforce low cost storage SKUs", @@ -117,4 +122,9 @@ async function createOrUpdateAPolicySetDefinitionWithGroups() { console.log(result); } -createOrUpdateAPolicySetDefinitionWithGroups().catch(console.error); +async function main() { + createOrUpdateAPolicySetDefinition(); + createOrUpdateAPolicySetDefinitionWithGroups(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsDeleteAtManagementGroupSample.ts b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsDeleteAtManagementGroupSample.ts index 049650909401..2b663525150f 100644 --- a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsDeleteAtManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsDeleteAtManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation deletes the policy set definition in the given management group with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicySetDefinitionAtManagementGroup.json */ async function deleteAPolicySetDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "CostManagement"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); @@ -30,4 +35,8 @@ async function deleteAPolicySetDefinitionAtManagementGroupLevel() { console.log(result); } -deleteAPolicySetDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + deleteAPolicySetDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsDeleteSample.ts b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsDeleteSample.ts index f677be46c467..fc3397aad46b 100644 --- a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsDeleteSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsDeleteSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation deletes the policy set definition in the given subscription with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicySetDefinition.json */ async function deleteAPolicySetDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policySetDefinitionName = "CostManagement"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -28,4 +33,8 @@ async function deleteAPolicySetDefinition() { console.log(result); } -deleteAPolicySetDefinition().catch(console.error); +async function main() { + deleteAPolicySetDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsGetAtManagementGroupSample.ts b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsGetAtManagementGroupSample.ts index 5bc3ae6bc005..bcc684972eb2 100644 --- a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsGetAtManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsGetAtManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the policy set definition in the given management group with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicySetDefinitionAtManagementGroup.json */ async function retrieveAPolicySetDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "CostManagement"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); @@ -30,4 +35,8 @@ async function retrieveAPolicySetDefinitionAtManagementGroupLevel() { console.log(result); } -retrieveAPolicySetDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + retrieveAPolicySetDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsGetBuiltInSample.ts b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsGetBuiltInSample.ts index eaa2ab035acc..abe463354e29 100644 --- a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsGetBuiltInSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsGetBuiltInSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the built-in policy set definition with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getBuiltInPolicySetDefinition.json */ async function retrieveABuiltInPolicySetDefinition() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "1f3afdf9-d0c9-4c3d-847f-89da613e70a8"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -28,4 +33,8 @@ async function retrieveABuiltInPolicySetDefinition() { console.log(result); } -retrieveABuiltInPolicySetDefinition().catch(console.error); +async function main() { + retrieveABuiltInPolicySetDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsGetSample.ts b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsGetSample.ts index f157eb34c168..8792a7c33808 100644 --- a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsGetSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsGetSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the policy set definition in the given subscription with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicySetDefinition.json */ async function retrieveAPolicySetDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policySetDefinitionName = "CostManagement"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +31,8 @@ async function retrieveAPolicySetDefinition() { console.log(result); } -retrieveAPolicySetDefinition().catch(console.error); +async function main() { + retrieveAPolicySetDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsListBuiltInSample.ts b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsListBuiltInSample.ts index 39c0fa42c3b7..c68958d14812 100644 --- a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsListBuiltInSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsListBuiltInSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a list of all the built-in policy set definitions that match the optional given $filter. If $filter='category -eq {value}' is provided, the returned list only includes all built-in policy set definitions whose category match the {value}. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listBuiltInPolicySetDefinitions.json */ async function listBuiltInPolicySetDefinitions() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -28,4 +33,8 @@ async function listBuiltInPolicySetDefinitions() { console.log(resArray); } -listBuiltInPolicySetDefinitions().catch(console.error); +async function main() { + listBuiltInPolicySetDefinitions(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsListByManagementGroupSample.ts b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsListByManagementGroupSample.ts index 7ad9f07b3d79..abd743e737f7 100644 --- a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsListByManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsListByManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a list of all the policy set definitions in a given management group that match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list includes all policy set definitions associated with the management group, including those that apply directly or from management groups that contain the given management group. If $filter=atExactScope() is provided, the returned list only includes all policy set definitions that at the given management group. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy set definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn and Custom. If $filter='category -eq {value}' is provided, the returned list only includes all policy set definitions whose category match the {value}. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicySetDefinitionsByManagementGroup.json */ async function listPolicySetDefinitionsAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -31,4 +36,8 @@ async function listPolicySetDefinitionsAtManagementGroupLevel() { console.log(resArray); } -listPolicySetDefinitionsAtManagementGroupLevel().catch(console.error); +async function main() { + listPolicySetDefinitionsAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsListSample.ts b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsListSample.ts index 9f7ffe53961a..feb9603a2d2d 100644 --- a/sdk/policy/arm-policy/samples-dev/policySetDefinitionsListSample.ts +++ b/sdk/policy/arm-policy/samples-dev/policySetDefinitionsListSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a list of all the policy set definitions in a given subscription that match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list includes all policy set definitions associated with the subscription, including those that apply directly or from management groups that contain the given subscription. If $filter=atExactScope() is provided, the returned list only includes all policy set definitions that at the given subscription. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy set definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn and Custom. If $filter='category -eq {value}' is provided, the returned list only includes all policy set definitions whose category match the {value}. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicySetDefinitions.json */ async function listPolicySetDefinitions() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -28,4 +33,8 @@ async function listPolicySetDefinitions() { console.log(resArray); } -listPolicySetDefinitions().catch(console.error); +async function main() { + listPolicySetDefinitions(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/README.md b/sdk/policy/arm-policy/samples/v5/javascript/README.md index 8e03a92851b4..b3a504eb6261 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/README.md +++ b/sdk/policy/arm-policy/samples/v5/javascript/README.md @@ -77,7 +77,7 @@ node dataPolicyManifestsGetByPolicyModeSample.js Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform): ```bash -npx cross-env node dataPolicyManifestsGetByPolicyModeSample.js +npx cross-env POLICY_SUBSCRIPTION_ID="" node dataPolicyManifestsGetByPolicyModeSample.js ``` ## Next Steps diff --git a/sdk/policy/arm-policy/samples/v5/javascript/dataPolicyManifestsGetByPolicyModeSample.js b/sdk/policy/arm-policy/samples/v5/javascript/dataPolicyManifestsGetByPolicyModeSample.js index e434bd96f694..b5c8a8929477 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/dataPolicyManifestsGetByPolicyModeSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/dataPolicyManifestsGetByPolicyModeSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the data policy manifest with the given policy mode. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/getDataPolicyManifest.json */ async function retrieveADataPolicyManifestByPolicyMode() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policyMode = "Microsoft.KeyVault.Data"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +28,8 @@ async function retrieveADataPolicyManifestByPolicyMode() { console.log(result); } -retrieveADataPolicyManifestByPolicyMode().catch(console.error); +async function main() { + retrieveADataPolicyManifestByPolicyMode(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/dataPolicyManifestsListSample.js b/sdk/policy/arm-policy/samples/v5/javascript/dataPolicyManifestsListSample.js index ead1d7d79fa9..d2e1546002ba 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/dataPolicyManifestsListSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/dataPolicyManifestsListSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves a list of all the data policy manifests that match the optional given $filter. Valid values for $filter are: "$filter=namespace eq '{0}'". If $filter is not provided, the unfiltered list includes all data policy manifests for data resource types. If $filter=namespace is provided, the returned list only includes all data policy manifests that have a namespace matching the provided value. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/listDataPolicyManifests.json */ async function listDataPolicyManifests() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -28,8 +30,6 @@ async function listDataPolicyManifests() { console.log(resArray); } -listDataPolicyManifests().catch(console.error); - /** * This sample demonstrates how to This operation retrieves a list of all the data policy manifests that match the optional given $filter. Valid values for $filter are: "$filter=namespace eq '{0}'". If $filter is not provided, the unfiltered list includes all data policy manifests for data resource types. If $filter=namespace is provided, the returned list only includes all data policy manifests that have a namespace matching the provided value. * @@ -37,7 +37,8 @@ listDataPolicyManifests().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/listDataPolicyManifestsNamespaceFilter.json */ async function listDataPolicyManifestsWithNamespaceFilter() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const filter = "namespace eq 'Microsoft.KeyVault'"; const options = { filter }; const credential = new DefaultAzureCredential(); @@ -49,4 +50,9 @@ async function listDataPolicyManifestsWithNamespaceFilter() { console.log(resArray); } -listDataPolicyManifestsWithNamespaceFilter().catch(console.error); +async function main() { + listDataPolicyManifests(); + listDataPolicyManifestsWithNamespaceFilter(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsCreateByIdSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsCreateByIdSample.js index 628884071a17..be26dba95f4e 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsCreateByIdSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsCreateByIdSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation creates or updates the policy assignment with the given ID. Policy assignments made on a scope apply to all resources contained in that scope. For example, when you assign a policy to a resource group that policy applies to all resources in the group. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentById.json */ async function createOrUpdatePolicyAssignmentById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const parameters = { @@ -38,8 +40,6 @@ async function createOrUpdatePolicyAssignmentById() { console.log(result); } -createOrUpdatePolicyAssignmentById().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates the policy assignment with the given ID. Policy assignments made on a scope apply to all resources contained in that scope. For example, when you assign a policy to a resource group that policy applies to all resources in the group. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. * @@ -47,7 +47,8 @@ createOrUpdatePolicyAssignmentById().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithIdentityById.json */ async function createOrUpdatePolicyAssignmentWithAManagedIdentityById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const parameters = { @@ -69,4 +70,9 @@ async function createOrUpdatePolicyAssignmentWithAManagedIdentityById() { console.log(result); } -createOrUpdatePolicyAssignmentWithAManagedIdentityById().catch(console.error); +async function main() { + createOrUpdatePolicyAssignmentById(); + createOrUpdatePolicyAssignmentWithAManagedIdentityById(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsCreateSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsCreateSample.js index b2ee6242e0b1..42bbac979ce0 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsCreateSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsCreateSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignment.json */ async function createOrUpdateAPolicyAssignment() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters = { @@ -38,8 +40,6 @@ async function createOrUpdateAPolicyAssignment() { console.log(result); } -createOrUpdateAPolicyAssignment().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -47,7 +47,8 @@ createOrUpdateAPolicyAssignment().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithIdentity.json */ async function createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters = { @@ -67,8 +68,6 @@ async function createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity() { console.log(result); } -createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -76,7 +75,8 @@ createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity().catch(console.error * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithUserAssignedIdentity.json */ async function createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters = { @@ -102,8 +102,6 @@ async function createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity() { console.log(result); } -createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -111,7 +109,8 @@ createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentNonComplianceMessages.json */ async function createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "securityInitAssignment"; const parameters = { @@ -139,8 +138,6 @@ async function createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages( console.log(result); } -createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -148,7 +145,8 @@ createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages().catch(console * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithoutEnforcement.json */ async function createOrUpdateAPolicyAssignmentWithoutEnforcingPolicyEffectDuringResourceCreationOrUpdate() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters = { @@ -166,6 +164,12 @@ async function createOrUpdateAPolicyAssignmentWithoutEnforcingPolicyEffectDuring console.log(result); } -createOrUpdateAPolicyAssignmentWithoutEnforcingPolicyEffectDuringResourceCreationOrUpdate().catch( - console.error -); +async function main() { + createOrUpdateAPolicyAssignment(); + createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity(); + createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity(); + createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages(); + createOrUpdateAPolicyAssignmentWithoutEnforcingPolicyEffectDuringResourceCreationOrUpdate(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsDeleteByIdSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsDeleteByIdSample.js index 28bd13e3bf6a..629c33e4ba66 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsDeleteByIdSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsDeleteByIdSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation deletes the policy with the given ID. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid formats for {scope} are: '/providers/Microsoft.Management/managementGroups/{managementGroup}' (management group), '/subscriptions/{subscriptionId}' (subscription), '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' (resource group), or '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}' (resource). @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyAssignmentById.json */ async function deleteAPolicyAssignmentById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const credential = new DefaultAzureCredential(); @@ -27,4 +29,8 @@ async function deleteAPolicyAssignmentById() { console.log(result); } -deleteAPolicyAssignmentById().catch(console.error); +async function main() { + deleteAPolicyAssignmentById(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsDeleteSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsDeleteSample.js index 9f955d4ff856..77e24d88252f 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsDeleteSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsDeleteSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation deletes a policy assignment, given its name and the scope it was created in. The scope of a policy assignment is the part of its ID preceding '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyAssignment.json */ async function deleteAPolicyAssignment() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const credential = new DefaultAzureCredential(); @@ -27,4 +29,8 @@ async function deleteAPolicyAssignment() { console.log(result); } -deleteAPolicyAssignment().catch(console.error); +async function main() { + deleteAPolicyAssignment(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsGetByIdSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsGetByIdSample.js index 23eb9d549953..990907f48a00 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsGetByIdSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsGetByIdSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to The operation retrieves the policy assignment with the given ID. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentById.json */ async function retrieveAPolicyAssignmentById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const credential = new DefaultAzureCredential(); @@ -27,8 +29,6 @@ async function retrieveAPolicyAssignmentById() { console.log(result); } -retrieveAPolicyAssignmentById().catch(console.error); - /** * This sample demonstrates how to The operation retrieves the policy assignment with the given ID. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. * @@ -36,7 +36,8 @@ retrieveAPolicyAssignmentById().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentWithIdentityById.json */ async function retrieveAPolicyAssignmentWithAManagedIdentityById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const credential = new DefaultAzureCredential(); @@ -45,4 +46,9 @@ async function retrieveAPolicyAssignmentWithAManagedIdentityById() { console.log(result); } -retrieveAPolicyAssignmentWithAManagedIdentityById().catch(console.error); +async function main() { + retrieveAPolicyAssignmentById(); + retrieveAPolicyAssignmentWithAManagedIdentityById(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsGetSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsGetSample.js index b0667ec71e34..d5bdb8a7839e 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsGetSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsGetSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves a single policy assignment, given its name and the scope it was created at. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignment.json */ async function retrieveAPolicyAssignment() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const credential = new DefaultAzureCredential(); @@ -27,8 +29,6 @@ async function retrieveAPolicyAssignment() { console.log(result); } -retrieveAPolicyAssignment().catch(console.error); - /** * This sample demonstrates how to This operation retrieves a single policy assignment, given its name and the scope it was created at. * @@ -36,7 +36,8 @@ retrieveAPolicyAssignment().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentWithIdentity.json */ async function retrieveAPolicyAssignmentWithASystemAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const credential = new DefaultAzureCredential(); @@ -45,8 +46,6 @@ async function retrieveAPolicyAssignmentWithASystemAssignedIdentity() { console.log(result); } -retrieveAPolicyAssignmentWithASystemAssignedIdentity().catch(console.error); - /** * This sample demonstrates how to This operation retrieves a single policy assignment, given its name and the scope it was created at. * @@ -54,7 +53,8 @@ retrieveAPolicyAssignmentWithASystemAssignedIdentity().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentWithUserAssignedIdentity.json */ async function retrieveAPolicyAssignmentWithAUserAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const credential = new DefaultAzureCredential(); @@ -63,4 +63,10 @@ async function retrieveAPolicyAssignmentWithAUserAssignedIdentity() { console.log(result); } -retrieveAPolicyAssignmentWithAUserAssignedIdentity().catch(console.error); +async function main() { + retrieveAPolicyAssignment(); + retrieveAPolicyAssignmentWithASystemAssignedIdentity(); + retrieveAPolicyAssignmentWithAUserAssignedIdentity(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListForManagementGroupSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListForManagementGroupSample.js index 16744fdc4d72..b5f5fec32cf0 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListForManagementGroupSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListForManagementGroupSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the list of all policy assignments applicable to the management group that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter=atScope() is provided, the returned list includes all policy assignments that are assigned to the management group or the management group's ancestors. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the management group. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value} that apply to the management group. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignmentsForManagementGroup.json */ async function listPolicyAssignmentsThatApplyToAManagementGroup() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const managementGroupId = "TestManagementGroup"; const filter = "atScope()"; const options = { @@ -36,4 +38,8 @@ async function listPolicyAssignmentsThatApplyToAManagementGroup() { console.log(resArray); } -listPolicyAssignmentsThatApplyToAManagementGroup().catch(console.error); +async function main() { + listPolicyAssignmentsThatApplyToAManagementGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListForResourceGroupSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListForResourceGroupSample.js index c699aea3df68..20d87b4a986e 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListForResourceGroupSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListForResourceGroupSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the list of all policy assignments associated with the given resource group in the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments associated with the resource group, including those that apply directly or apply from containing scopes, as well as any applied to resources contained within the resource group. If $filter=atScope() is provided, the returned list includes all policy assignments that apply to the resource group, which is everything in the unfiltered list except those applied to resources contained within the resource group. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the resource group. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value} that apply to the resource group. @@ -18,8 +19,9 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignmentsForResourceGroup.json */ async function listPolicyAssignmentsThatApplyToAResourceGroup() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; - const resourceGroupName = "TestResourceGroup"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const resourceGroupName = process.env["POLICY_RESOURCE_GROUP"] || "TestResourceGroup"; const filter = "atScope()"; const options = { filter, @@ -36,4 +38,8 @@ async function listPolicyAssignmentsThatApplyToAResourceGroup() { console.log(resArray); } -listPolicyAssignmentsThatApplyToAResourceGroup().catch(console.error); +async function main() { + listPolicyAssignmentsThatApplyToAResourceGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListForResourceSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListForResourceSample.js index 8311c9d34011..da266a317f5d 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListForResourceSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListForResourceSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the list of all policy assignments associated with the specified resource in the given resource group and subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments associated with the resource, including those that apply directly or from all containing scopes, as well as any applied to resources contained within the resource. If $filter=atScope() is provided, the returned list includes all policy assignments that apply to the resource, which is everything in the unfiltered list except those applied to resources contained within the resource. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the resource level. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value} that apply to the resource. Three parameters plus the resource name are used to identify a specific resource. If the resource is not part of a parent resource (the more common case), the parent resource path should not be provided (or provided as ''). For example a web app could be specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all parameters should be provided. For example a virtual machine DNS name could be specified as ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == 'MyComputerName'). A convenient alternative to providing the namespace and type name separately is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp'). @@ -18,8 +19,9 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignmentsForResource.json */ async function listAllPolicyAssignmentsThatApplyToAResource() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; - const resourceGroupName = "TestResourceGroup"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const resourceGroupName = process.env["POLICY_RESOURCE_GROUP"] || "TestResourceGroup"; const resourceProviderNamespace = "Microsoft.Compute"; const parentResourcePath = "virtualMachines/MyTestVm"; const resourceType = "domainNames"; @@ -39,4 +41,8 @@ async function listAllPolicyAssignmentsThatApplyToAResource() { console.log(resArray); } -listAllPolicyAssignmentsThatApplyToAResource().catch(console.error); +async function main() { + listAllPolicyAssignmentsThatApplyToAResource(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListSample.js index 01b74d637f23..ec1a5a2ea07e 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsListSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the list of all policy assignments associated with the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments associated with the subscription, including those that apply directly or from management groups that contain the given subscription, as well as any applied to objects contained within the subscription. If $filter=atScope() is provided, the returned list includes all policy assignments that apply to the subscription, which is everything in the unfiltered list except those applied to objects contained within the subscription. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the subscription. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value}. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignments.json */ async function listPolicyAssignmentsThatApplyToASubscription() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const filter = "atScope()"; const options = { filter }; const credential = new DefaultAzureCredential(); @@ -30,4 +32,8 @@ async function listPolicyAssignmentsThatApplyToASubscription() { console.log(resArray); } -listPolicyAssignmentsThatApplyToASubscription().catch(console.error); +async function main() { + listPolicyAssignmentsThatApplyToASubscription(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsUpdateByIdSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsUpdateByIdSample.js index 86078b842424..e2bd8a9b89cf 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsUpdateByIdSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsUpdateByIdSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation updates the policy assignment with the given ID. Policy assignments made on a scope apply to all resources contained in that scope. For example, when you assign a policy to a resource group that policy applies to all resources in the group. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/updatePolicyAssignmentWithIdentityById.json */ async function updatePolicyAssignmentWithAManagedIdentityById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const parameters = { @@ -31,4 +33,8 @@ async function updatePolicyAssignmentWithAManagedIdentityById() { console.log(result); } -updatePolicyAssignmentWithAManagedIdentityById().catch(console.error); +async function main() { + updatePolicyAssignmentWithAManagedIdentityById(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsUpdateSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsUpdateSample.js index 8465244f6d08..de1cf4fc6f65 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsUpdateSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyAssignmentsUpdateSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/updatePolicyAssignmentWithIdentity.json */ async function updateAPolicyAssignmentWithASystemAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters = { @@ -31,8 +33,6 @@ async function updateAPolicyAssignmentWithASystemAssignedIdentity() { console.log(result); } -updateAPolicyAssignmentWithASystemAssignedIdentity().catch(console.error); - /** * This sample demonstrates how to This operation updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -40,7 +40,8 @@ updateAPolicyAssignmentWithASystemAssignedIdentity().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/updatePolicyAssignmentWithUserAssignedIdentity.json */ async function updateAPolicyAssignmentWithAUserAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters = { @@ -59,4 +60,9 @@ async function updateAPolicyAssignmentWithAUserAssignedIdentity() { console.log(result); } -updateAPolicyAssignmentWithAUserAssignedIdentity().catch(console.error); +async function main() { + updateAPolicyAssignmentWithASystemAssignedIdentity(); + updateAPolicyAssignmentWithAUserAssignedIdentity(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsCreateOrUpdateAtManagementGroupSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsCreateOrUpdateAtManagementGroupSample.js index 2204a61d30e1..d43809ef1e5a 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsCreateOrUpdateAtManagementGroupSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsCreateOrUpdateAtManagementGroupSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation creates or updates a policy definition in the given management group with the given name. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinitionAtManagementGroup.json */ async function createOrUpdateAPolicyDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policyDefinitionName = "ResourceNaming"; const managementGroupId = "MyManagementGroup"; const parameters = { @@ -56,4 +58,8 @@ async function createOrUpdateAPolicyDefinitionAtManagementGroupLevel() { console.log(result); } -createOrUpdateAPolicyDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + createOrUpdateAPolicyDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsCreateOrUpdateSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsCreateOrUpdateSample.js index 847afc4944d2..aeb23974b433 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsCreateOrUpdateSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsCreateOrUpdateSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation creates or updates a policy definition in the given subscription with the given name. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinition.json */ async function createOrUpdateAPolicyDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyDefinitionName = "ResourceNaming"; const parameters = { description: "Force resource names to begin with given 'prefix' and/or end with given 'suffix'", @@ -51,8 +53,6 @@ async function createOrUpdateAPolicyDefinition() { console.log(result); } -createOrUpdateAPolicyDefinition().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy definition in the given subscription with the given name. * @@ -60,7 +60,8 @@ createOrUpdateAPolicyDefinition().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinitionAdvancedParams.json */ async function createOrUpdateAPolicyDefinitionWithAdvancedParameters() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyDefinitionName = "EventHubDiagnosticLogs"; const parameters = { description: @@ -107,4 +108,9 @@ async function createOrUpdateAPolicyDefinitionWithAdvancedParameters() { console.log(result); } -createOrUpdateAPolicyDefinitionWithAdvancedParameters().catch(console.error); +async function main() { + createOrUpdateAPolicyDefinition(); + createOrUpdateAPolicyDefinitionWithAdvancedParameters(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsDeleteAtManagementGroupSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsDeleteAtManagementGroupSample.js index 6b847c0826f7..928b7a93ad5c 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsDeleteAtManagementGroupSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsDeleteAtManagementGroupSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation deletes the policy definition in the given management group with the given name. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyDefinitionAtManagementGroup.json */ async function deleteAPolicyDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policyDefinitionName = "ResourceNaming"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); @@ -30,4 +32,8 @@ async function deleteAPolicyDefinitionAtManagementGroupLevel() { console.log(result); } -deleteAPolicyDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + deleteAPolicyDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsDeleteSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsDeleteSample.js index e938da8a4b02..c53374fec062 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsDeleteSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsDeleteSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation deletes the policy definition in the given subscription with the given name. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyDefinition.json */ async function deleteAPolicyDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyDefinitionName = "ResourceNaming"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +28,8 @@ async function deleteAPolicyDefinition() { console.log(result); } -deleteAPolicyDefinition().catch(console.error); +async function main() { + deleteAPolicyDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsGetAtManagementGroupSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsGetAtManagementGroupSample.js index 2a3c6f40536f..c29743f7568d 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsGetAtManagementGroupSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsGetAtManagementGroupSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the policy definition in the given management group with the given name. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyDefinitionAtManagementGroup.json */ async function retrieveAPolicyDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policyDefinitionName = "ResourceNaming"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); @@ -30,4 +32,8 @@ async function retrieveAPolicyDefinitionAtManagementGroupLevel() { console.log(result); } -retrieveAPolicyDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + retrieveAPolicyDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsGetBuiltInSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsGetBuiltInSample.js index 49d4d57cc05a..2a82f83a4529 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsGetBuiltInSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsGetBuiltInSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the built-in policy definition with the given name. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getBuiltinPolicyDefinition.json */ async function retrieveABuiltInPolicyDefinition() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policyDefinitionName = "7433c107-6db4-4ad1-b57a-a76dce0154a1"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +28,8 @@ async function retrieveABuiltInPolicyDefinition() { console.log(result); } -retrieveABuiltInPolicyDefinition().catch(console.error); +async function main() { + retrieveABuiltInPolicyDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsGetSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsGetSample.js index 5b93fe00a2e4..de64f5d6c52b 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsGetSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsGetSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the policy definition in the given subscription with the given name. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyDefinition.json */ async function retrieveAPolicyDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyDefinitionName = "ResourceNaming"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +28,8 @@ async function retrieveAPolicyDefinition() { console.log(result); } -retrieveAPolicyDefinition().catch(console.error); +async function main() { + retrieveAPolicyDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsListBuiltInSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsListBuiltInSample.js index 5fed649ed8e0..ee911d1e1e71 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsListBuiltInSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsListBuiltInSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves a list of all the built-in policy definitions that match the optional given $filter. If $filter='policyType -eq {value}' is provided, the returned list only includes all built-in policy definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all built-in policy definitions whose category match the {value}. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listBuiltInPolicyDefinitions.json */ async function listBuiltInPolicyDefinitions() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -28,4 +30,8 @@ async function listBuiltInPolicyDefinitions() { console.log(resArray); } -listBuiltInPolicyDefinitions().catch(console.error); +async function main() { + listBuiltInPolicyDefinitions(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsListByManagementGroupSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsListByManagementGroupSample.js index 939dc7af0244..4e8171a3d29a 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsListByManagementGroupSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsListByManagementGroupSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves a list of all the policy definitions in a given management group that match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list includes all policy definitions associated with the management group, including those that apply directly or from management groups that contain the given management group. If $filter=atExactScope() is provided, the returned list only includes all policy definitions that at the given management group. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all policy definitions whose category match the {value}. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyDefinitionsByManagementGroup.json */ async function listPolicyDefinitionsByManagementGroup() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -29,4 +31,8 @@ async function listPolicyDefinitionsByManagementGroup() { console.log(resArray); } -listPolicyDefinitionsByManagementGroup().catch(console.error); +async function main() { + listPolicyDefinitionsByManagementGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsListSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsListSample.js index da8a8b0acad1..ad5a2bf91a3e 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsListSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyDefinitionsListSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves a list of all the policy definitions in a given subscription that match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list includes all policy definitions associated with the subscription, including those that apply directly or from management groups that contain the given subscription. If $filter=atExactScope() is provided, the returned list only includes all policy definitions that at the given subscription. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all policy definitions whose category match the {value}. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyDefinitions.json */ async function listPolicyDefinitionsBySubscription() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -28,4 +30,8 @@ async function listPolicyDefinitionsBySubscription() { console.log(resArray); } -listPolicyDefinitionsBySubscription().catch(console.error); +async function main() { + listPolicyDefinitionsBySubscription(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsCreateOrUpdateSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsCreateOrUpdateSample.js index 77a5b5871cf4..5ab7cc179d84 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsCreateOrUpdateSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsCreateOrUpdateSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation creates or updates a policy exemption with the given scope and name. Policy exemptions apply to all resources contained within their scope. For example, when you create a policy exemption at resource group scope for a policy assignment at the same or above level, the exemption exempts to all applicable resources in the resource group. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/createOrUpdatePolicyExemption.json */ async function createOrUpdateAPolicyExemption() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/demoCluster"; const policyExemptionName = "DemoExpensiveVM"; const parameters = { @@ -40,4 +42,8 @@ async function createOrUpdateAPolicyExemption() { console.log(result); } -createOrUpdateAPolicyExemption().catch(console.error); +async function main() { + createOrUpdateAPolicyExemption(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsDeleteSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsDeleteSample.js index ca947377201e..5b23186c0b41 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsDeleteSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsDeleteSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation deletes a policy exemption, given its name and the scope it was created in. The scope of a policy exemption is the part of its ID preceding '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/deletePolicyExemption.json */ async function deleteAPolicyExemption() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/demoCluster"; const policyExemptionName = "DemoExpensiveVM"; const credential = new DefaultAzureCredential(); @@ -27,4 +29,8 @@ async function deleteAPolicyExemption() { console.log(result); } -deleteAPolicyExemption().catch(console.error); +async function main() { + deleteAPolicyExemption(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsGetSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsGetSample.js index db8555d7bdcb..251fa7787e91 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsGetSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsGetSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves a single policy exemption, given its name and the scope it was created at. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/getPolicyExemption.json */ async function retrieveAPolicyExemption() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/demoCluster"; const policyExemptionName = "DemoExpensiveVM"; const credential = new DefaultAzureCredential(); @@ -27,4 +29,8 @@ async function retrieveAPolicyExemption() { console.log(result); } -retrieveAPolicyExemption().catch(console.error); +async function main() { + retrieveAPolicyExemption(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListForManagementGroupSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListForManagementGroupSample.js index 72b2cb070e56..a9f6bba5a777 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListForManagementGroupSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListForManagementGroupSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the list of all policy exemptions applicable to the management group that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter=atScope() is provided, the returned list includes all policy exemptions that are assigned to the management group or the management group's ancestors. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForManagementGroup.json */ async function listPolicyExemptionsThatApplyToAManagementGroup() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const managementGroupId = "DevOrg"; const filter = "atScope()"; const options = { @@ -36,4 +38,8 @@ async function listPolicyExemptionsThatApplyToAManagementGroup() { console.log(resArray); } -listPolicyExemptionsThatApplyToAManagementGroup().catch(console.error); +async function main() { + listPolicyExemptionsThatApplyToAManagementGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListForResourceGroupSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListForResourceGroupSample.js index b941162a00b2..6829322b14c8 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListForResourceGroupSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListForResourceGroupSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the list of all policy exemptions associated with the given resource group in the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy exemptions associated with the resource group, including those that apply directly or apply from containing scopes, as well as any applied to resources contained within the resource group. @@ -18,8 +19,9 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForResourceGroup.json */ async function listPolicyExemptionsThatApplyToAResourceGroup() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; - const resourceGroupName = "TestResourceGroup"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const resourceGroupName = process.env["POLICY_RESOURCE_GROUP"] || "TestResourceGroup"; const filter = "atScope()"; const options = { filter, @@ -33,4 +35,8 @@ async function listPolicyExemptionsThatApplyToAResourceGroup() { console.log(resArray); } -listPolicyExemptionsThatApplyToAResourceGroup().catch(console.error); +async function main() { + listPolicyExemptionsThatApplyToAResourceGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListForResourceSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListForResourceSample.js index d715078b25a9..a3be9a131fea 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListForResourceSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListForResourceSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the list of all policy exemptions associated with the specified resource in the given resource group and subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy exemptions associated with the resource, including those that apply directly or from all containing scopes, as well as any applied to resources contained within the resource. Three parameters plus the resource name are used to identify a specific resource. If the resource is not part of a parent resource (the more common case), the parent resource path should not be provided (or provided as ''). For example a web app could be specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all parameters should be provided. For example a virtual machine DNS name could be specified as ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == 'MyComputerName'). A convenient alternative to providing the namespace and type name separately is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp'). @@ -18,8 +19,9 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForResource.json */ async function listAllPolicyExemptionsThatApplyToAResource() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; - const resourceGroupName = "TestResourceGroup"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const resourceGroupName = process.env["POLICY_RESOURCE_GROUP"] || "TestResourceGroup"; const resourceProviderNamespace = "Microsoft.Compute"; const parentResourcePath = "virtualMachines/MyTestVm"; const resourceType = "domainNames"; @@ -39,4 +41,8 @@ async function listAllPolicyExemptionsThatApplyToAResource() { console.log(resArray); } -listAllPolicyExemptionsThatApplyToAResource().catch(console.error); +async function main() { + listAllPolicyExemptionsThatApplyToAResource(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListSample.js index f2e8c684c1aa..2a998e07e3c5 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policyExemptionsListSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the list of all policy exemptions associated with the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy exemptions associated with the subscription, including those that apply directly or from management groups that contain the given subscription, as well as any applied to objects contained within the subscription. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForSubscription.json */ async function listPolicyExemptionsThatApplyToASubscription() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const filter = "atScope()"; const options = { filter }; const credential = new DefaultAzureCredential(); @@ -30,4 +32,8 @@ async function listPolicyExemptionsThatApplyToASubscription() { console.log(resArray); } -listPolicyExemptionsThatApplyToASubscription().catch(console.error); +async function main() { + listPolicyExemptionsThatApplyToASubscription(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsCreateOrUpdateAtManagementGroupSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsCreateOrUpdateAtManagementGroupSample.js index 2c3fd91a824d..bebee0731052 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsCreateOrUpdateAtManagementGroupSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsCreateOrUpdateAtManagementGroupSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation creates or updates a policy set definition in the given management group with the given name. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionAtManagementGroup.json */ async function createOrUpdateAPolicySetDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "CostManagement"; const managementGroupId = "MyManagementGroup"; const parameters = { @@ -52,8 +54,6 @@ async function createOrUpdateAPolicySetDefinitionAtManagementGroupLevel() { console.log(result); } -createOrUpdateAPolicySetDefinitionAtManagementGroupLevel().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy set definition in the given management group with the given name. * @@ -61,7 +61,8 @@ createOrUpdateAPolicySetDefinitionAtManagementGroupLevel().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionWithGroupsAtManagementGroup.json */ async function createOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "CostManagement"; const managementGroupId = "MyManagementGroup"; const parameters = { @@ -110,4 +111,9 @@ async function createOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLeve console.log(result); } -createOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLevel().catch(console.error); +async function main() { + createOrUpdateAPolicySetDefinitionAtManagementGroupLevel(); + createOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsCreateOrUpdateSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsCreateOrUpdateSample.js index c21849cfae97..3ec16012b0cf 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsCreateOrUpdateSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsCreateOrUpdateSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation creates or updates a policy set definition in the given subscription with the given name. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinition.json */ async function createOrUpdateAPolicySetDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policySetDefinitionName = "CostManagement"; const parameters = { description: "Policies to enforce low cost storage SKUs", @@ -60,8 +62,6 @@ async function createOrUpdateAPolicySetDefinition() { console.log(result); } -createOrUpdateAPolicySetDefinition().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy set definition in the given subscription with the given name. * @@ -69,7 +69,8 @@ createOrUpdateAPolicySetDefinition().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionWithGroups.json */ async function createOrUpdateAPolicySetDefinitionWithGroups() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policySetDefinitionName = "CostManagement"; const parameters = { description: "Policies to enforce low cost storage SKUs", @@ -116,4 +117,9 @@ async function createOrUpdateAPolicySetDefinitionWithGroups() { console.log(result); } -createOrUpdateAPolicySetDefinitionWithGroups().catch(console.error); +async function main() { + createOrUpdateAPolicySetDefinition(); + createOrUpdateAPolicySetDefinitionWithGroups(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsDeleteAtManagementGroupSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsDeleteAtManagementGroupSample.js index 1505ed63eb38..886d744e150e 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsDeleteAtManagementGroupSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsDeleteAtManagementGroupSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation deletes the policy set definition in the given management group with the given name. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicySetDefinitionAtManagementGroup.json */ async function deleteAPolicySetDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "CostManagement"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); @@ -30,4 +32,8 @@ async function deleteAPolicySetDefinitionAtManagementGroupLevel() { console.log(result); } -deleteAPolicySetDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + deleteAPolicySetDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsDeleteSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsDeleteSample.js index 82c0bbdf4037..959d5ea22589 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsDeleteSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsDeleteSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation deletes the policy set definition in the given subscription with the given name. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicySetDefinition.json */ async function deleteAPolicySetDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policySetDefinitionName = "CostManagement"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +28,8 @@ async function deleteAPolicySetDefinition() { console.log(result); } -deleteAPolicySetDefinition().catch(console.error); +async function main() { + deleteAPolicySetDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsGetAtManagementGroupSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsGetAtManagementGroupSample.js index 470ff8e6957a..ddd7eca1d337 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsGetAtManagementGroupSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsGetAtManagementGroupSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the policy set definition in the given management group with the given name. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicySetDefinitionAtManagementGroup.json */ async function retrieveAPolicySetDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "CostManagement"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); @@ -30,4 +32,8 @@ async function retrieveAPolicySetDefinitionAtManagementGroupLevel() { console.log(result); } -retrieveAPolicySetDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + retrieveAPolicySetDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsGetBuiltInSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsGetBuiltInSample.js index 05a606ff70d1..5eba174ba239 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsGetBuiltInSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsGetBuiltInSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the built-in policy set definition with the given name. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getBuiltInPolicySetDefinition.json */ async function retrieveABuiltInPolicySetDefinition() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "1f3afdf9-d0c9-4c3d-847f-89da613e70a8"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +28,8 @@ async function retrieveABuiltInPolicySetDefinition() { console.log(result); } -retrieveABuiltInPolicySetDefinition().catch(console.error); +async function main() { + retrieveABuiltInPolicySetDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsGetSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsGetSample.js index fc3ee534ddc4..b3658f636553 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsGetSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsGetSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves the policy set definition in the given subscription with the given name. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicySetDefinition.json */ async function retrieveAPolicySetDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policySetDefinitionName = "CostManagement"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +28,8 @@ async function retrieveAPolicySetDefinition() { console.log(result); } -retrieveAPolicySetDefinition().catch(console.error); +async function main() { + retrieveAPolicySetDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsListBuiltInSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsListBuiltInSample.js index 7a549d2479dc..dee2ef0b0446 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsListBuiltInSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsListBuiltInSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves a list of all the built-in policy set definitions that match the optional given $filter. If $filter='category -eq {value}' is provided, the returned list only includes all built-in policy set definitions whose category match the {value}. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listBuiltInPolicySetDefinitions.json */ async function listBuiltInPolicySetDefinitions() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -28,4 +30,8 @@ async function listBuiltInPolicySetDefinitions() { console.log(resArray); } -listBuiltInPolicySetDefinitions().catch(console.error); +async function main() { + listBuiltInPolicySetDefinitions(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsListByManagementGroupSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsListByManagementGroupSample.js index 5021224359a1..774c999bc2b6 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsListByManagementGroupSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsListByManagementGroupSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves a list of all the policy set definitions in a given management group that match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list includes all policy set definitions associated with the management group, including those that apply directly or from management groups that contain the given management group. If $filter=atExactScope() is provided, the returned list only includes all policy set definitions that at the given management group. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy set definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn and Custom. If $filter='category -eq {value}' is provided, the returned list only includes all policy set definitions whose category match the {value}. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicySetDefinitionsByManagementGroup.json */ async function listPolicySetDefinitionsAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -29,4 +31,8 @@ async function listPolicySetDefinitionsAtManagementGroupLevel() { console.log(resArray); } -listPolicySetDefinitionsAtManagementGroupLevel().catch(console.error); +async function main() { + listPolicySetDefinitionsAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsListSample.js b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsListSample.js index ede475ffeaac..fcbe8d163134 100644 --- a/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsListSample.js +++ b/sdk/policy/arm-policy/samples/v5/javascript/policySetDefinitionsListSample.js @@ -10,6 +10,7 @@ // Licensed under the MIT License. const { PolicyClient } = require("@azure/arm-policy"); const { DefaultAzureCredential } = require("@azure/identity"); +require("dotenv").config(); /** * This sample demonstrates how to This operation retrieves a list of all the policy set definitions in a given subscription that match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list includes all policy set definitions associated with the subscription, including those that apply directly or from management groups that contain the given subscription. If $filter=atExactScope() is provided, the returned list only includes all policy set definitions that at the given subscription. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy set definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn and Custom. If $filter='category -eq {value}' is provided, the returned list only includes all policy set definitions whose category match the {value}. @@ -18,7 +19,8 @@ const { DefaultAzureCredential } = require("@azure/identity"); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicySetDefinitions.json */ async function listPolicySetDefinitions() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -28,4 +30,8 @@ async function listPolicySetDefinitions() { console.log(resArray); } -listPolicySetDefinitions().catch(console.error); +async function main() { + listPolicySetDefinitions(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/README.md b/sdk/policy/arm-policy/samples/v5/typescript/README.md index fba7c8537b3d..030171440e51 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/README.md +++ b/sdk/policy/arm-policy/samples/v5/typescript/README.md @@ -89,7 +89,7 @@ node dist/dataPolicyManifestsGetByPolicyModeSample.js Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform): ```bash -npx cross-env node dist/dataPolicyManifestsGetByPolicyModeSample.js +npx cross-env POLICY_SUBSCRIPTION_ID="" node dist/dataPolicyManifestsGetByPolicyModeSample.js ``` ## Next Steps diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/dataPolicyManifestsGetByPolicyModeSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/dataPolicyManifestsGetByPolicyModeSample.ts index 956226d4552c..0d90725e4556 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/dataPolicyManifestsGetByPolicyModeSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/dataPolicyManifestsGetByPolicyModeSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the data policy manifest with the given policy mode. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/getDataPolicyManifest.json */ async function retrieveADataPolicyManifestByPolicyMode() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyMode = "Microsoft.KeyVault.Data"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +31,8 @@ async function retrieveADataPolicyManifestByPolicyMode() { console.log(result); } -retrieveADataPolicyManifestByPolicyMode().catch(console.error); +async function main() { + retrieveADataPolicyManifestByPolicyMode(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/dataPolicyManifestsListSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/dataPolicyManifestsListSample.ts index b9a1e68ed467..f2f7644f5e85 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/dataPolicyManifestsListSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/dataPolicyManifestsListSample.ts @@ -13,6 +13,9 @@ import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a list of all the data policy manifests that match the optional given $filter. Valid values for $filter are: "$filter=namespace eq '{0}'". If $filter is not provided, the unfiltered list includes all data policy manifests for data resource types. If $filter=namespace is provided, the returned list only includes all data policy manifests that have a namespace matching the provided value. @@ -21,7 +24,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/listDataPolicyManifests.json */ async function listDataPolicyManifests() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -31,8 +36,6 @@ async function listDataPolicyManifests() { console.log(resArray); } -listDataPolicyManifests().catch(console.error); - /** * This sample demonstrates how to This operation retrieves a list of all the data policy manifests that match the optional given $filter. Valid values for $filter are: "$filter=namespace eq '{0}'". If $filter is not provided, the unfiltered list includes all data policy manifests for data resource types. If $filter=namespace is provided, the returned list only includes all data policy manifests that have a namespace matching the provided value. * @@ -40,7 +43,9 @@ listDataPolicyManifests().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/listDataPolicyManifestsNamespaceFilter.json */ async function listDataPolicyManifestsWithNamespaceFilter() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const filter = "namespace eq 'Microsoft.KeyVault'"; const options: DataPolicyManifestsListOptionalParams = { filter }; const credential = new DefaultAzureCredential(); @@ -52,4 +57,9 @@ async function listDataPolicyManifestsWithNamespaceFilter() { console.log(resArray); } -listDataPolicyManifestsWithNamespaceFilter().catch(console.error); +async function main() { + listDataPolicyManifests(); + listDataPolicyManifestsWithNamespaceFilter(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsCreateByIdSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsCreateByIdSample.ts index c4cf52a4165d..ac2ee1876dff 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsCreateByIdSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsCreateByIdSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyAssignment, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation creates or updates the policy assignment with the given ID. Policy assignments made on a scope apply to all resources contained in that scope. For example, when you assign a policy to a resource group that policy applies to all resources in the group. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentById.json */ async function createOrUpdatePolicyAssignmentById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const parameters: PolicyAssignment = { @@ -42,8 +47,6 @@ async function createOrUpdatePolicyAssignmentById() { console.log(result); } -createOrUpdatePolicyAssignmentById().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates the policy assignment with the given ID. Policy assignments made on a scope apply to all resources contained in that scope. For example, when you assign a policy to a resource group that policy applies to all resources in the group. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. * @@ -51,7 +54,9 @@ createOrUpdatePolicyAssignmentById().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithIdentityById.json */ async function createOrUpdatePolicyAssignmentWithAManagedIdentityById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const parameters: PolicyAssignment = { @@ -77,4 +82,9 @@ async function createOrUpdatePolicyAssignmentWithAManagedIdentityById() { console.log(result); } -createOrUpdatePolicyAssignmentWithAManagedIdentityById().catch(console.error); +async function main() { + createOrUpdatePolicyAssignmentById(); + createOrUpdatePolicyAssignmentWithAManagedIdentityById(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsCreateSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsCreateSample.ts index 133bde87b7fb..37aee9e33096 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsCreateSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsCreateSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyAssignment, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignment.json */ async function createOrUpdateAPolicyAssignment() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters: PolicyAssignment = { @@ -43,8 +48,6 @@ async function createOrUpdateAPolicyAssignment() { console.log(result); } -createOrUpdateAPolicyAssignment().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -52,7 +55,9 @@ createOrUpdateAPolicyAssignment().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithIdentity.json */ async function createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters: PolicyAssignment = { @@ -77,10 +82,6 @@ async function createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity() { console.log(result); } -createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity().catch( - console.error -); - /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -88,7 +89,9 @@ createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity().catch( * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithUserAssignedIdentity.json */ async function createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters: PolicyAssignment = { @@ -118,8 +121,6 @@ async function createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity() { console.log(result); } -createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -127,7 +128,9 @@ createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentNonComplianceMessages.json */ async function createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "securityInitAssignment"; const parameters: PolicyAssignment = { @@ -159,10 +162,6 @@ async function createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages( console.log(result); } -createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages().catch( - console.error -); - /** * This sample demonstrates how to This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -170,7 +169,9 @@ createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages().catch( * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithoutEnforcement.json */ async function createOrUpdateAPolicyAssignmentWithoutEnforcingPolicyEffectDuringResourceCreationOrUpdate() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters: PolicyAssignment = { @@ -193,6 +194,12 @@ async function createOrUpdateAPolicyAssignmentWithoutEnforcingPolicyEffectDuring console.log(result); } -createOrUpdateAPolicyAssignmentWithoutEnforcingPolicyEffectDuringResourceCreationOrUpdate().catch( - console.error -); +async function main() { + createOrUpdateAPolicyAssignment(); + createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity(); + createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity(); + createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages(); + createOrUpdateAPolicyAssignmentWithoutEnforcingPolicyEffectDuringResourceCreationOrUpdate(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsDeleteByIdSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsDeleteByIdSample.ts index d35b62115dc8..0aa1ac4f69d2 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsDeleteByIdSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsDeleteByIdSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation deletes the policy with the given ID. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid formats for {scope} are: '/providers/Microsoft.Management/managementGroups/{managementGroup}' (management group), '/subscriptions/{subscriptionId}' (subscription), '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' (resource group), or '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}' (resource). @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyAssignmentById.json */ async function deleteAPolicyAssignmentById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const credential = new DefaultAzureCredential(); @@ -27,4 +32,8 @@ async function deleteAPolicyAssignmentById() { console.log(result); } -deleteAPolicyAssignmentById().catch(console.error); +async function main() { + deleteAPolicyAssignmentById(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsDeleteSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsDeleteSample.ts index e2976b8ac214..196f29e55cc9 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsDeleteSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsDeleteSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation deletes a policy assignment, given its name and the scope it was created in. The scope of a policy assignment is the part of its ID preceding '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyAssignment.json */ async function deleteAPolicyAssignment() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const credential = new DefaultAzureCredential(); @@ -30,4 +35,8 @@ async function deleteAPolicyAssignment() { console.log(result); } -deleteAPolicyAssignment().catch(console.error); +async function main() { + deleteAPolicyAssignment(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsGetByIdSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsGetByIdSample.ts index 1733f93e2cd9..78996c20c468 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsGetByIdSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsGetByIdSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to The operation retrieves the policy assignment with the given ID. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentById.json */ async function retrieveAPolicyAssignmentById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const credential = new DefaultAzureCredential(); @@ -27,8 +32,6 @@ async function retrieveAPolicyAssignmentById() { console.log(result); } -retrieveAPolicyAssignmentById().catch(console.error); - /** * This sample demonstrates how to The operation retrieves the policy assignment with the given ID. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. * @@ -36,7 +39,9 @@ retrieveAPolicyAssignmentById().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentWithIdentityById.json */ async function retrieveAPolicyAssignmentWithAManagedIdentityById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const credential = new DefaultAzureCredential(); @@ -45,4 +50,9 @@ async function retrieveAPolicyAssignmentWithAManagedIdentityById() { console.log(result); } -retrieveAPolicyAssignmentWithAManagedIdentityById().catch(console.error); +async function main() { + retrieveAPolicyAssignmentById(); + retrieveAPolicyAssignmentWithAManagedIdentityById(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsGetSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsGetSample.ts index 0b98df70f83a..e513b65584b8 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsGetSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsGetSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a single policy assignment, given its name and the scope it was created at. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignment.json */ async function retrieveAPolicyAssignment() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const credential = new DefaultAzureCredential(); @@ -30,8 +35,6 @@ async function retrieveAPolicyAssignment() { console.log(result); } -retrieveAPolicyAssignment().catch(console.error); - /** * This sample demonstrates how to This operation retrieves a single policy assignment, given its name and the scope it was created at. * @@ -39,7 +42,9 @@ retrieveAPolicyAssignment().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentWithIdentity.json */ async function retrieveAPolicyAssignmentWithASystemAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const credential = new DefaultAzureCredential(); @@ -51,8 +56,6 @@ async function retrieveAPolicyAssignmentWithASystemAssignedIdentity() { console.log(result); } -retrieveAPolicyAssignmentWithASystemAssignedIdentity().catch(console.error); - /** * This sample demonstrates how to This operation retrieves a single policy assignment, given its name and the scope it was created at. * @@ -60,7 +63,9 @@ retrieveAPolicyAssignmentWithASystemAssignedIdentity().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentWithUserAssignedIdentity.json */ async function retrieveAPolicyAssignmentWithAUserAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const credential = new DefaultAzureCredential(); @@ -72,4 +77,10 @@ async function retrieveAPolicyAssignmentWithAUserAssignedIdentity() { console.log(result); } -retrieveAPolicyAssignmentWithAUserAssignedIdentity().catch(console.error); +async function main() { + retrieveAPolicyAssignment(); + retrieveAPolicyAssignmentWithASystemAssignedIdentity(); + retrieveAPolicyAssignmentWithAUserAssignedIdentity(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListForManagementGroupSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListForManagementGroupSample.ts index dacf306881b2..a49056ffe7f2 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListForManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListForManagementGroupSample.ts @@ -13,6 +13,9 @@ import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy assignments applicable to the management group that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter=atScope() is provided, the returned list includes all policy assignments that are assigned to the management group or the management group's ancestors. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the management group. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value} that apply to the management group. @@ -21,7 +24,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignmentsForManagementGroup.json */ async function listPolicyAssignmentsThatApplyToAManagementGroup() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const managementGroupId = "TestManagementGroup"; const filter = "atScope()"; const options: PolicyAssignmentsListForManagementGroupOptionalParams = { @@ -39,4 +44,8 @@ async function listPolicyAssignmentsThatApplyToAManagementGroup() { console.log(resArray); } -listPolicyAssignmentsThatApplyToAManagementGroup().catch(console.error); +async function main() { + listPolicyAssignmentsThatApplyToAManagementGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListForResourceGroupSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListForResourceGroupSample.ts index 43679b8ae4c8..83f6cff931cf 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListForResourceGroupSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListForResourceGroupSample.ts @@ -13,6 +13,9 @@ import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy assignments associated with the given resource group in the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments associated with the resource group, including those that apply directly or apply from containing scopes, as well as any applied to resources contained within the resource group. If $filter=atScope() is provided, the returned list includes all policy assignments that apply to the resource group, which is everything in the unfiltered list except those applied to resources contained within the resource group. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the resource group. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value} that apply to the resource group. @@ -21,8 +24,11 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignmentsForResourceGroup.json */ async function listPolicyAssignmentsThatApplyToAResourceGroup() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; - const resourceGroupName = "TestResourceGroup"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const resourceGroupName = + process.env["POLICY_RESOURCE_GROUP"] || "TestResourceGroup"; const filter = "atScope()"; const options: PolicyAssignmentsListForResourceGroupOptionalParams = { filter @@ -39,4 +45,8 @@ async function listPolicyAssignmentsThatApplyToAResourceGroup() { console.log(resArray); } -listPolicyAssignmentsThatApplyToAResourceGroup().catch(console.error); +async function main() { + listPolicyAssignmentsThatApplyToAResourceGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListForResourceSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListForResourceSample.ts index 0d43e41446b9..4d7755b80551 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListForResourceSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListForResourceSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy assignments associated with the specified resource in the given resource group and subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments associated with the resource, including those that apply directly or from all containing scopes, as well as any applied to resources contained within the resource. If $filter=atScope() is provided, the returned list includes all policy assignments that apply to the resource, which is everything in the unfiltered list except those applied to resources contained within the resource. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the resource level. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value} that apply to the resource. Three parameters plus the resource name are used to identify a specific resource. If the resource is not part of a parent resource (the more common case), the parent resource path should not be provided (or provided as ''). For example a web app could be specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all parameters should be provided. For example a virtual machine DNS name could be specified as ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == 'MyComputerName'). A convenient alternative to providing the namespace and type name separately is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp'). @@ -18,8 +21,11 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignmentsForResource.json */ async function listAllPolicyAssignmentsThatApplyToAResource() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; - const resourceGroupName = "TestResourceGroup"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const resourceGroupName = + process.env["POLICY_RESOURCE_GROUP"] || "TestResourceGroup"; const resourceProviderNamespace = "Microsoft.Compute"; const parentResourcePath = "virtualMachines/MyTestVm"; const resourceType = "domainNames"; @@ -39,4 +45,8 @@ async function listAllPolicyAssignmentsThatApplyToAResource() { console.log(resArray); } -listAllPolicyAssignmentsThatApplyToAResource().catch(console.error); +async function main() { + listAllPolicyAssignmentsThatApplyToAResource(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListSample.ts index c3e9575f594c..225dc0e897d4 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsListSample.ts @@ -13,6 +13,9 @@ import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy assignments associated with the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments associated with the subscription, including those that apply directly or from management groups that contain the given subscription, as well as any applied to objects contained within the subscription. If $filter=atScope() is provided, the returned list includes all policy assignments that apply to the subscription, which is everything in the unfiltered list except those applied to objects contained within the subscription. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the subscription. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value}. @@ -21,7 +24,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignments.json */ async function listPolicyAssignmentsThatApplyToASubscription() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const filter = "atScope()"; const options: PolicyAssignmentsListOptionalParams = { filter }; const credential = new DefaultAzureCredential(); @@ -33,4 +38,8 @@ async function listPolicyAssignmentsThatApplyToASubscription() { console.log(resArray); } -listPolicyAssignmentsThatApplyToASubscription().catch(console.error); +async function main() { + listPolicyAssignmentsThatApplyToASubscription(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsUpdateByIdSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsUpdateByIdSample.ts index 3f654336a500..a69a4a007801 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsUpdateByIdSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsUpdateByIdSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyAssignmentUpdate, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation updates the policy assignment with the given ID. Policy assignments made on a scope apply to all resources contained in that scope. For example, when you assign a policy to a resource group that policy applies to all resources in the group. Policy assignment IDs have this format: '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/updatePolicyAssignmentWithIdentityById.json */ async function updatePolicyAssignmentWithAManagedIdentityById() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyAssignmentId = "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"; const parameters: PolicyAssignmentUpdate = { @@ -34,4 +39,8 @@ async function updatePolicyAssignmentWithAManagedIdentityById() { console.log(result); } -updatePolicyAssignmentWithAManagedIdentityById().catch(console.error); +async function main() { + updatePolicyAssignmentWithAManagedIdentityById(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsUpdateSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsUpdateSample.ts index 2c5ad77e13d0..14052f66cd03 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsUpdateSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyAssignmentsUpdateSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyAssignmentUpdate, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/updatePolicyAssignmentWithIdentity.json */ async function updateAPolicyAssignmentWithASystemAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters: PolicyAssignmentUpdate = { @@ -35,8 +40,6 @@ async function updateAPolicyAssignmentWithASystemAssignedIdentity() { console.log(result); } -updateAPolicyAssignmentWithASystemAssignedIdentity().catch(console.error); - /** * This sample demonstrates how to This operation updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. * @@ -44,7 +47,9 @@ updateAPolicyAssignmentWithASystemAssignedIdentity().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/updatePolicyAssignmentWithUserAssignedIdentity.json */ async function updateAPolicyAssignmentWithAUserAssignedIdentity() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyAssignmentName = "EnforceNaming"; const parameters: PolicyAssignmentUpdate = { @@ -66,4 +71,9 @@ async function updateAPolicyAssignmentWithAUserAssignedIdentity() { console.log(result); } -updateAPolicyAssignmentWithAUserAssignedIdentity().catch(console.error); +async function main() { + updateAPolicyAssignmentWithASystemAssignedIdentity(); + updateAPolicyAssignmentWithAUserAssignedIdentity(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsCreateOrUpdateAtManagementGroupSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsCreateOrUpdateAtManagementGroupSample.ts index eb6f78d43180..2bd9e6d06d21 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsCreateOrUpdateAtManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsCreateOrUpdateAtManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyDefinition, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation creates or updates a policy definition in the given management group with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinitionAtManagementGroup.json */ async function createOrUpdateAPolicyDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyDefinitionName = "ResourceNaming"; const managementGroupId = "MyManagementGroup"; const parameters: PolicyDefinition = { @@ -57,4 +62,8 @@ async function createOrUpdateAPolicyDefinitionAtManagementGroupLevel() { console.log(result); } -createOrUpdateAPolicyDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + createOrUpdateAPolicyDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsCreateOrUpdateSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsCreateOrUpdateSample.ts index 73945549810e..ca2517d2e44d 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsCreateOrUpdateSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsCreateOrUpdateSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyDefinition, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation creates or updates a policy definition in the given subscription with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinition.json */ async function createOrUpdateAPolicyDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyDefinitionName = "ResourceNaming"; const parameters: PolicyDefinition = { description: @@ -55,8 +60,6 @@ async function createOrUpdateAPolicyDefinition() { console.log(result); } -createOrUpdateAPolicyDefinition().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy definition in the given subscription with the given name. * @@ -64,7 +67,9 @@ createOrUpdateAPolicyDefinition().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinitionAdvancedParams.json */ async function createOrUpdateAPolicyDefinitionWithAdvancedParameters() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyDefinitionName = "EventHubDiagnosticLogs"; const parameters: PolicyDefinition = { description: @@ -116,4 +121,9 @@ async function createOrUpdateAPolicyDefinitionWithAdvancedParameters() { console.log(result); } -createOrUpdateAPolicyDefinitionWithAdvancedParameters().catch(console.error); +async function main() { + createOrUpdateAPolicyDefinition(); + createOrUpdateAPolicyDefinitionWithAdvancedParameters(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsDeleteAtManagementGroupSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsDeleteAtManagementGroupSample.ts index f21e0b672e3c..a558918f0922 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsDeleteAtManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsDeleteAtManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation deletes the policy definition in the given management group with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyDefinitionAtManagementGroup.json */ async function deleteAPolicyDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyDefinitionName = "ResourceNaming"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); @@ -30,4 +35,8 @@ async function deleteAPolicyDefinitionAtManagementGroupLevel() { console.log(result); } -deleteAPolicyDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + deleteAPolicyDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsDeleteSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsDeleteSample.ts index ba4d5422c2ae..4e9a36a37d78 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsDeleteSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsDeleteSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation deletes the policy definition in the given subscription with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyDefinition.json */ async function deleteAPolicyDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyDefinitionName = "ResourceNaming"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +31,8 @@ async function deleteAPolicyDefinition() { console.log(result); } -deleteAPolicyDefinition().catch(console.error); +async function main() { + deleteAPolicyDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsGetAtManagementGroupSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsGetAtManagementGroupSample.ts index 27fcab9e3087..eb82f1274580 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsGetAtManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsGetAtManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the policy definition in the given management group with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyDefinitionAtManagementGroup.json */ async function retrieveAPolicyDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyDefinitionName = "ResourceNaming"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); @@ -30,4 +35,8 @@ async function retrieveAPolicyDefinitionAtManagementGroupLevel() { console.log(result); } -retrieveAPolicyDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + retrieveAPolicyDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsGetBuiltInSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsGetBuiltInSample.ts index f719a34a23bf..e9bd89dee326 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsGetBuiltInSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsGetBuiltInSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the built-in policy definition with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getBuiltinPolicyDefinition.json */ async function retrieveABuiltInPolicyDefinition() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policyDefinitionName = "7433c107-6db4-4ad1-b57a-a76dce0154a1"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -28,4 +33,8 @@ async function retrieveABuiltInPolicyDefinition() { console.log(result); } -retrieveABuiltInPolicyDefinition().catch(console.error); +async function main() { + retrieveABuiltInPolicyDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsGetSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsGetSample.ts index ce61f8060856..db3faf195693 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsGetSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsGetSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the policy definition in the given subscription with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyDefinition.json */ async function retrieveAPolicyDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policyDefinitionName = "ResourceNaming"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +31,8 @@ async function retrieveAPolicyDefinition() { console.log(result); } -retrieveAPolicyDefinition().catch(console.error); +async function main() { + retrieveAPolicyDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsListBuiltInSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsListBuiltInSample.ts index b565261b76cf..255a1d66f5ce 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsListBuiltInSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsListBuiltInSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a list of all the built-in policy definitions that match the optional given $filter. If $filter='policyType -eq {value}' is provided, the returned list only includes all built-in policy definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all built-in policy definitions whose category match the {value}. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listBuiltInPolicyDefinitions.json */ async function listBuiltInPolicyDefinitions() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -28,4 +33,8 @@ async function listBuiltInPolicyDefinitions() { console.log(resArray); } -listBuiltInPolicyDefinitions().catch(console.error); +async function main() { + listBuiltInPolicyDefinitions(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsListByManagementGroupSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsListByManagementGroupSample.ts index 0d588d20df2b..4d2b83fb6c4c 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsListByManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsListByManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a list of all the policy definitions in a given management group that match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list includes all policy definitions associated with the management group, including those that apply directly or from management groups that contain the given management group. If $filter=atExactScope() is provided, the returned list only includes all policy definitions that at the given management group. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all policy definitions whose category match the {value}. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyDefinitionsByManagementGroup.json */ async function listPolicyDefinitionsByManagementGroup() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -31,4 +36,8 @@ async function listPolicyDefinitionsByManagementGroup() { console.log(resArray); } -listPolicyDefinitionsByManagementGroup().catch(console.error); +async function main() { + listPolicyDefinitionsByManagementGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsListSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsListSample.ts index b98016d43e38..5909902eb1f6 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsListSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyDefinitionsListSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a list of all the policy definitions in a given subscription that match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list includes all policy definitions associated with the subscription, including those that apply directly or from management groups that contain the given subscription. If $filter=atExactScope() is provided, the returned list only includes all policy definitions that at the given subscription. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all policy definitions whose category match the {value}. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyDefinitions.json */ async function listPolicyDefinitionsBySubscription() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -28,4 +33,8 @@ async function listPolicyDefinitionsBySubscription() { console.log(resArray); } -listPolicyDefinitionsBySubscription().catch(console.error); +async function main() { + listPolicyDefinitionsBySubscription(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsCreateOrUpdateSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsCreateOrUpdateSample.ts index d8baa98d0f63..fdf6492281f5 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsCreateOrUpdateSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsCreateOrUpdateSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyExemption, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation creates or updates a policy exemption with the given scope and name. Policy exemptions apply to all resources contained within their scope. For example, when you create a policy exemption at resource group scope for a policy assignment at the same or above level, the exemption exempts to all applicable resources in the resource group. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/createOrUpdatePolicyExemption.json */ async function createOrUpdateAPolicyExemption() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/demoCluster"; const policyExemptionName = "DemoExpensiveVM"; @@ -41,4 +46,8 @@ async function createOrUpdateAPolicyExemption() { console.log(result); } -createOrUpdateAPolicyExemption().catch(console.error); +async function main() { + createOrUpdateAPolicyExemption(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsDeleteSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsDeleteSample.ts index 333235e2aff4..602f7ab210e6 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsDeleteSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsDeleteSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation deletes a policy exemption, given its name and the scope it was created in. The scope of a policy exemption is the part of its ID preceding '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/deletePolicyExemption.json */ async function deleteAPolicyExemption() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/demoCluster"; const policyExemptionName = "DemoExpensiveVM"; @@ -31,4 +36,8 @@ async function deleteAPolicyExemption() { console.log(result); } -deleteAPolicyExemption().catch(console.error); +async function main() { + deleteAPolicyExemption(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsGetSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsGetSample.ts index 04416e7965c0..22bf6dc2ece5 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsGetSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsGetSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a single policy exemption, given its name and the scope it was created at. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/getPolicyExemption.json */ async function retrieveAPolicyExemption() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/demoCluster"; const policyExemptionName = "DemoExpensiveVM"; @@ -28,4 +33,8 @@ async function retrieveAPolicyExemption() { console.log(result); } -retrieveAPolicyExemption().catch(console.error); +async function main() { + retrieveAPolicyExemption(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListForManagementGroupSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListForManagementGroupSample.ts index 7efc527ef9a4..ce67bd91fa66 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListForManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListForManagementGroupSample.ts @@ -13,6 +13,9 @@ import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy exemptions applicable to the management group that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter=atScope() is provided, the returned list includes all policy exemptions that are assigned to the management group or the management group's ancestors. @@ -21,7 +24,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForManagementGroup.json */ async function listPolicyExemptionsThatApplyToAManagementGroup() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const managementGroupId = "DevOrg"; const filter = "atScope()"; const options: PolicyExemptionsListForManagementGroupOptionalParams = { @@ -39,4 +44,8 @@ async function listPolicyExemptionsThatApplyToAManagementGroup() { console.log(resArray); } -listPolicyExemptionsThatApplyToAManagementGroup().catch(console.error); +async function main() { + listPolicyExemptionsThatApplyToAManagementGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListForResourceGroupSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListForResourceGroupSample.ts index 71b11bd79266..89d134c5d28c 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListForResourceGroupSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListForResourceGroupSample.ts @@ -13,6 +13,9 @@ import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy exemptions associated with the given resource group in the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy exemptions associated with the resource group, including those that apply directly or apply from containing scopes, as well as any applied to resources contained within the resource group. @@ -21,8 +24,11 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForResourceGroup.json */ async function listPolicyExemptionsThatApplyToAResourceGroup() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; - const resourceGroupName = "TestResourceGroup"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const resourceGroupName = + process.env["POLICY_RESOURCE_GROUP"] || "TestResourceGroup"; const filter = "atScope()"; const options: PolicyExemptionsListForResourceGroupOptionalParams = { filter @@ -39,4 +45,8 @@ async function listPolicyExemptionsThatApplyToAResourceGroup() { console.log(resArray); } -listPolicyExemptionsThatApplyToAResourceGroup().catch(console.error); +async function main() { + listPolicyExemptionsThatApplyToAResourceGroup(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListForResourceSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListForResourceSample.ts index d244bccee220..d8b18e3d975f 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListForResourceSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListForResourceSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy exemptions associated with the specified resource in the given resource group and subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy exemptions associated with the resource, including those that apply directly or from all containing scopes, as well as any applied to resources contained within the resource. Three parameters plus the resource name are used to identify a specific resource. If the resource is not part of a parent resource (the more common case), the parent resource path should not be provided (or provided as ''). For example a web app could be specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all parameters should be provided. For example a virtual machine DNS name could be specified as ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == 'MyComputerName'). A convenient alternative to providing the namespace and type name separately is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp'). @@ -18,8 +21,11 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForResource.json */ async function listAllPolicyExemptionsThatApplyToAResource() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; - const resourceGroupName = "TestResourceGroup"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const resourceGroupName = + process.env["POLICY_RESOURCE_GROUP"] || "TestResourceGroup"; const resourceProviderNamespace = "Microsoft.Compute"; const parentResourcePath = "virtualMachines/MyTestVm"; const resourceType = "domainNames"; @@ -39,4 +45,8 @@ async function listAllPolicyExemptionsThatApplyToAResource() { console.log(resArray); } -listAllPolicyExemptionsThatApplyToAResource().catch(console.error); +async function main() { + listAllPolicyExemptionsThatApplyToAResource(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListSample.ts index 60c1219dbbf3..26024134450b 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policyExemptionsListSample.ts @@ -13,6 +13,9 @@ import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the list of all policy exemptions associated with the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy exemptions associated with the subscription, including those that apply directly or from management groups that contain the given subscription, as well as any applied to objects contained within the subscription. @@ -21,7 +24,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForSubscription.json */ async function listPolicyExemptionsThatApplyToASubscription() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const filter = "atScope()"; const options: PolicyExemptionsListOptionalParams = { filter }; const credential = new DefaultAzureCredential(); @@ -33,4 +38,8 @@ async function listPolicyExemptionsThatApplyToASubscription() { console.log(resArray); } -listPolicyExemptionsThatApplyToASubscription().catch(console.error); +async function main() { + listPolicyExemptionsThatApplyToASubscription(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsCreateOrUpdateAtManagementGroupSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsCreateOrUpdateAtManagementGroupSample.ts index e0d324f27db8..c8d68032ae6a 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsCreateOrUpdateAtManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsCreateOrUpdateAtManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicySetDefinition, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation creates or updates a policy set definition in the given management group with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionAtManagementGroup.json */ async function createOrUpdateAPolicySetDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "CostManagement"; const managementGroupId = "MyManagementGroup"; const parameters: PolicySetDefinition = { @@ -52,8 +57,6 @@ async function createOrUpdateAPolicySetDefinitionAtManagementGroupLevel() { console.log(result); } -createOrUpdateAPolicySetDefinitionAtManagementGroupLevel().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy set definition in the given management group with the given name. * @@ -61,7 +64,9 @@ createOrUpdateAPolicySetDefinitionAtManagementGroupLevel().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionWithGroupsAtManagementGroup.json */ async function createOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "CostManagement"; const managementGroupId = "MyManagementGroup"; const parameters: PolicySetDefinition = { @@ -111,6 +116,9 @@ async function createOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLeve console.log(result); } -createOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLevel().catch( - console.error -); +async function main() { + createOrUpdateAPolicySetDefinitionAtManagementGroupLevel(); + createOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsCreateOrUpdateSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsCreateOrUpdateSample.ts index 8b66d516f5f0..cd07a37043c9 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsCreateOrUpdateSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsCreateOrUpdateSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicySetDefinition, PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation creates or updates a policy set definition in the given subscription with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinition.json */ async function createOrUpdateAPolicySetDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policySetDefinitionName = "CostManagement"; const parameters: PolicySetDefinition = { description: "Policies to enforce low cost storage SKUs", @@ -60,8 +65,6 @@ async function createOrUpdateAPolicySetDefinition() { console.log(result); } -createOrUpdateAPolicySetDefinition().catch(console.error); - /** * This sample demonstrates how to This operation creates or updates a policy set definition in the given subscription with the given name. * @@ -69,7 +72,9 @@ createOrUpdateAPolicySetDefinition().catch(console.error); * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionWithGroups.json */ async function createOrUpdateAPolicySetDefinitionWithGroups() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policySetDefinitionName = "CostManagement"; const parameters: PolicySetDefinition = { description: "Policies to enforce low cost storage SKUs", @@ -117,4 +122,9 @@ async function createOrUpdateAPolicySetDefinitionWithGroups() { console.log(result); } -createOrUpdateAPolicySetDefinitionWithGroups().catch(console.error); +async function main() { + createOrUpdateAPolicySetDefinition(); + createOrUpdateAPolicySetDefinitionWithGroups(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsDeleteAtManagementGroupSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsDeleteAtManagementGroupSample.ts index 049650909401..2b663525150f 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsDeleteAtManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsDeleteAtManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation deletes the policy set definition in the given management group with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicySetDefinitionAtManagementGroup.json */ async function deleteAPolicySetDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "CostManagement"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); @@ -30,4 +35,8 @@ async function deleteAPolicySetDefinitionAtManagementGroupLevel() { console.log(result); } -deleteAPolicySetDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + deleteAPolicySetDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsDeleteSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsDeleteSample.ts index f677be46c467..fc3397aad46b 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsDeleteSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsDeleteSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation deletes the policy set definition in the given subscription with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicySetDefinition.json */ async function deleteAPolicySetDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policySetDefinitionName = "CostManagement"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -28,4 +33,8 @@ async function deleteAPolicySetDefinition() { console.log(result); } -deleteAPolicySetDefinition().catch(console.error); +async function main() { + deleteAPolicySetDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsGetAtManagementGroupSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsGetAtManagementGroupSample.ts index 5bc3ae6bc005..bcc684972eb2 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsGetAtManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsGetAtManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the policy set definition in the given management group with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicySetDefinitionAtManagementGroup.json */ async function retrieveAPolicySetDefinitionAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "CostManagement"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); @@ -30,4 +35,8 @@ async function retrieveAPolicySetDefinitionAtManagementGroupLevel() { console.log(result); } -retrieveAPolicySetDefinitionAtManagementGroupLevel().catch(console.error); +async function main() { + retrieveAPolicySetDefinitionAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsGetBuiltInSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsGetBuiltInSample.ts index eaa2ab035acc..abe463354e29 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsGetBuiltInSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsGetBuiltInSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the built-in policy set definition with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getBuiltInPolicySetDefinition.json */ async function retrieveABuiltInPolicySetDefinition() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const policySetDefinitionName = "1f3afdf9-d0c9-4c3d-847f-89da613e70a8"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -28,4 +33,8 @@ async function retrieveABuiltInPolicySetDefinition() { console.log(result); } -retrieveABuiltInPolicySetDefinition().catch(console.error); +async function main() { + retrieveABuiltInPolicySetDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsGetSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsGetSample.ts index f157eb34c168..8792a7c33808 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsGetSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsGetSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves the policy set definition in the given subscription with the given name. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicySetDefinition.json */ async function retrieveAPolicySetDefinition() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const policySetDefinitionName = "CostManagement"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -26,4 +31,8 @@ async function retrieveAPolicySetDefinition() { console.log(result); } -retrieveAPolicySetDefinition().catch(console.error); +async function main() { + retrieveAPolicySetDefinition(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsListBuiltInSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsListBuiltInSample.ts index 39c0fa42c3b7..c68958d14812 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsListBuiltInSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsListBuiltInSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a list of all the built-in policy set definitions that match the optional given $filter. If $filter='category -eq {value}' is provided, the returned list only includes all built-in policy set definitions whose category match the {value}. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listBuiltInPolicySetDefinitions.json */ async function listBuiltInPolicySetDefinitions() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -28,4 +33,8 @@ async function listBuiltInPolicySetDefinitions() { console.log(resArray); } -listBuiltInPolicySetDefinitions().catch(console.error); +async function main() { + listBuiltInPolicySetDefinitions(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsListByManagementGroupSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsListByManagementGroupSample.ts index 7ad9f07b3d79..abd743e737f7 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsListByManagementGroupSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsListByManagementGroupSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a list of all the policy set definitions in a given management group that match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list includes all policy set definitions associated with the management group, including those that apply directly or from management groups that contain the given management group. If $filter=atExactScope() is provided, the returned list only includes all policy set definitions that at the given management group. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy set definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn and Custom. If $filter='category -eq {value}' is provided, the returned list only includes all policy set definitions whose category match the {value}. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicySetDefinitionsByManagementGroup.json */ async function listPolicySetDefinitionsAtManagementGroupLevel() { - const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "00000000-0000-0000-0000-000000000000"; const managementGroupId = "MyManagementGroup"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); @@ -31,4 +36,8 @@ async function listPolicySetDefinitionsAtManagementGroupLevel() { console.log(resArray); } -listPolicySetDefinitionsAtManagementGroupLevel().catch(console.error); +async function main() { + listPolicySetDefinitionsAtManagementGroupLevel(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsListSample.ts b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsListSample.ts index 9f7ffe53961a..feb9603a2d2d 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsListSample.ts +++ b/sdk/policy/arm-policy/samples/v5/typescript/src/policySetDefinitionsListSample.ts @@ -10,6 +10,9 @@ // Licensed under the MIT License. import { PolicyClient } from "@azure/arm-policy"; import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); /** * This sample demonstrates how to This operation retrieves a list of all the policy set definitions in a given subscription that match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list includes all policy set definitions associated with the subscription, including those that apply directly or from management groups that contain the given subscription. If $filter=atExactScope() is provided, the returned list only includes all policy set definitions that at the given subscription. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy set definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn and Custom. If $filter='category -eq {value}' is provided, the returned list only includes all policy set definitions whose category match the {value}. @@ -18,7 +21,9 @@ import { DefaultAzureCredential } from "@azure/identity"; * x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicySetDefinitions.json */ async function listPolicySetDefinitions() { - const subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + const subscriptionId = + process.env["POLICY_SUBSCRIPTION_ID"] || + "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; const credential = new DefaultAzureCredential(); const client = new PolicyClient(credential, subscriptionId); const resArray = new Array(); @@ -28,4 +33,8 @@ async function listPolicySetDefinitions() { console.log(resArray); } -listPolicySetDefinitions().catch(console.error); +async function main() { + listPolicySetDefinitions(); +} + +main().catch(console.error); diff --git a/sdk/policy/arm-policy/samples/v5/typescript/tsconfig.json b/sdk/policy/arm-policy/samples/v5/typescript/tsconfig.json index 416c2dd82e00..e26ce2a6d8f7 100644 --- a/sdk/policy/arm-policy/samples/v5/typescript/tsconfig.json +++ b/sdk/policy/arm-policy/samples/v5/typescript/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "ES2018", + "target": "ES2020", "module": "commonjs", "moduleResolution": "node", "resolveJsonModule": true, diff --git a/sdk/policy/arm-policy/src/models/index.ts b/sdk/policy/arm-policy/src/models/index.ts index 3b908666e92e..43f12f588453 100644 --- a/sdk/policy/arm-policy/src/models/index.ts +++ b/sdk/policy/arm-policy/src/models/index.ts @@ -701,10 +701,7 @@ export type DataPolicyManifestsListResponse = DataPolicyManifestListResult; /** Optional parameters. */ export interface DataPolicyManifestsListNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: "namespace eq '{value}'". If $filter is not provided, no filtering is performed. If $filter=namespace eq '{value}' is provided, the returned list only includes all data policy manifests that have a namespace matching the provided value. */ - filter?: string; -} + extends coreClient.OperationOptions {} /** Contains response data for the listNext operation. */ export type DataPolicyManifestsListNextResponse = DataPolicyManifestListResult; @@ -815,48 +812,28 @@ export type PolicyAssignmentsUpdateByIdResponse = PolicyAssignment; /** Optional parameters. */ export interface PolicyAssignmentsListForResourceGroupNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering is performed. If $filter=atScope() is provided, the returned list only includes all policy assignments that apply to the scope, which is everything in the unfiltered list except those applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the given scope. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value}. */ - filter?: string; - /** Maximum number of records to return. When the $top filter is not provided, it will return 500 records. */ - top?: number; -} + extends coreClient.OperationOptions {} /** Contains response data for the listForResourceGroupNext operation. */ export type PolicyAssignmentsListForResourceGroupNextResponse = PolicyAssignmentListResult; /** Optional parameters. */ export interface PolicyAssignmentsListForResourceNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering is performed. If $filter=atScope() is provided, the returned list only includes all policy assignments that apply to the scope, which is everything in the unfiltered list except those applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the given scope. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value}. */ - filter?: string; - /** Maximum number of records to return. When the $top filter is not provided, it will return 500 records. */ - top?: number; -} + extends coreClient.OperationOptions {} /** Contains response data for the listForResourceNext operation. */ export type PolicyAssignmentsListForResourceNextResponse = PolicyAssignmentListResult; /** Optional parameters. */ export interface PolicyAssignmentsListForManagementGroupNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering is performed. If $filter=atScope() is provided, the returned list only includes all policy assignments that apply to the scope, which is everything in the unfiltered list except those applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the given scope. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value}. */ - filter?: string; - /** Maximum number of records to return. When the $top filter is not provided, it will return 500 records. */ - top?: number; -} + extends coreClient.OperationOptions {} /** Contains response data for the listForManagementGroupNext operation. */ export type PolicyAssignmentsListForManagementGroupNextResponse = PolicyAssignmentListResult; /** Optional parameters. */ export interface PolicyAssignmentsListNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering is performed. If $filter=atScope() is provided, the returned list only includes all policy assignments that apply to the scope, which is everything in the unfiltered list except those applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the given scope. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value}. */ - filter?: string; - /** Maximum number of records to return. When the $top filter is not provided, it will return 500 records. */ - top?: number; -} + extends coreClient.OperationOptions {} /** Contains response data for the listNext operation. */ export type PolicyAssignmentsListNextResponse = PolicyAssignmentListResult; @@ -942,36 +919,21 @@ export type PolicyDefinitionsListByManagementGroupResponse = PolicyDefinitionLis /** Optional parameters. */ export interface PolicyDefinitionsListNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list only includes all policy definitions that at the given scope. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all policy definitions whose category match the {value}. */ - filter?: string; - /** Maximum number of records to return. When the $top filter is not provided, it will return 500 records. */ - top?: number; -} + extends coreClient.OperationOptions {} /** Contains response data for the listNext operation. */ export type PolicyDefinitionsListNextResponse = PolicyDefinitionListResult; /** Optional parameters. */ export interface PolicyDefinitionsListBuiltInNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list only includes all policy definitions that at the given scope. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all policy definitions whose category match the {value}. */ - filter?: string; - /** Maximum number of records to return. When the $top filter is not provided, it will return 500 records. */ - top?: number; -} + extends coreClient.OperationOptions {} /** Contains response data for the listBuiltInNext operation. */ export type PolicyDefinitionsListBuiltInNextResponse = PolicyDefinitionListResult; /** Optional parameters. */ export interface PolicyDefinitionsListByManagementGroupNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list only includes all policy definitions that at the given scope. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all policy definitions whose category match the {value}. */ - filter?: string; - /** Maximum number of records to return. When the $top filter is not provided, it will return 500 records. */ - top?: number; -} + extends coreClient.OperationOptions {} /** Contains response data for the listByManagementGroupNext operation. */ export type PolicyDefinitionsListByManagementGroupNextResponse = PolicyDefinitionListResult; @@ -1057,36 +1019,21 @@ export type PolicySetDefinitionsListByManagementGroupResponse = PolicySetDefinit /** Optional parameters. */ export interface PolicySetDefinitionsListNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list only includes all policy set definitions that at the given scope. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy set definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all policy set definitions whose category match the {value}. */ - filter?: string; - /** Maximum number of records to return. When the $top filter is not provided, it will return 500 records. */ - top?: number; -} + extends coreClient.OperationOptions {} /** Contains response data for the listNext operation. */ export type PolicySetDefinitionsListNextResponse = PolicySetDefinitionListResult; /** Optional parameters. */ export interface PolicySetDefinitionsListBuiltInNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list only includes all policy set definitions that at the given scope. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy set definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all policy set definitions whose category match the {value}. */ - filter?: string; - /** Maximum number of records to return. When the $top filter is not provided, it will return 500 records. */ - top?: number; -} + extends coreClient.OperationOptions {} /** Contains response data for the listBuiltInNext operation. */ export type PolicySetDefinitionsListBuiltInNextResponse = PolicySetDefinitionListResult; /** Optional parameters. */ export interface PolicySetDefinitionsListByManagementGroupNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list only includes all policy set definitions that at the given scope. If $filter='policyType -eq {value}' is provided, the returned list only includes all policy set definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the returned list only includes all policy set definitions whose category match the {value}. */ - filter?: string; - /** Maximum number of records to return. When the $top filter is not provided, it will return 500 records. */ - top?: number; -} + extends coreClient.OperationOptions {} /** Contains response data for the listByManagementGroupNext operation. */ export type PolicySetDefinitionsListByManagementGroupNextResponse = PolicySetDefinitionListResult; @@ -1151,40 +1098,28 @@ export type PolicyExemptionsListForManagementGroupResponse = PolicyExemptionList /** Optional parameters. */ export interface PolicyExemptionsListNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, no filtering is performed. If $filter is not provided, the unfiltered list includes all policy exemptions associated with the scope, including those that apply directly or apply from containing scopes. If $filter=atScope() is provided, the returned list only includes all policy exemptions that apply to the scope, which is everything in the unfiltered list except those applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, the returned list only includes all policy exemptions that at the given scope. If $filter=excludeExpired() is provided, the returned list only includes all policy exemptions that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq '{value}' is provided. the returned list only includes all policy exemptions that are associated with the give policyAssignmentId. */ - filter?: string; -} + extends coreClient.OperationOptions {} /** Contains response data for the listNext operation. */ export type PolicyExemptionsListNextResponse = PolicyExemptionListResult; /** Optional parameters. */ export interface PolicyExemptionsListForResourceGroupNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, no filtering is performed. If $filter is not provided, the unfiltered list includes all policy exemptions associated with the scope, including those that apply directly or apply from containing scopes. If $filter=atScope() is provided, the returned list only includes all policy exemptions that apply to the scope, which is everything in the unfiltered list except those applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, the returned list only includes all policy exemptions that at the given scope. If $filter=excludeExpired() is provided, the returned list only includes all policy exemptions that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq '{value}' is provided. the returned list only includes all policy exemptions that are associated with the give policyAssignmentId. */ - filter?: string; -} + extends coreClient.OperationOptions {} /** Contains response data for the listForResourceGroupNext operation. */ export type PolicyExemptionsListForResourceGroupNextResponse = PolicyExemptionListResult; /** Optional parameters. */ export interface PolicyExemptionsListForResourceNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, no filtering is performed. If $filter is not provided, the unfiltered list includes all policy exemptions associated with the scope, including those that apply directly or apply from containing scopes. If $filter=atScope() is provided, the returned list only includes all policy exemptions that apply to the scope, which is everything in the unfiltered list except those applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, the returned list only includes all policy exemptions that at the given scope. If $filter=excludeExpired() is provided, the returned list only includes all policy exemptions that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq '{value}' is provided. the returned list only includes all policy exemptions that are associated with the give policyAssignmentId. */ - filter?: string; -} + extends coreClient.OperationOptions {} /** Contains response data for the listForResourceNext operation. */ export type PolicyExemptionsListForResourceNextResponse = PolicyExemptionListResult; /** Optional parameters. */ export interface PolicyExemptionsListForManagementGroupNextOptionalParams - extends coreClient.OperationOptions { - /** The filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, no filtering is performed. If $filter is not provided, the unfiltered list includes all policy exemptions associated with the scope, including those that apply directly or apply from containing scopes. If $filter=atScope() is provided, the returned list only includes all policy exemptions that apply to the scope, which is everything in the unfiltered list except those applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, the returned list only includes all policy exemptions that at the given scope. If $filter=excludeExpired() is provided, the returned list only includes all policy exemptions that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq '{value}' is provided. the returned list only includes all policy exemptions that are associated with the give policyAssignmentId. */ - filter?: string; -} + extends coreClient.OperationOptions {} /** Contains response data for the listForManagementGroupNext operation. */ export type PolicyExemptionsListForManagementGroupNextResponse = PolicyExemptionListResult; diff --git a/sdk/policy/arm-policy/src/operations/dataPolicyManifests.ts b/sdk/policy/arm-policy/src/operations/dataPolicyManifests.ts index 83dc011f316b..9f4abd98aba3 100644 --- a/sdk/policy/arm-policy/src/operations/dataPolicyManifests.ts +++ b/sdk/policy/arm-policy/src/operations/dataPolicyManifests.ts @@ -184,7 +184,6 @@ const listNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.apiVersion, Parameters.filter], urlParameters: [Parameters.$host, Parameters.nextLink], headerParameters: [Parameters.accept], serializer diff --git a/sdk/policy/arm-policy/src/operations/policyAssignments.ts b/sdk/policy/arm-policy/src/operations/policyAssignments.ts index ec9936e33a4a..7711d4d9b20b 100644 --- a/sdk/policy/arm-policy/src/operations/policyAssignments.ts +++ b/sdk/policy/arm-policy/src/operations/policyAssignments.ts @@ -1065,7 +1065,6 @@ const listForResourceGroupNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.filter, Parameters.apiVersion1, Parameters.top], urlParameters: [ Parameters.$host, Parameters.nextLink, @@ -1086,7 +1085,6 @@ const listForResourceNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.filter, Parameters.apiVersion1, Parameters.top], urlParameters: [ Parameters.$host, Parameters.nextLink, @@ -1111,7 +1109,6 @@ const listForManagementGroupNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.filter, Parameters.apiVersion1, Parameters.top], urlParameters: [ Parameters.$host, Parameters.nextLink, @@ -1131,7 +1128,6 @@ const listNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.filter, Parameters.apiVersion1, Parameters.top], urlParameters: [ Parameters.$host, Parameters.nextLink, diff --git a/sdk/policy/arm-policy/src/operations/policyDefinitions.ts b/sdk/policy/arm-policy/src/operations/policyDefinitions.ts index 29d4669b75cb..32335b3819ff 100644 --- a/sdk/policy/arm-policy/src/operations/policyDefinitions.ts +++ b/sdk/policy/arm-policy/src/operations/policyDefinitions.ts @@ -688,7 +688,6 @@ const listNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.filter, Parameters.apiVersion1, Parameters.top], urlParameters: [ Parameters.$host, Parameters.nextLink, @@ -708,7 +707,6 @@ const listBuiltInNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.filter, Parameters.apiVersion1, Parameters.top], urlParameters: [Parameters.$host, Parameters.nextLink], headerParameters: [Parameters.accept], serializer @@ -724,7 +722,6 @@ const listByManagementGroupNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.filter, Parameters.apiVersion1, Parameters.top], urlParameters: [ Parameters.$host, Parameters.nextLink, diff --git a/sdk/policy/arm-policy/src/operations/policyExemptions.ts b/sdk/policy/arm-policy/src/operations/policyExemptions.ts index b2584258caf4..917606661363 100644 --- a/sdk/policy/arm-policy/src/operations/policyExemptions.ts +++ b/sdk/policy/arm-policy/src/operations/policyExemptions.ts @@ -804,7 +804,6 @@ const listNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.filter, Parameters.apiVersion2], urlParameters: [ Parameters.$host, Parameters.nextLink, @@ -824,7 +823,6 @@ const listForResourceGroupNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.filter, Parameters.apiVersion2], urlParameters: [ Parameters.$host, Parameters.nextLink, @@ -845,7 +843,6 @@ const listForResourceNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.filter, Parameters.apiVersion2], urlParameters: [ Parameters.$host, Parameters.nextLink, @@ -870,7 +867,6 @@ const listForManagementGroupNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.filter, Parameters.apiVersion2], urlParameters: [ Parameters.$host, Parameters.nextLink, diff --git a/sdk/policy/arm-policy/src/operations/policySetDefinitions.ts b/sdk/policy/arm-policy/src/operations/policySetDefinitions.ts index 41ddd5716f4a..0a2a26cd3d2d 100644 --- a/sdk/policy/arm-policy/src/operations/policySetDefinitions.ts +++ b/sdk/policy/arm-policy/src/operations/policySetDefinitions.ts @@ -692,7 +692,6 @@ const listNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.filter, Parameters.apiVersion1, Parameters.top], urlParameters: [ Parameters.$host, Parameters.nextLink, @@ -712,7 +711,6 @@ const listBuiltInNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.filter, Parameters.apiVersion1, Parameters.top], urlParameters: [Parameters.$host, Parameters.nextLink], headerParameters: [Parameters.accept], serializer @@ -728,7 +726,6 @@ const listByManagementGroupNextOperationSpec: coreClient.OperationSpec = { bodyMapper: Mappers.CloudError } }, - queryParameters: [Parameters.filter, Parameters.apiVersion1, Parameters.top], urlParameters: [ Parameters.$host, Parameters.nextLink, diff --git a/sdk/policy/arm-policy/src/pagingHelper.ts b/sdk/policy/arm-policy/src/pagingHelper.ts index d85fc13bce1e..269a2b9814b5 100644 --- a/sdk/policy/arm-policy/src/pagingHelper.ts +++ b/sdk/policy/arm-policy/src/pagingHelper.ts @@ -13,11 +13,11 @@ export interface PageInfo { const pageMap = new WeakMap(); /** - * Given a result page from a pageable operation, returns a - * continuation token that can be used to begin paging from + * Given the last `.value` produced by the `byPage` iterator, + * returns a continuation token that can be used to begin paging from * that point later. - * @param page A result object from calling .byPage() on a paged operation. - * @returns The continuation token that can be passed into byPage(). + * @param page An object from accessing `value` on the IteratorResult from a `byPage` iterator. + * @returns The continuation token that can be passed into byPage() during future calls. */ export function getContinuationToken(page: unknown): string | undefined { if (typeof page !== "object" || page === null) { diff --git a/sdk/policy/arm-policy/src/policyClient.ts b/sdk/policy/arm-policy/src/policyClient.ts index 55575a71c63a..457609e7fedf 100644 --- a/sdk/policy/arm-policy/src/policyClient.ts +++ b/sdk/policy/arm-policy/src/policyClient.ts @@ -27,7 +27,7 @@ import { PolicyClientOptionalParams } from "./models"; export class PolicyClient extends coreClient.ServiceClient { $host: string; - subscriptionId: string; + subscriptionId?: string; /** * Initializes a new instance of the PolicyClient class. @@ -39,12 +39,27 @@ export class PolicyClient extends coreClient.ServiceClient { credentials: coreAuth.TokenCredential, subscriptionId: string, options?: PolicyClientOptionalParams + ); + constructor( + credentials: coreAuth.TokenCredential, + options?: PolicyClientOptionalParams + ); + constructor( + credentials: coreAuth.TokenCredential, + subscriptionIdOrOptions?: string | PolicyClientOptionalParams, + options?: PolicyClientOptionalParams ) { if (credentials === undefined) { throw new Error("'credentials' cannot be null"); } - if (subscriptionId === undefined) { - throw new Error("'subscriptionId' cannot be null"); + let subscriptionId: string | undefined; + + if (!subscriptionIdOrOptions !== undefined) { + if (typeof subscriptionIdOrOptions === "string") { + subscriptionId = subscriptionIdOrOptions; + } else if (typeof subscriptionIdOrOptions === "object") { + options = subscriptionIdOrOptions; + } } // Initializing default values for options @@ -56,7 +71,7 @@ export class PolicyClient extends coreClient.ServiceClient { credential: credentials }; - const packageDetails = `azsdk-js-arm-policy/5.0.4`; + const packageDetails = `azsdk-js-arm-policy/5.1.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}` diff --git a/sdk/policy/arm-policy/test/policy_examples.ts b/sdk/policy/arm-policy/test/policy_examples.ts index b999ca594247..d7c1103092c3 100644 --- a/sdk/policy/arm-policy/test/policy_examples.ts +++ b/sdk/policy/arm-policy/test/policy_examples.ts @@ -38,6 +38,7 @@ describe("Policy test", () => { let recorder: Recorder; let subscriptionId: string; let client: PolicyClient; + let client1: PolicyClient; let location: string; let resourceGroup: string; let groupId: string; @@ -60,6 +61,7 @@ describe("Policy test", () => { policyName = "jspolicy"; scope = "providers/Microsoft.Management/managementgroups/20000000-0001-0000-0000-000000000123/"; policyAssignmentName = "passigment"; + client1 = new PolicyClient(credential, recorder.configureClientOptions({})); }); afterEach(async function () { @@ -110,8 +112,8 @@ describe("Policy test", () => { }); it("policyAssignments create test", async function () { - const definition = await client.policyDefinitions.getAtManagementGroup(policyName, groupId); - const res = await client.policyAssignments.create(scope, policyAssignmentName, { + const definition = await client1.policyDefinitions.getAtManagementGroup(policyName, groupId); + const res = await client1.policyAssignments.create(scope, policyAssignmentName, { policyDefinitionId: definition.id }) assert.equal(res.name, policyAssignmentName); @@ -130,6 +132,17 @@ describe("Policy test", () => { assert.notEqual(resArray.length, 0); }); + it("policyAssignments list by managementgroup test", async function () { + const filter = "atScope()"; + const resArray = new Array(); + for await (let item of client1.policyAssignments.listForManagementGroup(groupId, { + filter + })) { + resArray.push(item); + } + assert.notEqual(resArray.length, 0); + }); + it("policyAssignments delete test", async function () { const res = await client.policyAssignments.delete(scope, policyAssignmentName); const resArray = new Array();