Skip to content

Commit c9dcb43

Browse files
[Recorder] configureClientOptions method on the recorder (Azure#20175)
* configureClientOptions core-v2 * configureClientOptions * & Record<string, unknown> * Replicate Azure#19920 for core-client-rest * formatting * Replicate Azure#19920 for core-client-rest * format * attestation test fixes * format * more format * format * more recorder.configureClientOptions * migration guide * more format * mixed-reality update * attestation simplification * more fixes * changelogs and gettingstarted docs * format * format * changelog * tables ci - test-proxy variable * env.SAS_CONNECTION_STRING test fix * sort imports
1 parent b92879e commit c9dcb43

File tree

29 files changed

+209
-140
lines changed

29 files changed

+209
-140
lines changed

sdk/attestation/attestation/CHANGELOG.md

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
### Bugs Fixed
1010

11+
Fixed a bug where the client options are ignored when passed along with an AAD credential.
12+
[#20175](https://github.com/Azure/azure-sdk-for-js/pull/20175)
13+
1114
### Other Changes
1215

1316
## 1.0.0 (2021-08-10)
@@ -24,50 +27,50 @@ and Buffer objects as inputs.
2427

2528
### Breaking Changes
2629

27-
* Reversed the order of `credentials` and `endpoint` in `AttestationAdministrationClient` to be
30+
- Reversed the order of `credentials` and `endpoint` in `AttestationAdministrationClient` to be
2831
consistent with other SDKs.
29-
* Removed `credentials` top level parameter for `AttestationClient` constructor, moved
32+
- Removed `credentials` top level parameter for `AttestationClient` constructor, moved
3033
to the `AttestationClientOptions` object.
31-
* Renamed the `validateToken` API in the `AttestationToken` class to `getTokenProblems` returning
34+
- Renamed the `validateToken` API in the `AttestationToken` class to `getTokenProblems` returning
3235
an array of strings.
33-
* Attestation Policy APIs (`setPolicy`, `resetPolicy`) have had their `privateKey` and `certificate` parameters moved to options.
34-
* Renamed `instanceUrl` to `endpoint` to be consistent with other APIs.
35-
* Removed `policyCertificates` from `AttestationAdministrationClient`.
36-
* Removed `StoredAttestationPolicy` and replaced it with `AttestationPolicyToken`.
37-
* Removed `AttestationData` type. Instead of specifying an `AttestationData` for `initTimeData` and `runTimeData` to the Attest APIs, the attest APIs take an `initTimeJson`, `initTimeData`, `runTimeData` and `runTimeJson` object and determine
38-
the `DataType` to send to the server based on that.
39-
* Removed the `AttestationSigningKey` model type replaced with two parameters
36+
- Attestation Policy APIs (`setPolicy`, `resetPolicy`) have had their `privateKey` and `certificate` parameters moved to options.
37+
- Renamed `instanceUrl` to `endpoint` to be consistent with other APIs.
38+
- Removed `policyCertificates` from `AttestationAdministrationClient`.
39+
- Removed `StoredAttestationPolicy` and replaced it with `AttestationPolicyToken`.
40+
- Removed `AttestationData` type. Instead of specifying an `AttestationData` for `initTimeData` and `runTimeData` to the Attest APIs, the attest APIs take an `initTimeJson`, `initTimeData`, `runTimeData` and `runTimeJson` object and determine
41+
the `DataType` to send to the server based on that.
42+
- Removed the `AttestationSigningKey` model type replaced with two parameters
4043
`privateKey` and `certificate` to the APIs which used to accept an `AttestationSigningKey`
41-
* Renamed `AttestationResponse.value` to `AttestationResponse.body` to align with
42-
API guidelines.
44+
- Renamed `AttestationResponse.value` to `AttestationResponse.body` to align with
45+
API guidelines.
4346

4447
## 1.0.0-beta.4 (2021-06-15)
4548

4649
### Features Added
4750

48-
* The package now contains type definitions compatible with TypeScript versions earlier than v3.6.
51+
- The package now contains type definitions compatible with TypeScript versions earlier than v3.6.
4952

5053
### Key Bugs Fixed
5154

52-
* Fixes the location of types definition in package.json
55+
- Fixes the location of types definition in package.json
5356

5457
## 1.0.0-beta.3 (2021-06-08)
5558

5659
### Features Added
5760

5861
### Breaking Changes
5962

60-
* Essentially completely rewritten. All existing functionality has been replaced.
61-
* Removed `policy` property on `AttestationClient` object, because it has been replaced.
62-
* Removed `policy.reset` and `policy.set`, replaced with the `resetPolicy` and `setPolicy` methods on the `AttestationAdministrationClient`.
63-
* Removed `policy.get`, replaced with the `getPolicy` method of the new `AttestationAdministrationClient` client object.
64-
* Removed `attestation.attestSgxEnclave`, `attestation.attestOpenEnclave`, `attestation.attestTpm`, and `attestation` property from attestationClient, replaced with `attestSgxEnclave`, `attestOpenEnclave` and `attestTpm`.
65-
* Removed `metadataConfiguration` and `signingCertificates` properties from attestationClient.
66-
* Removed `metadataConfiguration.get()` method, replaced with `client.getOpenIdMetadata()`.
67-
* Removed `signingCertificates.get()` method, replaced with `client.getAttestationSigners()`. The return value for `getAttestationSigners()` is an array of `AttestationSigner` objects,
68-
each of which has two properties: `key_id` and `certificates`. `key_id`
69-
reflects the `kid` JSON Web Key attribute, and `certificates` is the **decoded** `x5c` attribute
70-
in the JSON Web Key.
63+
- Essentially completely rewritten. All existing functionality has been replaced.
64+
- Removed `policy` property on `AttestationClient` object, because it has been replaced.
65+
- Removed `policy.reset` and `policy.set`, replaced with the `resetPolicy` and `setPolicy` methods on the `AttestationAdministrationClient`.
66+
- Removed `policy.get`, replaced with the `getPolicy` method of the new `AttestationAdministrationClient` client object.
67+
- Removed `attestation.attestSgxEnclave`, `attestation.attestOpenEnclave`, `attestation.attestTpm`, and `attestation` property from attestationClient, replaced with `attestSgxEnclave`, `attestOpenEnclave` and `attestTpm`.
68+
- Removed `metadataConfiguration` and `signingCertificates` properties from attestationClient.
69+
- Removed `metadataConfiguration.get()` method, replaced with `client.getOpenIdMetadata()`.
70+
- Removed `signingCertificates.get()` method, replaced with `client.getAttestationSigners()`. The return value for `getAttestationSigners()` is an array of `AttestationSigner` objects,
71+
each of which has two properties: `key_id` and `certificates`. `key_id`
72+
reflects the `kid` JSON Web Key attribute, and `certificates` is the **decoded** `x5c` attribute
73+
in the JSON Web Key.
7174

7275
## 1.0.0-beta.2 (2021-01-19)
7376

@@ -77,4 +80,4 @@ Regenerated Attestation SDK. The properties alg, kid and use in JsonWebKey objec
7780

7881
Initial early preview release for MAA Data Plane SDK Demonstrates use of the machine generated MAA APIs.
7982

80-
* Initial Release
83+
- Initial Release

sdk/attestation/attestation/src/attestationClient.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,14 @@ export class AttestationClient {
187187
) {
188188
let credentialScopes: string[] | undefined = undefined;
189189
let credential: TokenCredential | undefined = undefined;
190-
let options: AttestationClientOptions = {};
190+
let options: AttestationClientOptions;
191191

192-
// If arg2 is defined, it's either a tokenCredential or it's a client options.
193-
if (credentialsOrOptions !== undefined) {
194-
if (isTokenCredential(credentialsOrOptions)) {
195-
credential = credentialsOrOptions;
196-
credentialScopes = ["https://attest.azure.net/.default"];
197-
} else {
198-
options = credentialsOrOptions;
199-
}
200-
} else if (clientOptions !== undefined) {
192+
if (credentialsOrOptions && isTokenCredential(credentialsOrOptions)) {
193+
credential = credentialsOrOptions;
194+
credentialScopes = ["https://attest.azure.net/.default"];
201195
options = clientOptions;
196+
} else {
197+
options = credentialsOrOptions || {};
202198
}
203199

204200
const internalPipelineOptions: GeneratedClientOptionalParams = {

sdk/attestation/attestation/test/public/attestationTests.spec.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,15 @@ describe("[AAD] Attestation Client", function () {
197197
const binaryRuntimeData = base64url.decodeString(_runtimeData);
198198
const client = createRecordedClient(recorder, endpointType);
199199

200-
{
201-
// You can't specify both runtimeData and runtimeJson.
202-
await expect(
203-
client.attestOpenEnclave(base64url.decodeString(_openEnclaveReport).subarray(0x10), {
204-
runTimeData: binaryRuntimeData,
205-
runTimeJson: binaryRuntimeData,
206-
})
207-
).to.eventually.be.rejectedWith("Cannot provide both runTimeData and runTimeJson");
208-
}
200+
// You can't specify both runtimeData and runtimeJson.
201+
await assert.isRejected(
202+
client.attestOpenEnclave(base64url.decodeString(_openEnclaveReport).subarray(0x10), {
203+
runTimeData: binaryRuntimeData,
204+
runTimeJson: binaryRuntimeData,
205+
}),
206+
"Cannot provide both runTimeData and runTimeJson.",
207+
"Expected to throw since you can't specify both runtimeData and runtimeJson"
208+
);
209209

210210
{
211211
const attestationResult = await client.attestOpenEnclave(
@@ -251,15 +251,14 @@ describe("[AAD] Attestation Client", function () {
251251

252252
const binaryRuntimeData = base64url.decodeString(_runtimeData);
253253

254-
{
255-
// You can't specify both runtimeData and runtimeJson.
256-
await expect(
257-
client.attestSgxEnclave(base64url.decodeString(_openEnclaveReport).subarray(0x10), {
258-
runTimeData: binaryRuntimeData,
259-
runTimeJson: binaryRuntimeData,
260-
})
261-
).to.eventually.be.rejectedWith("Cannot provide both runTimeData and runTimeJson");
262-
}
254+
await assert.isRejected(
255+
client.attestSgxEnclave(base64url.decodeString(_openEnclaveReport).subarray(0x10), {
256+
runTimeData: binaryRuntimeData,
257+
runTimeJson: binaryRuntimeData,
258+
}),
259+
"Cannot provide both runTimeData and runTimeJson.",
260+
"Expected to throw since you can't specify both runtimeData and runtimeJson"
261+
);
263262

264263
{
265264
// An OpenEnclave report has a 16 byte header prepended to an SGX quote.

sdk/attestation/attestation/test/utils/recordedClient.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,18 @@ export function createRecordedClient(
9292
},
9393
};
9494
}
95-
if (authenticatedClient !== undefined && authenticatedClient) {
95+
if (authenticatedClient) {
9696
const attClient = new AttestationClient(
9797
getAttestationUri(endpointType),
9898
createTestCredential(),
99-
options
99+
recorder.configureClientOptions(options)
100100
);
101-
recorder.configureClient(attClient["_client"]);
102101
return attClient;
103102
}
104-
const attClient = new AttestationClient(getAttestationUri(endpointType), options);
105-
recorder.configureClient(attClient["_client"]);
103+
const attClient = new AttestationClient(
104+
getAttestationUri(endpointType),
105+
recorder.configureClientOptions(options)
106+
);
106107
return attClient;
107108
}
108109

@@ -128,8 +129,7 @@ export function createRecordedAdminClient(
128129
const adminClient = new AttestationAdministrationClient(
129130
getAttestationUri(endpointType),
130131
createTestCredential(),
131-
options
132+
recorder.configureClientOptions(options)
132133
);
133-
recorder.configureClient(adminClient["_client"]);
134134
return adminClient;
135135
}

sdk/deviceupdate/iot-device-update-rest/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"autoPublish": false,
8686
"dependencies": {
8787
"@azure/core-auth": "^1.3.0",
88-
"@azure-rest/core-client": "1.0.0-beta.7",
88+
"@azure-rest/core-client": "1.0.0-beta.9",
8989
"@azure/core-rest-pipeline": "^1.1.0",
9090
"@azure/logger": "^1.0.0",
9191
"tslib": "^2.2.0",

sdk/deviceupdate/iot-device-update-rest/test/public/utils/recordedClient.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import { Recorder, assertEnvironmentVariable } from "@azure-tools/test-recorder"
77

88
export function createRecordedClient(recorder: Recorder): DeviceUpdateRestClient {
99
const credential = createTestCredential();
10-
const client = DeviceUpdate(assertEnvironmentVariable("ENDPOINT"), credential);
11-
recorder.configureClient(client);
10+
const client = DeviceUpdate(
11+
assertEnvironmentVariable("ENDPOINT"),
12+
credential,
13+
recorder.configureClientOptions({})
14+
);
1215
return client;
1316
}
1417

sdk/documenttranslator/ai-document-translator-rest/test/public/utils/recordedClient.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export async function createClient(
1919
): Promise<DocumentTranslatorClient> {
2020
await recorder.start({ envSetupForPlayback });
2121
const credential = { key: env.DOCUMENT_TRANSLATOR_API_KEY ?? "" };
22-
const client = DocumentTranslator(env.ENDPOINT ?? "", credential, options);
23-
recorder.configureClient(client);
22+
const client = DocumentTranslator(
23+
env.ENDPOINT ?? "",
24+
credential,
25+
recorder.configureClientOptions(options || {})
26+
);
2427
return client;
2528
}

sdk/remoterendering/mixed-reality-remote-rendering/test/public/remoteRenderingClient.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ describe("RemoteRendering functional tests", () => {
113113
beforeEach(async function (this: Context) {
114114
recorder = createRecorder(this);
115115
await recorder.start(recorderStartOptions);
116-
client = createClient();
117-
recorder.configureClient(client["client"]);
116+
client = createClient(recorder);
118117
});
119118

120119
afterEach(async function () {

sdk/remoterendering/mixed-reality-remote-rendering/test/utils/recordedClient.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const recorderStartOptions: RecorderStartOptions = {
3939
},
4040
};
4141

42-
export function createClient(): RemoteRenderingClient {
42+
export function createClient(recorder: Recorder): RemoteRenderingClient {
4343
const serviceEndpoint = assertEnvironmentVariable("REMOTERENDERING_ARR_SERVICE_ENDPOINT");
4444
const accountDomain = assertEnvironmentVariable("REMOTERENDERING_ARR_ACCOUNT_DOMAIN");
4545
const accountId = assertEnvironmentVariable("REMOTERENDERING_ARR_ACCOUNT_ID");
@@ -50,10 +50,21 @@ export function createClient(): RemoteRenderingClient {
5050
// the AccessToken auth path.
5151
const maxTimestampMs = 8640000000000000;
5252
const credential: AccessToken = { token: "<access_token>", expiresOnTimestamp: maxTimestampMs };
53-
return new RemoteRenderingClient(serviceEndpoint, accountId, credential);
53+
return new RemoteRenderingClient(
54+
serviceEndpoint,
55+
accountId,
56+
credential,
57+
recorder.configureClientOptions({})
58+
);
5459
} else {
5560
const credential: AzureKeyCredential = new AzureKeyCredential(accountKey);
56-
return new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
61+
return new RemoteRenderingClient(
62+
serviceEndpoint,
63+
accountId,
64+
accountDomain,
65+
credential,
66+
recorder.configureClientOptions({})
67+
);
5768
}
5869
}
5970

sdk/schemaregistry/schema-registry/test/public/utils/recordedClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export function createRecordedClient(recorder: Recorder): SchemaRegistryClient {
2323
const credential = createTestCredential();
2424
const client = new SchemaRegistryClient(
2525
assertEnvironmentVariable("SCHEMA_REGISTRY_ENDPOINT"),
26-
credential
26+
credential,
27+
recorder.configureClientOptions({})
2728
);
28-
recorder.configureClient(client["client"]);
2929
return client;
3030
}

0 commit comments

Comments
 (0)