Allow setting of ARM API version via query param (#241)

This commit is contained in:
Steve Faulkner 2020-10-02 10:45:32 -05:00 committed by GitHub
parent 0ad5fb465b
commit 3112cf5573
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -25,6 +25,7 @@ interface ConfigContext {
GITHUB_CLIENT_ID: string; GITHUB_CLIENT_ID: string;
GITHUB_CLIENT_SECRET?: string; // No need to inject secret for prod. Juno already knows it. GITHUB_CLIENT_SECRET?: string; // No need to inject secret for prod. Juno already knows it.
hostedExplorerURL: string; hostedExplorerURL: string;
armAPIVersion?: string;
} }
// Default configuration // Default configuration
@ -93,6 +94,10 @@ export async function initializeConfiguration(): Promise<ConfigContext> {
} }
// Allow override of platform value with URL query parameter // Allow override of platform value with URL query parameter
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
if (params.has("armAPIVersion")) {
const armAPIVersion = params.get("armAPIVersion") || "";
updateConfigContext({ armAPIVersion });
}
if (params.has("platform")) { if (params.has("platform")) {
const platform = params.get("platform"); const platform = params.get("platform");
switch (platform) { switch (platform) {

View File

@ -6,6 +6,7 @@ Instead, generate ARM clients that consume this function with stricter typing.
*/ */
import promiseRetry, { AbortError } from "p-retry"; import promiseRetry, { AbortError } from "p-retry";
import { configContext } from "../../ConfigContext";
import { userContext } from "../../UserContext"; import { userContext } from "../../UserContext";
interface ErrorResponse { interface ErrorResponse {
@ -43,7 +44,7 @@ interface Options {
// TODO: This is very similar to what is happening in ResourceProviderClient.ts. Should probably merge them. // TODO: This is very similar to what is happening in ResourceProviderClient.ts. Should probably merge them.
export async function armRequest<T>({ host, path, apiVersion, method, body: requestBody }: Options): Promise<T> { export async function armRequest<T>({ host, path, apiVersion, method, body: requestBody }: Options): Promise<T> {
const url = new URL(path, host); const url = new URL(path, host);
url.searchParams.append("api-version", apiVersion); url.searchParams.append("api-version", configContext.armAPIVersion || apiVersion);
const response = await window.fetch(url.href, { const response = await window.fetch(url.href, {
method, method,
headers: { headers: {