Skip to content

Commit

Permalink
[core-http] Reintroduce ServiceClientCredentials as an accepted crede…
Browse files Browse the repository at this point in the history
…ntial type (#4773)

* Re-introduce ServiceClientCredentials interface to ServiceClient API

* Update versions of local core dependencies

* Remove unneeded conflicting methods from core-http's AbortSignalLike

* Improve ServiceClient and AzureServiceClient constructor comments

* Use and re-export AbortSignalLike from @azure/abort-controller
  • Loading branch information
daviwil authored Aug 16, 2019
1 parent cc1f0a9 commit 8c22d1c
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 37 deletions.
4 changes: 2 additions & 2 deletions sdk/core/core-amqp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"dependencies": {
"@azure/abort-controller": "1.0.0-preview.2",
"@azure/core-auth": "1.0.0-preview.2",
"@azure/core-auth": "1.0.0-preview.3",
"@types/async-lock": "^1.1.0",
"@types/is-buffer": "^2.0.0",
"async-lock": "^1.1.3",
Expand All @@ -72,7 +72,7 @@
"rhea-promise": "^1.0.0"
},
"devDependencies": {
"@azure/identity": "1.0.0-preview.2",
"@azure/identity": "1.0.0-preview.3",
"@types/chai": "^4.1.6",
"@types/chai-as-promised": "^7.1.0",
"@types/debug": "^0.0.31",
Expand Down
8 changes: 4 additions & 4 deletions sdk/core/core-arm/lib/azureServiceClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

import { HttpOperationResponse, OperationArguments, OperationSpec, RequestOptionsBase, RequestPrepareOptions, ServiceClient, ServiceClientOptions, TokenCredential, WebResource, getDefaultUserAgentValue as getDefaultUserAgentValueFromMsRest } from "@azure/core-http";
import { HttpOperationResponse, OperationArguments, OperationSpec, RequestOptionsBase, RequestPrepareOptions, ServiceClient, ServiceClientCredentials, ServiceClientOptions, TokenCredential, WebResource, getDefaultUserAgentValue as getDefaultUserAgentValueFromMsRest } from "@azure/core-http";
import { createLROPollerFromInitialResponse, createLROPollerFromPollState, LROPoller } from "./lroPoller";
import { LROPollState } from "./lroPollStrategy";
import * as Constants from "./util/constants";
Expand All @@ -27,8 +27,8 @@ export interface AzureServiceClientOptions extends ServiceClientOptions {
* Initializes a new instance of the AzureServiceClient class.
* @constructor
*
* @param {TokenCredential} credentials - The TokenCredential used for authentication.
* @param {AzureServiceClientOptions} options - The parameter options used by AzureServiceClient
* @param credentials The credentials used for authentication with the service.
* @param options The parameter options used by AzureServiceClient.
*/
export class AzureServiceClient extends ServiceClient {
public acceptLanguage: string = Constants.DEFAULT_LANGUAGE;
Expand All @@ -37,7 +37,7 @@ export class AzureServiceClient extends ServiceClient {
*/
public longRunningOperationRetryTimeout?: number;

constructor(credentials: TokenCredential, options?: AzureServiceClientOptions) {
constructor(credentials: TokenCredential | ServiceClientCredentials, options?: AzureServiceClientOptions) {
super(credentials, options = updateOptionsWithDefaultValues(options));

// For convenience, if the credentials have an associated AzureEnvironment,
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-arm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
},
"sideEffects": false,
"dependencies": {
"@azure/core-http": "1.0.0-preview.2",
"@azure/core-http": "1.0.0-preview.3",
"tslib": "^1.9.3"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion sdk/core/core-http/lib/coreHttp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export { WebResource, HttpRequestBody, RequestPrepareOptions, HttpMethods, ParameterValue, RequestOptionsBase, TransferProgressEvent, AbortSignalLike } from "./webResource";
export { WebResource, HttpRequestBody, RequestPrepareOptions, HttpMethods, ParameterValue, RequestOptionsBase, TransferProgressEvent } from "./webResource";
export { DefaultHttpClient } from "./defaultHttpClient";
export { HttpClient } from "./httpClient";
export { HttpHeaders } from "./httpHeaders";
Expand Down Expand Up @@ -41,6 +41,7 @@ export {
applyMixins, isNode, isDuration
} from "./util/utils";
export { URLBuilder, URLQuery } from "./url";
export { AbortSignalLike } from "@azure/abort-controller";

// Credentials
export { TokenCredential, GetTokenOptions, AccessToken, isTokenCredential, SimpleTokenCredential } from "@azure/core-auth";
Expand Down
10 changes: 7 additions & 3 deletions sdk/core/core-http/lib/serviceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { OperationResponse } from "./operationResponse";
import { ServiceCallback } from "./util/utils";
import { proxyPolicy, getDefaultProxySettings } from "./policies/proxyPolicy";
import { throttlingRetryPolicy } from "./policies/throttlingRetryPolicy";
import { ServiceClientCredentials } from "./credentials/serviceClientCredentials";
import { signingPolicy } from './policies/signingPolicy';


/**
Expand Down Expand Up @@ -131,10 +133,10 @@ export class ServiceClient {
/**
* The ServiceClient constructor
* @constructor
* @param {TokenCredential} [credentials] The credentials object used for authentication.
* @param {ServiceClientOptions} [options] The service client options that govern the behavior of the client.
* @param credentials The credentials used for authentication with the service.
* @param options The service client options that govern the behavior of the client.
*/
constructor(credentials?: TokenCredential, options?: ServiceClientOptions) {
constructor(credentials?: TokenCredential | ServiceClientCredentials, options?: ServiceClientOptions) {
if (!options) {
options = {};
}
Expand Down Expand Up @@ -170,6 +172,8 @@ export class ServiceClient {
};

authPolicyFactory = wrappedPolicyFactory();
} else if (credentials && typeof credentials.signRequest === "function") {
authPolicyFactory = signingPolicy(credentials);
} else if (credentials !== undefined) {
throw new Error("The credentials argument must implement the TokenCredential interface");
}
Expand Down
13 changes: 1 addition & 12 deletions sdk/core/core-http/lib/webResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { generateUuid } from "./util/utils";
import { HttpOperationResponse } from "./httpOperationResponse";
import { OperationResponse } from "./operationResponse";
import { ProxySettings } from "./serviceClient";
import { AbortSignalLike } from "@azure/abort-controller";

export type HttpMethods = "GET" | "PUT" | "POST" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "TRACE";
export type HttpRequestBody = Blob | string | ArrayBuffer | ArrayBufferView | (() => NodeJS.ReadableStream);
Expand All @@ -22,18 +23,6 @@ export type TransferProgressEvent = {
loadedBytes: number
};

/**
* Allows the request to be aborted upon firing of the "abort" event.
* Compatible with the browser built-in AbortSignal and common polyfills.
*/
export interface AbortSignalLike {
readonly aborted: boolean;
dispatchEvent: (event: Event) => boolean;
onabort: ((this: AbortSignalLike, ev: Event) => any) | null;
addEventListener: (type: "abort", listener: (this: AbortSignalLike, ev: Event) => any, options?: any) => void;
removeEventListener: (type: "abort", listener: (this: AbortSignalLike, ev: Event) => any, options?: any) => void;
}

/**
* Creates a new WebResource object.
*
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
},
"dependencies": {
"@azure/abort-controller": "1.0.0-preview.2",
"@azure/core-auth": "1.0.0-preview.2",
"@azure/core-auth": "1.0.0-preview.3",
"@types/node-fetch": "^2.5.0",
"@types/tunnel": "^0.0.1",
"form-data": "^2.5.0",
Expand Down
2 changes: 1 addition & 1 deletion sdk/eventhub/event-hubs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"uuid": "^3.3.2"
},
"devDependencies": {
"@azure/identity": "1.0.0-preview.2",
"@azure/identity": "1.0.0-preview.3",
"@microsoft/api-extractor": "^7.1.5",
"@types/async-lock": "^1.1.0",
"@types/chai": "^4.1.6",
Expand Down
4 changes: 2 additions & 2 deletions sdk/identity/identity/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@azure/identity",
"sdk-type": "client",
"version": "1.0.0-preview.2",
"version": "1.0.0-preview.3",
"description": "Provides credential implementations for Azure SDK libraries that can authenticate with Azure Active Directory",
"main": "dist/index.js",
"module": "dist-esm/src/index.js",
Expand Down Expand Up @@ -70,7 +70,7 @@
"homepage": "https://github.com/azure/azure-sdk-for-js/tree/master/sdk/identity/identity",
"sideEffects": false,
"dependencies": {
"@azure/core-http": "1.0.0-preview.2",
"@azure/core-http": "1.0.0-preview.3",
"events": "^3.0.0",
"jws": "~3.2.2",
"msal": "~1.0.2",
Expand Down
6 changes: 3 additions & 3 deletions sdk/keyvault/keyvault-certificates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
},
"sideEffects": false,
"dependencies": {
"@azure/core-arm": "1.0.0-preview.2",
"@azure/core-http": "1.0.0-preview.2",
"@azure/core-arm": "1.0.0-preview.3",
"@azure/core-http": "1.0.0-preview.3",
"@azure/core-paging": "1.0.0-preview.1",
"@azure/core-tracing": "1.0.0-preview.1",
"@azure/identity": "1.0.0-preview.2",
"tslib": "^1.9.3"
},
"devDependencies": {
"@azure/identity": "1.0.0-preview.3",
"@microsoft/api-extractor": "^7.1.5",
"@types/chai": "^4.1.6",
"@types/dotenv": "^6.1.0",
Expand Down
6 changes: 3 additions & 3 deletions sdk/keyvault/keyvault-keys/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@
},
"sideEffects": false,
"dependencies": {
"@azure/core-arm": "1.0.0-preview.2",
"@azure/core-http": "1.0.0-preview.2",
"@azure/core-arm": "1.0.0-preview.3",
"@azure/core-http": "1.0.0-preview.3",
"@azure/core-paging": "1.0.0-preview.1",
"@azure/core-tracing": "1.0.0-preview.1",
"@azure/identity": "1.0.0-preview.2",
"@azure/identity": "1.0.0-preview.3",
"tslib": "^1.9.3",
"@trust/keyto": "0.3.7"
},
Expand Down
6 changes: 3 additions & 3 deletions sdk/keyvault/keyvault-secrets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@
"sideEffects": false,
"dependencies": {
"@azure/abort-controller": "1.0.0-preview.2",
"@azure/core-arm": "1.0.0-preview.2",
"@azure/core-http": "1.0.0-preview.2",
"@azure/core-arm": "1.0.0-preview.3",
"@azure/core-http": "1.0.0-preview.3",
"@azure/core-paging": "1.0.0-preview.1",
"@azure/identity": "1.0.0-preview.2",
"@azure/identity": "1.0.0-preview.3",
"tslib": "^1.9.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion sdk/template/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"sideEffects": false,
"private": true,
"dependencies": {
"@azure/core-http": "1.0.0-preview.2",
"@azure/core-http": "1.0.0-preview.3",
"events": "^3.0.0",
"tslib": "^1.9.3"
},
Expand Down

0 comments on commit 8c22d1c

Please sign in to comment.