Skip to content

Commit a05c590

Browse files
author
SDKAuto
committed
CodeGen from PR 19273 in Azure/azure-rest-api-specs
Merge b91ffac4f3b4981092c1d868dfffd85590e476b8 into 2e59fa3ef47822961f3bde711183859729fc9970
1 parent 9067ea6 commit a05c590

File tree

6 files changed

+92
-61
lines changed

6 files changed

+92
-61
lines changed

sdk/msi/arm-msi/CHANGELOG.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
# Release History
2-
3-
## 2.1.0-beta.2 (Unreleased)
4-
5-
### Features Added
6-
7-
### Breaking Changes
8-
9-
### Bugs Fixed
10-
11-
### Other Changes
12-
13-
## 2.1.0-beta.1 (2022-03-23)
2+
3+
## 2.1.0-beta.2 (2022-06-02)
144

155
**Features**
166

sdk/msi/arm-msi/_meta.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"commit": "82fdf284eea880a8e027c354911a814999a77178",
2+
"commit": "072dca0080f39db3099eb21cf610456e62c16fb2",
33
"readme": "specification/msi/resource-manager/readme.md",
4-
"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:\\work\\azure-sdk-for-js ..\\azure-rest-api-specs\\specification\\msi\\resource-manager\\readme.md --use=@autorest/[email protected]beta.17 --generate-sample=true",
4+
"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/msi/resource-manager/readme.md --use=@autorest/[email protected]alpha.19.20220425.1",
55
"repository_url": "https://github.com/Azure/azure-rest-api-specs.git",
6-
"release_tool": "@azure-tools/js-sdk-release-tools@2.1.3",
7-
"use": "@autorest/[email protected]beta.17"
6+
"release_tool": "@azure-tools/js-sdk-release-tools@2.3.1",
7+
"use": "@autorest/[email protected]alpha.19.20220425.1"
88
}

sdk/msi/arm-msi/package.json

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
},
1010
"dependencies": {
1111
"@azure/core-paging": "^1.2.0",
12-
"@azure/core-client": "^1.0.0",
12+
"@azure/core-client": "^1.5.0",
1313
"@azure/core-auth": "^1.3.0",
14-
"@azure/core-rest-pipeline": "^1.1.0",
14+
"@azure/core-rest-pipeline": "^1.8.0",
1515
"tslib": "^2.2.0"
1616
},
1717
"keywords": [
@@ -38,9 +38,11 @@
3838
"uglify-js": "^3.4.9",
3939
"rimraf": "^3.0.0",
4040
"@azure/identity": "^2.0.1",
41-
"@azure-tools/test-recorder": "^1.0.0",
41+
"@azure-tools/test-recorder": "^2.0.0",
42+
"@azure-tools/test-credential": "^1.0.0",
4243
"mocha": "^7.1.1",
43-
"cross-env": "^7.0.2"
44+
"cross-env": "^7.0.2",
45+
"@azure/dev-tool": "^1.0.0"
4446
},
4547
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/msi/arm-msi",
4648
"repository": {
@@ -91,7 +93,7 @@
9193
"unit-test:node": "cross-env TEST_MODE=playback npm run integration-test:node",
9294
"unit-test:browser": "echo skipped",
9395
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
94-
"integration-test:node": "mocha -r esm --require ts-node/register --timeout 1200000 --full-trace test/*.ts --reporter ../../../common/tools/mocha-multi-reporter.js",
96+
"integration-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 'test/*.ts'",
9597
"integration-test:browser": "echo skipped",
9698
"docs": "echo skipped"
9799
},
@@ -104,13 +106,5 @@
104106
}
105107
]
106108
},
107-
"autoPublish": true,
108-
"//sampleConfiguration": {
109-
"productName": "",
110-
"productSlugs": [
111-
"azure"
112-
],
113-
"disableDocsMs": true,
114-
"apiRefLink": "https://docs.microsoft.com/javascript/api/@azure/arm-msi?view=azure-node-preview"
115-
}
116-
}
109+
"autoPublish": true
110+
}

sdk/msi/arm-msi/src/managedServiceIdentityClient.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
*/
88

99
import * as coreClient from "@azure/core-client";
10+
import * as coreRestPipeline from "@azure/core-rest-pipeline";
11+
import {
12+
PipelineRequest,
13+
PipelineResponse,
14+
SendRequest
15+
} from "@azure/core-rest-pipeline";
1016
import * as coreAuth from "@azure/core-auth";
1117
import {
1218
SystemAssignedIdentitiesImpl,
@@ -71,6 +77,29 @@ export class ManagedServiceIdentityClient extends coreClient.ServiceClient {
7177
options.endpoint ?? options.baseUri ?? "https://management.azure.com"
7278
};
7379
super(optionsWithDefaults);
80+
81+
if (options?.pipeline && options.pipeline.getOrderedPolicies().length > 0) {
82+
const pipelinePolicies: coreRestPipeline.PipelinePolicy[] = options.pipeline.getOrderedPolicies();
83+
const bearerTokenAuthenticationPolicyFound = pipelinePolicies.some(
84+
(pipelinePolicy) =>
85+
pipelinePolicy.name ===
86+
coreRestPipeline.bearerTokenAuthenticationPolicyName
87+
);
88+
if (!bearerTokenAuthenticationPolicyFound) {
89+
this.pipeline.removePolicy({
90+
name: coreRestPipeline.bearerTokenAuthenticationPolicyName
91+
});
92+
this.pipeline.addPolicy(
93+
coreRestPipeline.bearerTokenAuthenticationPolicy({
94+
scopes: `${optionsWithDefaults.baseUri}/.default`,
95+
challengeCallbacks: {
96+
authorizeRequestOnChallenge:
97+
coreClient.authorizeRequestOnClaimChallenge
98+
}
99+
})
100+
);
101+
}
102+
}
74103
// Parameter assignments
75104
this.subscriptionId = subscriptionId;
76105

@@ -80,6 +109,35 @@ export class ManagedServiceIdentityClient extends coreClient.ServiceClient {
80109
this.systemAssignedIdentities = new SystemAssignedIdentitiesImpl(this);
81110
this.operations = new OperationsImpl(this);
82111
this.userAssignedIdentities = new UserAssignedIdentitiesImpl(this);
112+
this.addCustomApiVersionPolicy(options.apiVersion);
113+
}
114+
115+
/** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */
116+
private addCustomApiVersionPolicy(apiVersion?: string) {
117+
if (!apiVersion) {
118+
return;
119+
}
120+
const apiVersionPolicy = {
121+
name: "CustomApiVersionPolicy",
122+
async sendRequest(
123+
request: PipelineRequest,
124+
next: SendRequest
125+
): Promise<PipelineResponse> {
126+
const param = request.url.split("?");
127+
if (param.length > 1) {
128+
const newParams = param[1].split("&").map((item) => {
129+
if (item.indexOf("api-version") > -1) {
130+
return item.replace(/(?<==).*$/, apiVersion);
131+
} else {
132+
return item;
133+
}
134+
});
135+
request.url = param[0] + "?" + newParams.join("&");
136+
}
137+
return next(request);
138+
}
139+
};
140+
this.pipeline.addPolicy(apiVersionPolicy);
83141
}
84142

85143
systemAssignedIdentities: SystemAssignedIdentities;

sdk/msi/arm-msi/test/sampleTest.ts

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,30 @@
77
*/
88

99
import {
10-
env,
11-
record,
12-
RecorderEnvironmentSetup,
13-
Recorder
10+
Recorder,
11+
RecorderStartOptions,
12+
env
1413
} from "@azure-tools/test-recorder";
15-
import * as assert from "assert";
14+
import { assert } from "chai";
15+
import { Context } from "mocha";
1616

17-
const recorderEnvSetup: RecorderEnvironmentSetup = {
18-
replaceableVariables: {
19-
AZURE_CLIENT_ID: "azure_client_id",
20-
AZURE_CLIENT_SECRET: "azure_client_secret",
21-
AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888",
22-
SUBSCRIPTION_ID: "azure_subscription_id"
23-
},
24-
customizationsOnRecordings: [
25-
(recording: any): any =>
26-
recording.replace(
27-
/"access_token":"[^"]*"/g,
28-
`"access_token":"access_token"`
29-
)
30-
],
31-
queryParametersToSkip: []
17+
const replaceableVariables: Record<string, string> = {
18+
AZURE_CLIENT_ID: "azure_client_id",
19+
AZURE_CLIENT_SECRET: "azure_client_secret",
20+
AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888",
21+
SUBSCRIPTION_ID: "azure_subscription_id"
22+
};
23+
24+
const recorderOptions: RecorderStartOptions = {
25+
envSetupForPlayback: replaceableVariables
3226
};
3327

3428
describe("My test", () => {
3529
let recorder: Recorder;
3630

37-
beforeEach(async function() {
38-
recorder = record(this, recorderEnvSetup);
31+
beforeEach(async function(this: Context) {
32+
recorder = new Recorder(this.currentTest);
33+
await recorder.start(recorderOptions);
3934
});
4035

4136
afterEach(async function() {

sdk/msi/arm-msi/tsconfig.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,11 @@
1515
],
1616
"declaration": true,
1717
"outDir": "./dist-esm",
18-
"importHelpers": true,
19-
"paths": {
20-
"@azure/arm-msi": [
21-
"./src/index"
22-
]
23-
}
18+
"importHelpers": true
2419
},
2520
"include": [
2621
"./src/**/*.ts",
27-
"./test/**/*.ts",
28-
"samples-dev/**/*.ts"
22+
"./test/**/*.ts"
2923
],
3024
"exclude": [
3125
"node_modules"

0 commit comments

Comments
 (0)