From 57ed845d5f8b6c756b975fc1c30104311f3ac502 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Thu, 2 Jun 2022 05:57:50 +0000 Subject: [PATCH] CodeGen from PR 19278 in Azure/azure-rest-api-specs remove global config (#19278) --- .../arm-digitaltwins/CHANGELOG.md | 14 +---- sdk/digitaltwins/arm-digitaltwins/_meta.json | 7 ++- .../arm-digitaltwins/package.json | 24 +++----- .../src/azureDigitalTwinsManagementClient.ts | 61 ++++++++++++++++++- .../src/operations/digitalTwins.ts | 12 +++- .../src/operations/digitalTwinsEndpoint.ts | 8 ++- .../operations/privateEndpointConnections.ts | 8 ++- .../timeSeriesDatabaseConnections.ts | 8 ++- .../arm-digitaltwins/test/sampleTest.ts | 39 ++++++------ .../arm-digitaltwins/tsconfig.json | 10 +-- 10 files changed, 121 insertions(+), 70 deletions(-) diff --git a/sdk/digitaltwins/arm-digitaltwins/CHANGELOG.md b/sdk/digitaltwins/arm-digitaltwins/CHANGELOG.md index 91ab453319e0..cf5c2aa4ac22 100644 --- a/sdk/digitaltwins/arm-digitaltwins/CHANGELOG.md +++ b/sdk/digitaltwins/arm-digitaltwins/CHANGELOG.md @@ -1,16 +1,6 @@ # Release History - -## 3.1.0-beta.2 (Unreleased) - -### Features Added - -### Breaking Changes - -### Bugs Fixed - -### Other Changes - -## 3.1.0-beta.1 (2022-03-02) + +## 3.1.0-beta.2 (2022-06-02) **Features** diff --git a/sdk/digitaltwins/arm-digitaltwins/_meta.json b/sdk/digitaltwins/arm-digitaltwins/_meta.json index 0ff4af9e798a..86b18d2be7b3 100644 --- a/sdk/digitaltwins/arm-digitaltwins/_meta.json +++ b/sdk/digitaltwins/arm-digitaltwins/_meta.json @@ -1,7 +1,8 @@ { - "commit": "4042a47cff72c950d35dd72149895b044ed79713", + "commit": "2e59fa3ef47822961f3bde711183859729fc9970", "readme": "specification/digitaltwins/resource-manager/readme.md", - "autorest_command": "autorest --version=3.7.3 --typescript --modelerfour.lenient-model-deduplication --head-as-boolean=true --license-header=MICROSOFT_MIT_NO_VERSION --generate-test --typescript-sdks-folder=D:\\mydev\\azure-sdk-for-js ..\\azure-rest-api-specs\\specification\\digitaltwins\\resource-manager\\readme.md --use=@autorest/typescript@6.0.0-beta.16 --generate-sample=true", + "autorest_command": "autorest --version=3.7.3 --typescript --modelerfour.lenient-model-deduplication --head-as-boolean=true --license-header=MICROSOFT_MIT_NO_VERSION --generate-test --typescript-sdks-folder=/mnt/vss/_work/1/s/azure-sdk-for-js ../azure-rest-api-specs/specification/digitaltwins/resource-manager/readme.md --use=@autorest/typescript@6.0.0-alpha.19.20220425.1", "repository_url": "https://github.com/Azure/azure-rest-api-specs.git", - "use": "@autorest/typescript@6.0.0-beta.16" + "release_tool": "@azure-tools/js-sdk-release-tools@2.3.1", + "use": "@autorest/typescript@6.0.0-alpha.19.20220425.1" } \ No newline at end of file diff --git a/sdk/digitaltwins/arm-digitaltwins/package.json b/sdk/digitaltwins/arm-digitaltwins/package.json index ef0a9413bbbb..81b555ec988c 100644 --- a/sdk/digitaltwins/arm-digitaltwins/package.json +++ b/sdk/digitaltwins/arm-digitaltwins/package.json @@ -11,9 +11,9 @@ "@azure/core-lro": "^2.2.0", "@azure/abort-controller": "^1.0.0", "@azure/core-paging": "^1.2.0", - "@azure/core-client": "^1.0.0", + "@azure/core-client": "^1.5.0", "@azure/core-auth": "^1.3.0", - "@azure/core-rest-pipeline": "^1.1.0", + "@azure/core-rest-pipeline": "^1.8.0", "tslib": "^2.2.0" }, "keywords": [ @@ -40,9 +40,11 @@ "uglify-js": "^3.4.9", "rimraf": "^3.0.0", "@azure/identity": "^2.0.1", - "@azure-tools/test-recorder": "^1.0.0", + "@azure-tools/test-recorder": "^2.0.0", + "@azure-tools/test-credential": "^1.0.0", "mocha": "^7.1.1", - "cross-env": "^7.0.2" + "cross-env": "^7.0.2", + "@azure/dev-tool": "^1.0.0" }, "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/digitaltwins/arm-digitaltwins", "repository": { @@ -93,7 +95,7 @@ "unit-test:node": "cross-env TEST_MODE=playback npm run integration-test:node", "unit-test:browser": "echo skipped", "integration-test": "npm run integration-test:node && npm run integration-test:browser", - "integration-test:node": "mocha -r esm --require ts-node/register --timeout 1200000 --full-trace test/*.ts --reporter ../../../common/tools/mocha-multi-reporter.js", + "integration-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 'test/*.ts'", "integration-test:browser": "echo skipped", "docs": "echo skipped" }, @@ -106,13 +108,5 @@ } ] }, - "autoPublish": true, - "//sampleConfiguration": { - "productName": "", - "productSlugs": [ - "azure" - ], - "disableDocsMs": true, - "apiRefLink": "https://docs.microsoft.com/javascript/api/@azure/arm-digitaltwins?view=azure-node-preview" - } -} + "autoPublish": true +} \ No newline at end of file diff --git a/sdk/digitaltwins/arm-digitaltwins/src/azureDigitalTwinsManagementClient.ts b/sdk/digitaltwins/arm-digitaltwins/src/azureDigitalTwinsManagementClient.ts index 5569d4b42bf1..1618e9056955 100644 --- a/sdk/digitaltwins/arm-digitaltwins/src/azureDigitalTwinsManagementClient.ts +++ b/sdk/digitaltwins/arm-digitaltwins/src/azureDigitalTwinsManagementClient.ts @@ -7,6 +7,12 @@ */ import * as coreClient from "@azure/core-client"; +import * as coreRestPipeline from "@azure/core-rest-pipeline"; +import { + PipelineRequest, + PipelineResponse, + SendRequest +} from "@azure/core-rest-pipeline"; import * as coreAuth from "@azure/core-auth"; import { DigitalTwinsImpl, @@ -73,9 +79,33 @@ export class AzureDigitalTwinsManagementClient extends coreClient.ServiceClient userAgentOptions: { userAgentPrefix }, - baseUri: options.endpoint || "https://management.azure.com" + baseUri: + options.endpoint ?? options.baseUri ?? "https://management.azure.com" }; super(optionsWithDefaults); + + if (options?.pipeline && options.pipeline.getOrderedPolicies().length > 0) { + const pipelinePolicies: coreRestPipeline.PipelinePolicy[] = options.pipeline.getOrderedPolicies(); + const bearerTokenAuthenticationPolicyFound = pipelinePolicies.some( + (pipelinePolicy) => + pipelinePolicy.name === + coreRestPipeline.bearerTokenAuthenticationPolicyName + ); + if (!bearerTokenAuthenticationPolicyFound) { + this.pipeline.removePolicy({ + name: coreRestPipeline.bearerTokenAuthenticationPolicyName + }); + this.pipeline.addPolicy( + coreRestPipeline.bearerTokenAuthenticationPolicy({ + scopes: `${optionsWithDefaults.baseUri}/.default`, + challengeCallbacks: { + authorizeRequestOnChallenge: + coreClient.authorizeRequestOnClaimChallenge + } + }) + ); + } + } // Parameter assignments this.subscriptionId = subscriptionId; @@ -90,6 +120,35 @@ export class AzureDigitalTwinsManagementClient extends coreClient.ServiceClient this.timeSeriesDatabaseConnections = new TimeSeriesDatabaseConnectionsImpl( this ); + this.addCustomApiVersionPolicy(options.apiVersion); + } + + /** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */ + private addCustomApiVersionPolicy(apiVersion?: string) { + if (!apiVersion) { + return; + } + const apiVersionPolicy = { + name: "CustomApiVersionPolicy", + async sendRequest( + request: PipelineRequest, + next: SendRequest + ): Promise { + const param = request.url.split("?"); + if (param.length > 1) { + const newParams = param[1].split("&").map((item) => { + if (item.indexOf("api-version") > -1) { + return item.replace(/(?<==).*$/, apiVersion); + } else { + return item; + } + }); + request.url = param[0] + "?" + newParams.join("&"); + } + return next(request); + } + }; + this.pipeline.addPolicy(apiVersionPolicy); } digitalTwins: DigitalTwins; diff --git a/sdk/digitaltwins/arm-digitaltwins/src/operations/digitalTwins.ts b/sdk/digitaltwins/arm-digitaltwins/src/operations/digitalTwins.ts index e96d914dcab0..0503622ae398 100644 --- a/sdk/digitaltwins/arm-digitaltwins/src/operations/digitalTwins.ts +++ b/sdk/digitaltwins/arm-digitaltwins/src/operations/digitalTwins.ts @@ -227,10 +227,12 @@ export class DigitalTwinsImpl implements DigitalTwins { { resourceGroupName, resourceName, digitalTwinsCreate, options }, createOrUpdateOperationSpec ); - return new LroEngine(lro, { + const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); + await poller.poll(); + return poller; } /** @@ -324,10 +326,12 @@ export class DigitalTwinsImpl implements DigitalTwins { }, updateOperationSpec ); - return new LroEngine(lro, { + const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); + await poller.poll(); + return poller; } /** @@ -412,10 +416,12 @@ export class DigitalTwinsImpl implements DigitalTwins { { resourceGroupName, resourceName, options }, deleteOperationSpec ); - return new LroEngine(lro, { + const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); + await poller.poll(); + return poller; } /** diff --git a/sdk/digitaltwins/arm-digitaltwins/src/operations/digitalTwinsEndpoint.ts b/sdk/digitaltwins/arm-digitaltwins/src/operations/digitalTwinsEndpoint.ts index 81aadd6f7a4f..14c03357f69b 100644 --- a/sdk/digitaltwins/arm-digitaltwins/src/operations/digitalTwinsEndpoint.ts +++ b/sdk/digitaltwins/arm-digitaltwins/src/operations/digitalTwinsEndpoint.ts @@ -206,10 +206,12 @@ export class DigitalTwinsEndpointImpl implements DigitalTwinsEndpoint { }, createOrUpdateOperationSpec ); - return new LroEngine(lro, { + const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); + await poller.poll(); + return poller; } /** @@ -299,10 +301,12 @@ export class DigitalTwinsEndpointImpl implements DigitalTwinsEndpoint { { resourceGroupName, resourceName, endpointName, options }, deleteOperationSpec ); - return new LroEngine(lro, { + const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); + await poller.poll(); + return poller; } /** diff --git a/sdk/digitaltwins/arm-digitaltwins/src/operations/privateEndpointConnections.ts b/sdk/digitaltwins/arm-digitaltwins/src/operations/privateEndpointConnections.ts index 5fdbf2241549..de08be9f1781 100644 --- a/sdk/digitaltwins/arm-digitaltwins/src/operations/privateEndpointConnections.ts +++ b/sdk/digitaltwins/arm-digitaltwins/src/operations/privateEndpointConnections.ts @@ -140,10 +140,12 @@ export class PrivateEndpointConnectionsImpl }, deleteOperationSpec ); - return new LroEngine(lro, { + const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); + await poller.poll(); + return poller; } /** @@ -238,10 +240,12 @@ export class PrivateEndpointConnectionsImpl }, createOrUpdateOperationSpec ); - return new LroEngine(lro, { + const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); + await poller.poll(); + return poller; } /** diff --git a/sdk/digitaltwins/arm-digitaltwins/src/operations/timeSeriesDatabaseConnections.ts b/sdk/digitaltwins/arm-digitaltwins/src/operations/timeSeriesDatabaseConnections.ts index 90a8ca2fff1a..6df55fa15028 100644 --- a/sdk/digitaltwins/arm-digitaltwins/src/operations/timeSeriesDatabaseConnections.ts +++ b/sdk/digitaltwins/arm-digitaltwins/src/operations/timeSeriesDatabaseConnections.ts @@ -212,10 +212,12 @@ export class TimeSeriesDatabaseConnectionsImpl }, createOrUpdateOperationSpec ); - return new LroEngine(lro, { + const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); + await poller.poll(); + return poller; } /** @@ -310,10 +312,12 @@ export class TimeSeriesDatabaseConnectionsImpl }, deleteOperationSpec ); - return new LroEngine(lro, { + const poller = new LroEngine(lro, { resumeFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs }); + await poller.poll(); + return poller; } /** diff --git a/sdk/digitaltwins/arm-digitaltwins/test/sampleTest.ts b/sdk/digitaltwins/arm-digitaltwins/test/sampleTest.ts index 7ed89b043e1b..25aeb3ebcc36 100644 --- a/sdk/digitaltwins/arm-digitaltwins/test/sampleTest.ts +++ b/sdk/digitaltwins/arm-digitaltwins/test/sampleTest.ts @@ -7,35 +7,30 @@ */ import { - env, - record, - RecorderEnvironmentSetup, - Recorder + Recorder, + RecorderStartOptions, + env } from "@azure-tools/test-recorder"; -import * as assert from "assert"; +import { assert } from "chai"; +import { Context } from "mocha"; -const recorderEnvSetup: RecorderEnvironmentSetup = { - replaceableVariables: { - AZURE_CLIENT_ID: "azure_client_id", - AZURE_CLIENT_SECRET: "azure_client_secret", - AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888", - SUBSCRIPTION_ID: "azure_subscription_id" - }, - customizationsOnRecordings: [ - (recording: any): any => - recording.replace( - /"access_token":"[^"]*"/g, - `"access_token":"access_token"` - ) - ], - queryParametersToSkip: [] +const replaceableVariables: Record = { + AZURE_CLIENT_ID: "azure_client_id", + AZURE_CLIENT_SECRET: "azure_client_secret", + AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888", + SUBSCRIPTION_ID: "azure_subscription_id" +}; + +const recorderOptions: RecorderStartOptions = { + envSetupForPlayback: replaceableVariables }; describe("My test", () => { let recorder: Recorder; - beforeEach(async function() { - recorder = record(this, recorderEnvSetup); + beforeEach(async function(this: Context) { + recorder = new Recorder(this.currentTest); + await recorder.start(recorderOptions); }); afterEach(async function() { diff --git a/sdk/digitaltwins/arm-digitaltwins/tsconfig.json b/sdk/digitaltwins/arm-digitaltwins/tsconfig.json index 15e8d9a4ecc7..3e6ae96443f3 100644 --- a/sdk/digitaltwins/arm-digitaltwins/tsconfig.json +++ b/sdk/digitaltwins/arm-digitaltwins/tsconfig.json @@ -15,17 +15,11 @@ ], "declaration": true, "outDir": "./dist-esm", - "importHelpers": true, - "paths": { - "@azure/arm-digitaltwins": [ - "./src/index" - ] - } + "importHelpers": true }, "include": [ "./src/**/*.ts", - "./test/**/*.ts", - "samples-dev/**/*.ts" + "./test/**/*.ts" ], "exclude": [ "node_modules"