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

Provide proxy options to Blob Service Client #25126

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 20 additions & 2 deletions extensions/azurecore/src/azureResource/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as nls from 'vscode-nls';
import * as Constants from '../constants';
import { ResourceGraphClient } from '@azure/arm-resourcegraph';
import { TokenCredentials } from '@azure/ms-rest-js';
import { ProxySettings } from '@azure/core-http';
import { AzureRestResponse, GetResourceGroupsResult, GetSubscriptionsResult, ResourceQueryResult, GetBlobContainersResult, GetFileSharesResult, HttpRequestMethod, GetLocationsResult, GetManagedDatabasesResult, CreateResourceGroupResult, GetBlobsResult, GetStorageAccountAccessKeyResult, AzureAccount, azureResource, AzureAccountProviderMetadata } from 'azurecore';
import { EOL } from 'os';
import { AppContext } from '../appContext';
Expand Down Expand Up @@ -628,7 +629,7 @@ export async function getStorageAccountAccessKey(account: AzureAccount, subscrip
};
}

export async function getBlobs(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, containerName: string, ignoreErrors: boolean): Promise<GetBlobsResult> {
export async function getBlobs(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, containerName: string, ignoreErrors: boolean, proxyUrl: string | undefined): Promise<GetBlobsResult> {
const result: GetBlobsResult = { blobs: [], errors: [] };
const storageKeys = await getStorageAccountAccessKey(account, subscription, storageAccount, ignoreErrors);
if (!ignoreErrors) {
Expand All @@ -640,7 +641,10 @@ export async function getBlobs(account: AzureAccount, subscription: azureResourc
const sharedKeyCredential = new StorageSharedKeyCredential(storageAccount.name, storageKeys.keyName1);
const blobServiceClient = new BlobServiceClient(
`https://${storageAccount.name}.blob${account.properties.providerSettings.settings.azureStorageResource.endpointSuffix}`,
sharedKeyCredential
sharedKeyCredential,
{
proxyOptions: getProxyOptionsBlobService(proxyUrl)
}
);
const containerClient = blobServiceClient.getContainerClient(containerName);
for await (const blob of containerClient.listBlobsFlat()) {
Expand All @@ -666,3 +670,17 @@ export function getProviderMetadataForAccount(account: AzureAccount): AzureAccou

return provider.metadata;
}

export function getProxyOptionsBlobService(proxyUrl: string | undefined): ProxySettings | undefined {
if (proxyUrl) {
const proxyEndpoint = new URL(proxyUrl);
return {
host: proxyEndpoint.host,
port: Number.parseInt(proxyEndpoint.port) ?? NaN,
username: proxyEndpoint.username,
password: proxyEndpoint.password
}
}
return undefined;
}

6 changes: 4 additions & 2 deletions extensions/azurecore/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export const EnableArcFeaturesSection = 'enableArcFeatures';

export const ServiceName = 'azuredatastudio';

export const HttpConfigSection = 'http';

export const Proxy = 'proxy';

export const TenantSection = 'tenant';

export const NoSystemKeyChainSection = 'noSystemKeychain';
Expand All @@ -54,8 +58,6 @@ export const AccountVersion = '2.0';

export const Bearer = 'Bearer';

/** HTTP Client */
export const httpConfigSectionName = 'http';

/**
* Use SHA-256 algorithm
Expand Down
5 changes: 3 additions & 2 deletions extensions/azurecore/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec

}
updatePiiLoggingLevel();

let proxyUrl: string | undefined = vscode.workspace.getConfiguration(Constants.HttpConfigSection).get(Constants.Proxy);
cheenamalhotra marked this conversation as resolved.
Show resolved Hide resolved
let eventEmitter: vscode.EventEmitter<azurecore.CacheEncryptionKeys>;
// Create the provider service and activate
let providerService = await initAzureAccountProvider(extensionContext, storagePath).catch((err) => Logger.error(err));
Expand Down Expand Up @@ -186,7 +186,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
storageAccount: azurecore.azureResource.AzureGraphResource,
containerName: string,
ignoreErrors: boolean): Promise<azurecore.GetBlobsResult> {
return azureResourceUtils.getBlobs(account, subscription, storageAccount, containerName, ignoreErrors);
return azureResourceUtils.getBlobs(account, subscription, storageAccount, containerName, ignoreErrors, proxyUrl);
},
createResourceGroup(account: azurecore.AzureAccount,
subscription: azurecore.azureResource.AzureResourceSubscription,
Expand Down Expand Up @@ -285,3 +285,4 @@ function updatePiiLoggingLevel(): void {
const piiLogging: boolean = vscode.workspace.getConfiguration(Constants.AzureSection).get('piiLogging', false);
Logger.piiLogging = piiLogging;
}