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

Adds property baseUri on the ServiceClientOptions #457

Merged
merged 22 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.6.0 - (2021-07-29)

- Added a new property `baseUri` on the `ServiceClientOptions`, so that when a `TokenCredential` is sent to `ServiceClient`, it now automatically sets the scope of future token requests based on the `options.baseUri` property.
sadasant marked this conversation as resolved.
Show resolved Hide resolved

## 2.5.3 - (2021-07-12)
- Updated the dependency on the uuid package to v8 (PR [456](https://github.com/Azure/ms-rest-js/pull/456))

Expand Down
6 changes: 5 additions & 1 deletion lib/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,11 @@ function deserializeCompositeType(
// paging
if (Array.isArray(responseBody[key]) && modelProps[key].serializedName === "") {
propertyInstance = responseBody[key];
const arrayInstance = serializer.deserialize(propertyMapper, propertyInstance, propertyObjectName);
const arrayInstance = serializer.deserialize(
propertyMapper,
propertyInstance,
propertyObjectName
);
// Copy over any properties that have already been added into the instance, where they do
// not exist on the newly de-serialized array
for (const [key, value] of Object.entries(instance)) {
Expand Down
28 changes: 25 additions & 3 deletions lib/serviceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ export interface ServiceClientOptions {
* HTTP and HTTPS agents which will be used for every HTTP request (Node.js only).
*/
agentSettings?: AgentSettings;
/**
* If specified:
* - This `baseUri` becomes the base URI that requests will be made against for this ServiceClient.
* - If a `TokenCredential` was passed through the constructor, this `baseUri` defines the `getToken` scope to be `${options.baseUri}/.default`.
*
* If it is not specified:
* - All OperationSpecs must contain a baseUrl property.
* - If a `TokenCredential` was passed through the constructor, the `getToken` scope is set to be "https://management.azure.com/.default".
*/
baseUri?: string;
}

/**
Expand All @@ -151,8 +161,13 @@ export interface ServiceClientOptions {
*/
export class ServiceClient {
/**
* If specified, this is the base URI that requests will be made against for this ServiceClient.
* If it is not specified, then all OperationSpecs must contain a baseUrl property.
* If specified:
* - This `baseUri` becomes the base URI that requests will be made against for this ServiceClient.
* - If a `TokenCredential` was passed through the constructor, this `baseUri` defines the `getToken` scope to be `${options.baseUri}/.default`.
*
* If it is not specified:
* - All OperationSpecs must contain a baseUrl property.
* - If a `TokenCredential` was passed through the constructor, the `getToken` scope is set to be "https://management.azure.com/.default".
sadasant marked this conversation as resolved.
Show resolved Hide resolved
*/
protected baseUri?: string;

Expand Down Expand Up @@ -185,9 +200,16 @@ export class ServiceClient {
options = {};
}

if (options.baseUri) {
this.baseUri = options.baseUri;
}

let serviceClientCredentials: ServiceClientCredentials | undefined;
if (isTokenCredential(credentials)) {
serviceClientCredentials = new AzureIdentityCredentialAdapter(credentials);
serviceClientCredentials = new AzureIdentityCredentialAdapter(
credentials,
options?.baseUri ? `${options.baseUri}/.default` : undefined
sadasant marked this conversation as resolved.
Show resolved Hide resolved
);
} else {
serviceClientCredentials = credentials;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const Constants = {
* @const
* @type {string}
*/
msRestVersion: "2.5.3",
msRestVersion: "2.6.0",

/**
* Specifies HTTP.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"email": "azsdkteam@microsoft.com",
"url": "https://github.com/Azure/ms-rest-js"
},
"version": "2.5.3",
"version": "2.6.0",
"description": "Isomorphic client Runtime for Typescript/node.js/browser javascript client libraries generated using AutoRest",
"tags": [
"isomorphic",
Expand Down