Skip to content

Commit

Permalink
Use @azure/core-http and its TokenCredential interface
Browse files Browse the repository at this point in the history
  • Loading branch information
daviwil committed Jun 17, 2019
1 parent 46df644 commit b1c0b01
Show file tree
Hide file tree
Showing 45 changed files with 2,595 additions and 961 deletions.
2 changes: 1 addition & 1 deletion sdk/storage/storage-queue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"homepage": "https://github.com/Azure/azure-storage-js#readme",
"sideEffects": false,
"dependencies": {
"@azure/ms-rest-js": "^1.2.6",
"@azure/core-http": "^1.2.6",
"tslib": "^1.9.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-queue/rollup.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const depNames = Object.keys(pkg.dependencies);
const production = process.env.NODE_ENV === "production";

export function nodeConfig(test = false) {
const externalNodeBuiltins = ["@azure/ms-rest-js", "crypto", "fs", "os"];
const externalNodeBuiltins = ["@azure/core-http", "crypto", "fs", "os"];
const baseConfig = {
input: "dist-esm/src/index.js",
external: depNames.concat(externalNodeBuiltins),
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-queue/src/Aborter.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.

import { AbortSignalLike, isNode } from "@azure/ms-rest-js";
import { AbortSignalLike, isNode } from "@azure/core-http";

/**
* An aborter instance implements AbortSignal interface, can abort HTTP requests.
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-queue/src/BrowserPolicyFactory.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.

import { RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "@azure/ms-rest-js";
import { RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "@azure/core-http";
import { BrowserPolicy } from "./policies/BrowserPolicy";

/**
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-queue/src/LoggingPolicyFactory.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.

import { RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "@azure/ms-rest-js";
import { RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "@azure/core-http";
import { LoggingPolicy } from "./policies/LoggingPolicy";

/**
Expand Down
18 changes: 13 additions & 5 deletions sdk/storage/storage-queue/src/MessageIdClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as coreHttp from "@azure/core-http";
import * as Models from "./generated/lib/models";
import { Aborter } from "./Aborter";
import { MessageId } from "./generated/lib/operations";
Expand Down Expand Up @@ -85,12 +86,16 @@ export class MessageIdClient extends StorageClient {
* "https://myaccount.queue.core.windows.net/myqueue/messages/messageid". You can
* append a SAS if using AnonymousCredential, such as
* "https://myaccount.queue.core.windows.net/myqueue/messages/messageid?sasString".
* @param {Credential} credential Such as AnonymousCredential, SharedKeyCredential or TokenCredential.
* If not specified, anonymous credential is used.
* @param {Credential | coreHttp.TokenCredential} credential Such as AnonymousCredential, SharedKeyCredential or TokenCredential.
* If not specified, anonymous credential is used.
* @param {NewPipelineOptions} [options] Options to configure the HTTP pipeline.
* @memberof MessageIdClient
*/
constructor(url: string, credential?: Credential, options?: NewPipelineOptions);
constructor(
url: string,
credential?: Credential | coreHttp.TokenCredential,
options?: NewPipelineOptions
);
/**
* Creates an instance of MessageIdClient.
*
Expand All @@ -105,14 +110,17 @@ export class MessageIdClient extends StorageClient {
constructor(url: string, pipeline: Pipeline);
constructor(
urlOrConnectionString: string,
credentialOrPipelineOrQueueName?: Credential | Pipeline | string,
credentialOrPipelineOrQueueName?: Credential | coreHttp.TokenCredential | Pipeline | string,
messageIdOrOptions?: string | NewPipelineOptions,
options: NewPipelineOptions = {}
) {
let pipeline: Pipeline;
if (credentialOrPipelineOrQueueName instanceof Pipeline) {
pipeline = credentialOrPipelineOrQueueName;
} else if (credentialOrPipelineOrQueueName instanceof Credential) {
} else if (
credentialOrPipelineOrQueueName instanceof Credential ||
coreHttp.isTokenCredential(credentialOrPipelineOrQueueName)
) {
options = messageIdOrOptions as NewPipelineOptions;
pipeline = newPipeline(credentialOrPipelineOrQueueName, options);
} else if (
Expand Down
21 changes: 16 additions & 5 deletions sdk/storage/storage-queue/src/MessagesClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { HttpResponse } from "@azure/ms-rest-js";
import {
HttpResponse,
TokenCredential as CoreHttpTokenCredential,
isTokenCredential as isCoreHttpTokenCredential
} from "@azure/core-http";
import * as Models from "./generated/lib/models";
import { Aborter } from "./Aborter";
import { Messages } from "./generated/lib/operations";
Expand Down Expand Up @@ -180,12 +184,16 @@ export class MessagesClient extends StorageClient {
* "https://myaccount.queue.core.windows.net/myqueue/messages". You can
* append a SAS if using AnonymousCredential, such as
* "https://myaccount.queue.core.windows.net/myqueue/messages?sasString".
* @param {Credential} credential Such as AnonymousCredential, SharedKeyCredential or TokenCredential.
* @param {Credential | CoreHttpTokenCredential } credential Such as AnonymousCredential, SharedKeyCredential or TokenCredential.
* If not specified, anonymous credential is used.
* @param {NewPipelineOptions} [options] Options to configure the HTTP pipeline.
* @memberof MessagesClient
*/
constructor(url: string, credential?: Credential, options?: NewPipelineOptions);
constructor(
url: string,
credential?: Credential | CoreHttpTokenCredential,
options?: NewPipelineOptions
);
/**
* Creates an instance of MessagesClient.
*
Expand All @@ -200,13 +208,16 @@ export class MessagesClient extends StorageClient {
constructor(url: string, pipeline: Pipeline);
constructor(
urlOrConnectionString: string,
credentialOrPipelineOrQueueName?: Credential | Pipeline | string,
credentialOrPipelineOrQueueName?: Credential | CoreHttpTokenCredential | Pipeline | string,
options?: NewPipelineOptions
) {
let pipeline: Pipeline;
if (credentialOrPipelineOrQueueName instanceof Pipeline) {
pipeline = credentialOrPipelineOrQueueName;
} else if (credentialOrPipelineOrQueueName instanceof Credential) {
} else if (
credentialOrPipelineOrQueueName instanceof Credential ||
isCoreHttpTokenCredential(credentialOrPipelineOrQueueName)
) {
pipeline = newPipeline(credentialOrPipelineOrQueueName, options);
} else if (
!credentialOrPipelineOrQueueName &&
Expand Down
15 changes: 10 additions & 5 deletions sdk/storage/storage-queue/src/Pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import {
RequestPolicyFactory,
RequestPolicyOptions,
ServiceClientOptions,
WebResource
} from "@azure/ms-rest-js";
WebResource,
TokenCredential as CoreHttpTokenCredential,
isTokenCredential as isCoreHttpTokenCredential,
bearerTokenAuthenticationPolicy
} from "@azure/core-http";
import { BrowserPolicyFactory } from "./BrowserPolicyFactory";
import { Credential } from "./credentials/Credential";
import { LoggingPolicyFactory } from "./LoggingPolicyFactory";
Expand Down Expand Up @@ -159,13 +162,13 @@ export interface NewPipelineOptions {
* Creates a new Pipeline object with Credential provided.
*
* @static
* @param {Credential} credential Such as AnonymousCredential, SharedKeyCredential or TokenCredential.
* @param {Credential | CoreHttpTokenCredential } credential Such as AnonymousCredential, SharedKeyCredential or TokenCredential.
* @param {NewPipelineOptions} [pipelineOptions] Options.
* @returns {Pipeline} A new Pipeline object.
* @memberof Pipeline
*/
export function newPipeline(
credential: Credential,
credential: Credential | CoreHttpTokenCredential,
pipelineOptions: NewPipelineOptions = {}
): Pipeline {
// Order is important. Closer to the API at the top & closer to the network at the bottom.
Expand All @@ -178,7 +181,9 @@ export function newPipeline(
deserializationPolicy(), // Default deserializationPolicy is provided by protocol layer
new RetryPolicyFactory(pipelineOptions.retryOptions),
new LoggingPolicyFactory(),
credential
isCoreHttpTokenCredential(credential)
? bearerTokenAuthenticationPolicy(credential, "https://storage.azure.com/.default")
: credential
];

return new Pipeline(factories, {
Expand Down
25 changes: 18 additions & 7 deletions sdk/storage/storage-queue/src/QueueClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { HttpResponse } from "@azure/ms-rest-js";
import {
HttpResponse,
TokenCredential as CoreHttpTokenCredential,
isTokenCredential as isCoreHttpTokenCredential
} from "@azure/core-http";
import * as Models from "./generated/lib/models";
import { Aborter } from "./Aborter";
import { Queue } from "./generated/lib/operations";
Expand Down Expand Up @@ -219,12 +223,16 @@ export class QueueClient extends StorageClient {
* "https://myaccount.queue.core.windows.net/myqueue". You can
* append a SAS if using AnonymousCredential, such as
* "https://myaccount.queue.core.windows.net/myqueue?sasString".
* @param {Credential} credential Such as AnonymousCredential, SharedKeyCredential or TokenCredential.
* @param {Credential | CoreHttpTokenCredential } credential Such as AnonymousCredential, SharedKeyCredential or TokenCredential.
* If not specified, anonymous credential is used.
* @param {NewPipelineOptions} [options] Options to configure the HTTP pipeline.
* @memberof QueueClient
*/
constructor(url: string, credential?: Credential, options?: NewPipelineOptions);
constructor(
url: string,
credential?: Credential | CoreHttpTokenCredential,
options?: NewPipelineOptions
);
/**
* Creates an instance of QueueClient.
*
Expand All @@ -239,13 +247,16 @@ export class QueueClient extends StorageClient {
constructor(url: string, pipeline: Pipeline);
constructor(
urlOrConnectionString: string,
credentialOrPipelineOrQueueName?: Credential | Pipeline | string,
credentialOrPipelineOrQueueName?: Credential | CoreHttpTokenCredential | Pipeline | string,
options?: NewPipelineOptions
) {
let pipeline: Pipeline;
if (credentialOrPipelineOrQueueName instanceof Pipeline) {
pipeline = credentialOrPipelineOrQueueName;
} else if (credentialOrPipelineOrQueueName instanceof Credential) {
} else if (
credentialOrPipelineOrQueueName instanceof Credential ||
isCoreHttpTokenCredential(credentialOrPipelineOrQueueName)
) {
pipeline = newPipeline(credentialOrPipelineOrQueueName, options);
} else if (
!credentialOrPipelineOrQueueName &&
Expand Down Expand Up @@ -286,7 +297,7 @@ export class QueueClient extends StorageClient {
return this.queueContext.create({
...options,
abortSignal: aborter
});
} as Models.QueueCreateOptionalParams);
}

/**
Expand Down Expand Up @@ -350,7 +361,7 @@ export class QueueClient extends StorageClient {
return this.queueContext.setMetadata({
abortSignal: aborter,
metadata
});
} as Models.QueueSetMetadataOptionalParams);
}

/**
Expand Down
23 changes: 17 additions & 6 deletions sdk/storage/storage-queue/src/QueueServiceClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as coreHttp from "@azure/core-http";
import * as Models from "./generated/lib/models";
import { Aborter } from "./Aborter";
import { ListQueuesIncludeType } from "./generated/lib/models/index";
Expand Down Expand Up @@ -122,7 +123,10 @@ export class QueueServiceClient extends StorageClient {
* @returns {QueueServiceClient} A new QueueServiceClient object from the given connection string.
* @memberof QueueServiceClient
*/
public static fromConnectionString(connectionString: string, options?: NewPipelineOptions): QueueServiceClient {
public static fromConnectionString(
connectionString: string,
options?: NewPipelineOptions
): QueueServiceClient {
const extractedCreds = extractConnectionStringParts(connectionString);
const sharedKeyCredential = new SharedKeyCredential(
extractedCreds.accountName,
Expand All @@ -148,12 +152,16 @@ export class QueueServiceClient extends StorageClient {
* @param {string} url A URL string pointing to Azure Storage queue service, such as
* "https://myaccount.queue.core.windows.net". You can append a SAS
* if using AnonymousCredential, such as "https://myaccount.queue.core.windows.net?sasString".
* @param {Credential} credential Such as AnonymousCredential, SharedKeyCredential or TokenCredential.
* @param {Credential | coreHttp.TokenCredential} credential Such as AnonymousCredential, SharedKeyCredential or TokenCredential.
* If not specified, anonymous credential is used.
* @param {NewPipelineOptions} [options] Options to configure the HTTP pipeline.
* @memberof QueueServiceClient
*/
constructor(url: string, credential?: Credential, options?: NewPipelineOptions);
constructor(
url: string,
credential?: Credential | coreHttp.TokenCredential,
options?: NewPipelineOptions
);
/**
* Creates an instance of QueueServiceClient.
*
Expand All @@ -167,13 +175,16 @@ export class QueueServiceClient extends StorageClient {
constructor(url: string, pipeline: Pipeline);
constructor(
url: string,
credentialOrPipeline?: Credential | Pipeline,
credentialOrPipeline?: Credential | coreHttp.TokenCredential | Pipeline,
options?: NewPipelineOptions
) {
let pipeline: Pipeline;
if (credentialOrPipeline instanceof Pipeline) {
pipeline = credentialOrPipeline;
} else if (credentialOrPipeline instanceof Credential) {
} else if (
credentialOrPipeline instanceof Credential ||
coreHttp.isTokenCredential(credentialOrPipeline)
) {
pipeline = newPipeline(credentialOrPipeline, options);
} else {
// The second paramter is undefined. Use anonymous credential.
Expand Down Expand Up @@ -322,6 +333,6 @@ export class QueueServiceClient extends StorageClient {
abortSignal: aborter,
marker,
...options
});
} as Models.ServiceListQueuesSegmentOptionalParams);
}
}
2 changes: 1 addition & 1 deletion sdk/storage/storage-queue/src/RetryPolicyFactory.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.

import { RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "@azure/ms-rest-js";
import { RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "@azure/core-http";
import { RetryPolicy, RetryPolicyType } from "./policies/RetryPolicy";

/**
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-queue/src/TelemetryPolicyFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
RequestPolicy,
RequestPolicyFactory,
RequestPolicyOptions
} from "@azure/ms-rest-js";
} from "@azure/core-http";
import * as os from "os";

import { TelemetryPolicy } from "./policies/TelemetryPolicy";
Expand Down
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.

import { RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "@azure/ms-rest-js";
import { RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "@azure/core-http";
import { UniqueRequestIDPolicy } from "./policies/UniqueRequestIDPolicy";

/**
Expand Down
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.

import { RequestPolicy, RequestPolicyOptions } from "@azure/ms-rest-js";
import { RequestPolicy, RequestPolicyOptions } from "@azure/core-http";

import { AnonymousCredentialPolicy } from "../policies/AnonymousCredentialPolicy";
import { Credential } from "./Credential";
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-queue/src/credentials/Credential.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.

import { RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "@azure/ms-rest-js";
import { RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "@azure/core-http";
import { CredentialPolicy } from "../policies/CredentialPolicy";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import * as Crypto from "crypto";
import { RequestPolicy, RequestPolicyOptions } from "@azure/ms-rest-js";
import { RequestPolicy, RequestPolicyOptions } from "@azure/core-http";

import { SharedKeyCredentialPolicy } from "../policies/SharedKeyCredentialPolicy";
import { Credential } from "./Credential";
Expand Down
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.

import { RequestPolicy, RequestPolicyOptions } from "@azure/ms-rest-js";
import { RequestPolicy, RequestPolicyOptions } from "@azure/core-http";

import { Credential } from "../credentials/Credential";
import { TokenCredentialPolicy } from "../policies/TokenCredentialPolicy";
Expand Down
Loading

0 comments on commit b1c0b01

Please sign in to comment.