diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +{} diff --git a/vscode/src/azure/commands.ts b/vscode/src/azure/commands.ts index 3b9eeffe3b..c09b36e665 100644 --- a/vscode/src/azure/commands.ts +++ b/vscode/src/azure/commands.ts @@ -23,6 +23,7 @@ import { QuantumUris, checkCorsConfig, compileToBitcode, + useProxy, } from "./networkRequests"; import { getQirForActiveWindow } from "../qirGeneration"; import { targetSupportQir } from "./providerProperties"; @@ -228,7 +229,7 @@ export async function initAzureWorkspaces(context: vscode.ExtensionContext) { const token = await getTokenForWorkspace(workspace); if (!token) return; try { - await checkCorsConfig(token, quantumUris); + if (!useProxy) await checkCorsConfig(token, quantumUris); } catch (e: any) { log.debug("CORS check failed. ", e); diff --git a/vscode/src/azure/networkRequests.ts b/vscode/src/azure/networkRequests.ts index 79edffad95..7cf3185000 100644 --- a/vscode/src/azure/networkRequests.ts +++ b/vscode/src/azure/networkRequests.ts @@ -2,12 +2,13 @@ // Licensed under the MIT License. import { log } from "qsharp-lang"; -import { workspace } from "vscode"; import { EventType, UserFlowStatus, sendTelemetryEvent } from "../telemetry"; import { getRandomGuid } from "../utils"; const publicMgmtEndpoint = "https://management.azure.com"; +export const useProxy = true; + export async function azureRequest( uri: string, token: string, @@ -65,6 +66,8 @@ export async function azureRequest( export async function storageRequest( uri: string, method: string, + token?: string, + proxy?: string, extraHeaders?: [string, string][], body?: string | Uint8Array, correlationId?: string, @@ -73,15 +76,13 @@ export async function storageRequest( ["x-ms-version", "2023-01-03"], ["x-ms-date", new Date().toUTCString()], ]; - const storageProxy: string | undefined = workspace - .getConfiguration("Q#") - .get("storageProxy"); // e.g. in settings.json: "Q#.storageProxy": "https://qsx-proxy.azurewebsites.net/api/proxy"; + if (token) headers.push(["Authorization", `Bearer ${token}`]); if (extraHeaders?.length) headers.push(...extraHeaders); - if (storageProxy) { + if (proxy) { log.debug(`Setting x-proxy-to header to ${uri}`); headers.push(["x-proxy-to", uri]); - uri = storageProxy; + uri = proxy; } try { log.debug(`Fetching ${uri} with method ${method}`); @@ -165,6 +166,10 @@ export class QuantumUris { sasUri() { return `${this.endpoint}${this.id}/storage/sasUri?api-version=${this.apiVersion}`; } + + storageProxy() { + return `${this.endpoint}${this.id}/storage/proxy?api-version=${this.apiVersion}`; + } } export class StorageUris { diff --git a/vscode/src/azure/workspaceActions.ts b/vscode/src/azure/workspaceActions.ts index e213e9a968..2812842984 100644 --- a/vscode/src/azure/workspaceActions.ts +++ b/vscode/src/azure/workspaceActions.ts @@ -9,6 +9,7 @@ import { QuantumUris, ResponseTypes, storageRequest, + useProxy, } from "./networkRequests"; import { WorkspaceConnection } from "./treeView"; import { @@ -453,7 +454,12 @@ export async function getJobFiles( const sasUri = decodeURI(sasResponse.sasUri); log.trace(`Got SAS URI: ${sasUri}`); - const file = await storageRequest(sasUri, "GET"); + const file = await storageRequest( + sasUri, + "GET", + useProxy ? token : undefined, + useProxy ? quantumUris.storageProxy() : undefined, + ); if (!file) { sendTelemetryEvent( @@ -545,6 +551,8 @@ export async function submitJob( await storageRequest( containerPutUri, "PUT", + useProxy ? token : undefined, + useProxy ? quantumUris.storageProxy() : undefined, undefined, undefined, correlationId, @@ -555,7 +563,12 @@ export async function submitJob( await storageRequest( inputDataUri, "PUT", - [["x-ms-blob-type", "BlockBlob"]], + useProxy ? token : undefined, + useProxy ? quantumUris.storageProxy() : undefined, + [ + ["x-ms-blob-type", "BlockBlob"], + ["Content-Type", "text/plain"], + ], qirFile, correlationId, );