Skip to content

Commit

Permalink
proxyOptions to proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshaNalluru committed Jun 18, 2019
1 parent cf7fbad commit 20ec78a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
41 changes: 41 additions & 0 deletions sdk/storage/storage-blob/samples/typescript/proxyAuth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Setup: Enter your storage account name and shared key in main()
*/

import { BlobServiceClient, newPipeline, SharedKeyCredential } from "../../src"; // Change to "@azure/storage-blob" in your package

async function main() {
// Enter your storage account name and shared key
const account = "";
const accountKey = "";

// Use SharedKeyCredential with storage account and account key
const sharedKeyCredential = new SharedKeyCredential(account, accountKey);

// Use sharedKeyCredential, tokenCredential or anonymousCredential to create a pipeline
const pipeline = newPipeline(sharedKeyCredential, {
proxy: { url: "http://localhost:3128" }
});

const blobServiceClient = new BlobServiceClient(
// When using AnonymousCredential, following url should include a valid SAS or support public access
`https://${account}.blob.core.windows.net`,
pipeline
);

// Create a container
const containerName = `newcontainer${new Date().getTime()}`;
const createContainerResponse = await blobServiceClient
.createContainerClient(containerName)
.create();
console.log(`Created container ${containerName} successfully`, createContainerResponse.requestId);
}

// An async method returns a Promise object, which is compatible with then().catch() coding style.
main()
.then(() => {
console.log("Successfully executed the sample.");
})
.catch((err) => {
console.log(err.message);
});
16 changes: 15 additions & 1 deletion sdk/storage/storage-blob/src/Pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {
RequestPolicyFactory,
RequestPolicyOptions,
ServiceClientOptions,
WebResource
WebResource,
proxyPolicy,
getDefaultProxySettings
} from "@azure/ms-rest-js";

import { BrowserPolicyFactory } from "./BrowserPolicyFactory";
Expand All @@ -41,6 +43,16 @@ export {
RequestPolicyOptions
};

/**
* Interface of proxy policy options.
*
* @export
* @interface ProxyOptions
*/

export interface ProxyOptions {
url?: string;
}
/**
* Option interface for Pipeline constructor.
*
Expand Down Expand Up @@ -125,6 +137,7 @@ export class Pipeline {
* @interface NewPipelineOptions
*/
export interface NewPipelineOptions {
proxy?: ProxyOptions;
/**
* Telemetry configures the built-in telemetry policy behavior.
*
Expand Down Expand Up @@ -178,6 +191,7 @@ export function newPipeline(
deserializationPolicy(), // Default deserializationPolicy is provided by protocol layer
new RetryPolicyFactory(pipelineOptions.retryOptions),
new LoggingPolicyFactory(),
proxyPolicy(getDefaultProxySettings((pipelineOptions.proxy || {}).url)),
credential
];

Expand Down

0 comments on commit 20ec78a

Please sign in to comment.