Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Recorder] configureClientOptions method on the recorder #20175

Merged
merged 33 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
88fe779
configureClientOptions core-v2
HarshaNalluru Jan 31, 2022
00eb82e
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Feb 1, 2022
8048e9e
configureClientOptions
HarshaNalluru Feb 1, 2022
e1626ca
& Record<string, unknown>
HarshaNalluru Feb 1, 2022
a6d1b95
Replicate https://github.com/Azure/azure-sdk-for-js/pull/19920 for co…
HarshaNalluru Feb 2, 2022
6c29355
formatting
HarshaNalluru Feb 2, 2022
5885760
Replicate https://github.com/Azure/azure-sdk-for-js/pull/19920 for co…
HarshaNalluru Feb 2, 2022
e44fe9c
format
HarshaNalluru Feb 2, 2022
c64883f
Merge branch 'harshan/issue/16876-rest' of https://github.com/HarshaN…
HarshaNalluru Feb 2, 2022
bf8bd52
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Feb 4, 2022
2eaf778
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Feb 4, 2022
fe5fb23
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Feb 4, 2022
8822738
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Feb 4, 2022
4f84663
attestation test fixes
HarshaNalluru Feb 4, 2022
0ce0ed3
format
HarshaNalluru Feb 4, 2022
5fc3208
more format
HarshaNalluru Feb 4, 2022
4340a71
format
HarshaNalluru Feb 4, 2022
b5fa677
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Feb 4, 2022
f65c68a
more recorder.configureClientOptions
HarshaNalluru Feb 4, 2022
9a9e0aa
migration guide
HarshaNalluru Feb 4, 2022
bab5665
more format
HarshaNalluru Feb 4, 2022
2b36e82
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Feb 4, 2022
74684dd
mixed-reality update
HarshaNalluru Feb 4, 2022
c79a6bb
attestation simplification
HarshaNalluru Feb 4, 2022
23dcf48
more fixes
HarshaNalluru Feb 4, 2022
18a4fab
changelogs and gettingstarted docs
HarshaNalluru Feb 5, 2022
3b2f286
format
HarshaNalluru Feb 7, 2022
8e564c1
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Feb 7, 2022
0215d5d
format
HarshaNalluru Feb 7, 2022
dc1a346
changelog
HarshaNalluru Feb 7, 2022
1601db6
tables ci - test-proxy variable
HarshaNalluru Feb 7, 2022
a4fe196
env.SAS_CONNECTION_STRING test fix
HarshaNalluru Feb 7, 2022
d0cbb6f
sort imports
HarshaNalluru Feb 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions sdk/attestation/attestation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

### Bugs Fixed

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

### Other Changes

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

### Breaking Changes

* Reversed the order of `credentials` and `endpoint` in `AttestationAdministrationClient` to be
- Reversed the order of `credentials` and `endpoint` in `AttestationAdministrationClient` to be
consistent with other SDKs.
* Removed `credentials` top level parameter for `AttestationClient` constructor, moved
- Removed `credentials` top level parameter for `AttestationClient` constructor, moved
to the `AttestationClientOptions` object.
* Renamed the `validateToken` API in the `AttestationToken` class to `getTokenProblems` returning
- Renamed the `validateToken` API in the `AttestationToken` class to `getTokenProblems` returning
an array of strings.
* Attestation Policy APIs (`setPolicy`, `resetPolicy`) have had their `privateKey` and `certificate` parameters moved to options.
* Renamed `instanceUrl` to `endpoint` to be consistent with other APIs.
* Removed `policyCertificates` from `AttestationAdministrationClient`.
* Removed `StoredAttestationPolicy` and replaced it with `AttestationPolicyToken`.
* 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
the `DataType` to send to the server based on that.
* Removed the `AttestationSigningKey` model type replaced with two parameters
- Attestation Policy APIs (`setPolicy`, `resetPolicy`) have had their `privateKey` and `certificate` parameters moved to options.
- Renamed `instanceUrl` to `endpoint` to be consistent with other APIs.
- Removed `policyCertificates` from `AttestationAdministrationClient`.
- Removed `StoredAttestationPolicy` and replaced it with `AttestationPolicyToken`.
- 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
the `DataType` to send to the server based on that.
- Removed the `AttestationSigningKey` model type replaced with two parameters
`privateKey` and `certificate` to the APIs which used to accept an `AttestationSigningKey`
* Renamed `AttestationResponse.value` to `AttestationResponse.body` to align with
API guidelines.
- Renamed `AttestationResponse.value` to `AttestationResponse.body` to align with
API guidelines.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, are these changes necessary?

Copy link
Member Author

@HarshaNalluru HarshaNalluru Feb 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier did this.


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

### Features Added

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

### Key Bugs Fixed

* Fixes the location of types definition in package.json
- Fixes the location of types definition in package.json

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

### Features Added

### Breaking Changes

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

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

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

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

* Initial Release
- Initial Release
16 changes: 6 additions & 10 deletions sdk/attestation/attestation/src/attestationClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,14 @@ export class AttestationClient {
) {
let credentialScopes: string[] | undefined = undefined;
let credential: TokenCredential | undefined = undefined;
let options: AttestationClientOptions = {};
let options: AttestationClientOptions;

// If arg2 is defined, it's either a tokenCredential or it's a client options.
if (credentialsOrOptions !== undefined) {
if (isTokenCredential(credentialsOrOptions)) {
credential = credentialsOrOptions;
credentialScopes = ["https://attest.azure.net/.default"];
} else {
options = credentialsOrOptions;
}
} else if (clientOptions !== undefined) {
if (credentialsOrOptions && isTokenCredential(credentialsOrOptions)) {
credential = credentialsOrOptions;
credentialScopes = ["https://attest.azure.net/.default"];
options = clientOptions;
} else {
options = credentialsOrOptions || {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You can use ?? here. Not a big deal but it is semantically clearer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to kick off another 100 builds again. 🥲

I'll consider the change if I am making any other significant commit 🙂

}

const internalPipelineOptions: GeneratedClientOptionalParams = {
Expand Down
35 changes: 17 additions & 18 deletions sdk/attestation/attestation/test/public/attestationTests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ describe("[AAD] Attestation Client", function () {
const binaryRuntimeData = base64url.decodeString(_runtimeData);
const client = createRecordedClient(recorder, endpointType);

{
// You can't specify both runtimeData and runtimeJson.
await expect(
Copy link
Member Author

@HarshaNalluru HarshaNalluru Feb 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect wasn't capturing somehow.
Maybe a breaking change or something, hence updated to assert instead.

client.attestOpenEnclave(base64url.decodeString(_openEnclaveReport).subarray(0x10), {
runTimeData: binaryRuntimeData,
runTimeJson: binaryRuntimeData,
})
).to.eventually.be.rejectedWith("Cannot provide both runTimeData and runTimeJson");
}
// You can't specify both runtimeData and runtimeJson.
await assert.isRejected(
client.attestOpenEnclave(base64url.decodeString(_openEnclaveReport).subarray(0x10), {
runTimeData: binaryRuntimeData,
runTimeJson: binaryRuntimeData,
}),
"Cannot provide both runTimeData and runTimeJson.",
"Expected to throw since you can't specify both runtimeData and runtimeJson"
);

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

const binaryRuntimeData = base64url.decodeString(_runtimeData);

{
// You can't specify both runtimeData and runtimeJson.
await expect(
client.attestSgxEnclave(base64url.decodeString(_openEnclaveReport).subarray(0x10), {
runTimeData: binaryRuntimeData,
runTimeJson: binaryRuntimeData,
})
).to.eventually.be.rejectedWith("Cannot provide both runTimeData and runTimeJson");
}
await assert.isRejected(
client.attestSgxEnclave(base64url.decodeString(_openEnclaveReport).subarray(0x10), {
runTimeData: binaryRuntimeData,
runTimeJson: binaryRuntimeData,
}),
"Cannot provide both runTimeData and runTimeJson.",
"Expected to throw since you can't specify both runtimeData and runtimeJson"
);

{
// An OpenEnclave report has a 16 byte header prepended to an SGX quote.
Expand Down
14 changes: 7 additions & 7 deletions sdk/attestation/attestation/test/utils/recordedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,18 @@ export function createRecordedClient(
},
};
}
if (authenticatedClient !== undefined && authenticatedClient) {
if (authenticatedClient) {
const attClient = new AttestationClient(
getAttestationUri(endpointType),
createTestCredential(),
options
recorder.configureClientOptions(options)
);
recorder.configureClient(attClient["_client"]);
return attClient;
}
const attClient = new AttestationClient(getAttestationUri(endpointType), options);
recorder.configureClient(attClient["_client"]);
const attClient = new AttestationClient(
getAttestationUri(endpointType),
recorder.configureClientOptions(options)
);
return attClient;
}

Expand All @@ -128,8 +129,7 @@ export function createRecordedAdminClient(
const adminClient = new AttestationAdministrationClient(
getAttestationUri(endpointType),
createTestCredential(),
options
recorder.configureClientOptions(options)
);
recorder.configureClient(adminClient["_client"]);
return adminClient;
}
2 changes: 1 addition & 1 deletion sdk/deviceupdate/iot-device-update-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"autoPublish": false,
"dependencies": {
"@azure/core-auth": "^1.3.0",
"@azure-rest/core-client": "1.0.0-beta.7",
"@azure-rest/core-client": "1.0.0-beta.9",
"@azure/core-rest-pipeline": "^1.1.0",
"@azure/logger": "^1.0.0",
"tslib": "^2.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import { Recorder, assertEnvironmentVariable } from "@azure-tools/test-recorder"

export function createRecordedClient(recorder: Recorder): DeviceUpdateRestClient {
const credential = createTestCredential();
const client = DeviceUpdate(assertEnvironmentVariable("ENDPOINT"), credential);
recorder.configureClient(client);
const client = DeviceUpdate(
assertEnvironmentVariable("ENDPOINT"),
credential,
recorder.configureClientOptions({})
);
return client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export async function createClient(
): Promise<DocumentTranslatorClient> {
await recorder.start({ envSetupForPlayback });
const credential = { key: env.DOCUMENT_TRANSLATOR_API_KEY ?? "" };
const client = DocumentTranslator(env.ENDPOINT ?? "", credential, options);
recorder.configureClient(client);
const client = DocumentTranslator(
env.ENDPOINT ?? "",
credential,
recorder.configureClientOptions(options || {})
);
return client;
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ describe("RemoteRendering functional tests", () => {
beforeEach(async function (this: Context) {
recorder = createRecorder(this);
await recorder.start(recorderStartOptions);
client = createClient();
recorder.configureClient(client["client"]);
client = createClient(recorder);
});

afterEach(async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const recorderStartOptions: RecorderStartOptions = {
},
};

export function createClient(): RemoteRenderingClient {
export function createClient(recorder: Recorder): RemoteRenderingClient {
const serviceEndpoint = assertEnvironmentVariable("REMOTERENDERING_ARR_SERVICE_ENDPOINT");
const accountDomain = assertEnvironmentVariable("REMOTERENDERING_ARR_ACCOUNT_DOMAIN");
const accountId = assertEnvironmentVariable("REMOTERENDERING_ARR_ACCOUNT_ID");
Expand All @@ -50,10 +50,21 @@ export function createClient(): RemoteRenderingClient {
// the AccessToken auth path.
const maxTimestampMs = 8640000000000000;
const credential: AccessToken = { token: "<access_token>", expiresOnTimestamp: maxTimestampMs };
return new RemoteRenderingClient(serviceEndpoint, accountId, credential);
return new RemoteRenderingClient(
serviceEndpoint,
accountId,
credential,
recorder.configureClientOptions({})
);
} else {
const credential: AzureKeyCredential = new AzureKeyCredential(accountKey);
return new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential);
return new RemoteRenderingClient(
serviceEndpoint,
accountId,
accountDomain,
credential,
recorder.configureClientOptions({})
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export function createRecordedClient(recorder: Recorder): SchemaRegistryClient {
const credential = createTestCredential();
const client = new SchemaRegistryClient(
assertEnvironmentVariable("SCHEMA_REGISTRY_ENDPOINT"),
credential
credential,
recorder.configureClientOptions({})
);
recorder.configureClient(client["client"]);
return client;
}
35 changes: 22 additions & 13 deletions sdk/search/search-documents/test/public/utils/recordedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,28 @@ export async function createClients<IndexModel>(
indexName = recorder.variable("TEST_INDEX_NAME", indexName);
const endPoint: string = process.env.ENDPOINT ?? "https://endpoint";
const credential = new AzureKeyCredential(testEnv.SEARCH_API_ADMIN_KEY);
const searchClient = new SearchClient<IndexModel>(endPoint, indexName, credential, {
serviceVersion,
});
const indexClient = new SearchIndexClient(endPoint, credential, {
serviceVersion,
});
const indexerClient = new SearchIndexerClient(endPoint, credential, {
serviceVersion,
});

recorder.configureClient(searchClient["client"]);
recorder.configureClient(indexClient["client"]);
recorder.configureClient(indexerClient["client"]);
const searchClient = new SearchClient<IndexModel>(
endPoint,
indexName,
credential,
recorder.configureClientOptions({
serviceVersion,
})
);
const indexClient = new SearchIndexClient(
endPoint,
credential,
recorder.configureClientOptions({
serviceVersion,
})
);
const indexerClient = new SearchIndexerClient(
endPoint,
credential,
recorder.configureClientOptions({
serviceVersion,
})
);

return {
searchClient,
Expand Down
2 changes: 1 addition & 1 deletion sdk/synapse/synapse-access-control-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"sdk-type": "client",
"version": "1.0.0-beta.1",
"dependencies": {
"@azure-rest/core-client": "1.0.0-beta.7",
"@azure-rest/core-client": "1.0.0-beta.9",
"@azure/core-auth": "^1.3.0",
"@azure/core-rest-pipeline": "^1.3.0",
"@azure/core-paging": "^1.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export async function createClient(
await recorder.start({ envSetupForPlayback: replaceableVariables });

let credential: TokenCredential = createTestCredential();
const client = AccessControlClient(env.ENDPOINT ?? "", credential, {...options, allowInsecureConnection: true});
recorder.configureClient(client);
const client = AccessControlClient(env.ENDPOINT ?? "", credential, recorder.configureClientOptions({ ...options, allowInsecureConnection: true }));
return client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ export async function createClient(
},
});

const client = new ArtifactsClient(credential, env.ENDPOINT ?? "", {
const client = new ArtifactsClient(credential, env.ENDPOINT ?? "", recorder.configureClientOptions({
...options,
allowInsecureConnection: true,
});
recorder.configureClient(client);


}));
return client;
}
1 change: 1 addition & 0 deletions sdk/tables/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extends:
template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml
parameters:
ServiceDirectory: tables
TestProxy: true
Artifacts:
- name: azure-data-tables
safeName: azuretables
Loading