microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
source/vscode/src/azure/test/REST API tests.http
141lines · modecode
| 1 | // For use with the "REST Client" VS Code extension https://github.com/Huachao/vscode-restclient |
| 2 | // to test the Azure management and Quantum REST API. |
| 3 | |
| 4 | @ARM_EP = management.azure.com |
| 5 | |
| 6 | // Set the following either in settings.json, or as variables in this file. |
| 7 | // See https://github.com/Huachao/vscode-restclient#environment-variables |
| 8 | // Note: To get the auth tokens, it's easiest to set breakpoints in the VS Code extension and grab them from there. |
| 9 | // The tokens and the SAS URI are only valid for a short time, so you'll need to get new ones each time you run this. |
| 10 | // |
| 11 | // @ARM_AAD_TOKEN = eyJ0eXAiOi... |
| 12 | // @QUANTUM_TOKEN = eyJhbGciOi... |
| 13 | // @QUANTUM_KEY = Xy..uA |
| 14 | // @BLOB_SASPARAMS = sv=2019-07-07&sig=5vxLvO... |
| 15 | // @QUANTUM_SUBID = 916dfd6d-030c-... |
| 16 | // @QUANTUM_RG = MyAzResourceGroup |
| 17 | // @QUANTUM_WORKSPACE = MyWorkspace |
| 18 | // @QUANTUM_ENDPOINT = westus2.quantum.azure.com |
| 19 | // @BLOB_ENDPOINT = storageaccountname.blob.core.windows.net |
| 20 | // @BLOB_CONTAINER = job-b639b6e7-... |
| 21 | |
| 22 | ### Get the tenants for a user |
| 23 | |
| 24 | // Use an AAD or MSA token here that should have scope 'https://management.azure.com/user_impersonation' |
| 25 | |
| 26 | GET https://{{ARM_EP}}/tenants?api-version=2020-01-01 |
| 27 | Authorization: Bearer {{ARM_AAD_TOKEN}} |
| 28 | Content-type: application/json |
| 29 | |
| 30 | ### Request all subscriptions for a user |
| 31 | |
| 32 | // Need to use an AAD token for here on (not MSA). This should have 'https://management.azure.com/user_impersonation' scope. |
| 33 | // If prior request was done with an MSA account/token, need to get an AAD token for the tenant of the subscription. |
| 34 | |
| 35 | GET https://{{ARM_EP}}/subscriptions?api-version=2020-01-01 |
| 36 | Authorization: Bearer {{ARM_AAD_TOKEN}} |
| 37 | Content-type: application/json |
| 38 | |
| 39 | ### Get all Quantum workspaces for a subscription |
| 40 | |
| 41 | GET https://{{ARM_EP}}/subscriptions/{{QUANTUM_SUBID}}/providers/Microsoft.Quantum/workspaces?api-version=2022-01-10-preview |
| 42 | Authorization: Bearer {{ARM_AAD_TOKEN}} |
| 43 | Content-type: application/json |
| 44 | |
| 45 | ### Get the quotas for a workspace |
| 46 | |
| 47 | // Note change of endpoint and token from here on. This should be for the account used above, but have the 'https://quantum.microsoft.com/user_impersonation' scope. |
| 48 | |
| 49 | GET https://{{QUANTUM_ENDPOINT}}/subscriptions/{{QUANTUM_SUBID}}/resourceGroups/{{QUANTUM_RG}}/providers/Microsoft.Quantum/Workspaces/{{QUANTUM_WORKSPACE}}/quotas?api-version=2022-09-12-preview |
| 50 | Authorization: Bearer {{QUANTUM_TOKEN}} |
| 51 | Content-type: application/json |
| 52 | |
| 53 | ### Provider status |
| 54 | GET https://{{QUANTUM_ENDPOINT}}/subscriptions/{{QUANTUM_SUBID}}/resourceGroups/{{QUANTUM_RG}}/providers/Microsoft.Quantum/Workspaces/{{QUANTUM_WORKSPACE}}/providerStatus?api-version=2022-09-12-preview |
| 55 | Authorization: Bearer {{QUANTUM_TOKEN}} |
| 56 | Content-type: application/json |
| 57 | |
| 58 | ### Provider status via API key |
| 59 | GET https://{{QUANTUM_ENDPOINT}}/subscriptions/{{QUANTUM_SUBID}}/resourceGroups/{{QUANTUM_RG}}/providers/Microsoft.Quantum/Workspaces/{{QUANTUM_WORKSPACE}}/providerStatus?api-version=2022-09-12-preview |
| 60 | x-ms-quantum-api-key: {{QUANTUM_KEY}} |
| 61 | Content-type: application/json |
| 62 | |
| 63 | ### Get jobs for the workspace |
| 64 | GET https://{{QUANTUM_ENDPOINT}}/subscriptions/{{QUANTUM_SUBID}}/resourceGroups/{{QUANTUM_RG}}/providers/Microsoft.Quantum/Workspaces/{{QUANTUM_WORKSPACE}}/jobs?api-version=2022-09-12-preview |
| 65 | Authorization: Bearer {{QUANTUM_TOKEN}} |
| 66 | Content-type: application/json |
| 67 | |
| 68 | ### Get a container sasURI |
| 69 | |
| 70 | POST https://{{QUANTUM_ENDPOINT}}/subscriptions/{{QUANTUM_SUBID}}/resourceGroups/{{QUANTUM_RG}}/providers/Microsoft.Quantum/Workspaces/{{QUANTUM_WORKSPACE}}/storage/sasUri?api-version=2022-09-12-preview |
| 71 | Accept: application/json |
| 72 | Content-Type: application/json |
| 73 | Authorization: Bearer {{QUANTUM_TOKEN}} |
| 74 | |
| 75 | {"containerName": "{{BLOB_CONTAINER}}"} |
| 76 | |
| 77 | |
| 78 | // === Working with blob storage === |
| 79 | // *** TODO: The following requests should be using the quantum service proxy now, not going direct to storage. |
| 80 | |
| 81 | // From here on, the requests are to blob storage, not the quantum endpoint. |
| 82 | |
| 83 | // Currently you need to PUT the job file, and GET results, directly from Azure Blob storage. |
| 84 | // You query the quantum endpoint to get SAS URIs to access the blob storage. |
| 85 | |
| 86 | // To submit a job |
| 87 | // - Get a blob storage SAS URI from the quantum endpoint via a POST with the container name in the body |
| 88 | // - PUT on the blob storage SAS URI to create the container |
| 89 | // - [optional?] Check via a GET that it was created |
| 90 | // - PUT the job file directly into the blob storage container |
| 91 | // - PUT on the quantum endpoint the job data to submit the job |
| 92 | // - GET the job status from the quantum endpoint until it is complete (Succeeded, Failed, or Cancelled) |
| 93 | // - GET the job output data from the blob storage container. |
| 94 | |
| 95 | // To just get the output data |
| 96 | // - Get a blob storage SAS URI from the quantum endpoint via a POST with the container name in the body |
| 97 | // - GET the output data from the blob storage container |
| 98 | |
| 99 | |
| 100 | # Below are requests to blob storage for the job file and output data. |
| 101 | |
| 102 | // SAS URI fields (see https://learn.microsoft.com/en-us/rest/api/storageservices/create-account-sas): |
| 103 | // - "sv=2019-07-07" is the API version (signed version) |
| 104 | // - "srt=co" means access to container and objects (signed resource types) |
| 105 | // - "sp=racw" means read, add, create, write (signed permissions) |
| 106 | // - "ss=b" means access to blob storage (signed services) |
| 107 | // - "se=2023-07-28T17:25:07Z" is the expiry date (signed expiry) |
| 108 | // - "sig=..." is the signature |
| 109 | |
| 110 | ### Cors check (note that x-ms-* headers must be enabled on the storage account) |
| 111 | OPTIONS https://{{BLOB_ENDPOINT}}/{{BLOB_CONTAINER}}/outputData?{{BLOB_SASPARAMS}} |
| 112 | Access-Control-Request-Method: GET |
| 113 | Host: swernlitest.blob.core.windows.net |
| 114 | Origin: vscode-file://vscode-app |
| 115 | Accept: */* |
| 116 | Accept-Encoding: gzip, deflate, br |
| 117 | Accept-Language: en-US |
| 118 | Access-Control-Request-Headers: x-ms-date,x-ms-version |
| 119 | Cache-Control: no-cache |
| 120 | Connection: keep-alive |
| 121 | Pragma: no-cache |
| 122 | Sec-Fetch-Dest: empty |
| 123 | Sec-Fetch-Mode: cors |
| 124 | Sec-Fetch-Site: cross-site |
| 125 | User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 13_5_0) AppleWebKit/537.36 (KHTML, like Gecko) Code/1.81.1 Chrome/108.0.5359.215 Electron/22.3.18 Safari/537.36 |
| 126 | |
| 127 | |
| 128 | ### Container properties (not that useful) |
| 129 | GET https://{{BLOB_ENDPOINT}}/{{BLOB_CONTAINER}}?restype=container&{{BLOB_SASPARAMS}} |
| 130 | x-ms-version: 2023-01-03 |
| 131 | x-ms-date: {{$datetime rfc1123}} |
| 132 | |
| 133 | ### Input data (QIR) |
| 134 | GET https://{{BLOB_ENDPOINT}}/{{BLOB_CONTAINER}}/inputData?{{BLOB_SASPARAMS}} |
| 135 | x-ms-version: 2023-01-03 |
| 136 | x-ms-date: {{$datetime rfc1123}} |
| 137 | |
| 138 | ### Output data (histogram) |
| 139 | GET https://{{BLOB_ENDPOINT}}/{{BLOB_CONTAINER}}/outputData?{{BLOB_SASPARAMS}} |
| 140 | x-ms-version: 2023-01-03 |
| 141 | x-ms-date: {{$datetime rfc1123}} |
| 142 | |