diff --git a/src/components/app/app.ts b/src/components/app/app.ts index 63c11e3e1..245d99ff2 100644 --- a/src/components/app/app.ts +++ b/src/components/app/app.ts @@ -30,11 +30,6 @@ export class App { return; } - if (!settings["managementApiVersion"]) { - this.viewManager.addToast(startupError, `Management API version is missing. See setting managementApiVersion in the configuration file config.design.json`); - return; - } - try { const token = await this.authenticator.getAccessToken(); diff --git a/src/config.runtime.json b/src/config.runtime.json index b32bc8fd1..687e9c0a7 100644 --- a/src/config.runtime.json +++ b/src/config.runtime.json @@ -1,6 +1,5 @@ { "managementApiUrl": "https://.management.azure-api.net", - "managementApiVersion": "2019-12-01", "environment": "runtime", "backendUrl": "https://.developer.azure-api.net" } \ No newline at end of file diff --git a/src/constants.ts b/src/constants.ts index 8d3541707..3425773d6 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -87,7 +87,6 @@ export const AppType = "developerPortal"; export enum SettingNames { backendUrl = "backendUrl", managementApiUrl = "managementApiUrl", - managementApiVersion = "managementApiVersion", managementApiAccessToken = "managementApiAccessToken" } @@ -113,4 +112,6 @@ export enum GrantTypes { * the context of a user. */ clientCredentials = "clientCredentials" -} \ No newline at end of file +} + +export const managementApiVersion = "2019-12-01"; \ No newline at end of file diff --git a/src/services/aadService.ts b/src/services/aadService.ts index 7a2665e74..b11ad3371 100644 --- a/src/services/aadService.ts +++ b/src/services/aadService.ts @@ -30,10 +30,9 @@ export class AadService { private async exchangeIdToken(idToken: string, provider: string): Promise { let managementApiUrl = await this.settingsProvider.getSetting(Constants.SettingNames.managementApiUrl); managementApiUrl = Utils.ensureUrlArmified(managementApiUrl); - const managementApiVersion = await this.settingsProvider.getSetting(Constants.SettingNames.managementApiVersion); const request = { - url: `${managementApiUrl}/identity?api-version=${managementApiVersion}`, + url: `${managementApiUrl}/identity?api-version=${Constants.managementApiVersion}`, method: "GET", headers: [{ name: "Authorization", value: `${provider} id_token="${idToken}"` }] }; diff --git a/src/services/mapiClient.ts b/src/services/mapiClient.ts index 12e1ed28e..a3ca1f5e2 100644 --- a/src/services/mapiClient.ts +++ b/src/services/mapiClient.ts @@ -22,8 +22,6 @@ export interface IHttpBatchResponse { export class MapiClient { private managementApiUrl: string; - private managementApiUrlBase: string; - private managementApiVersion: string; private environment: string; private initializePromise: Promise; private requestCache: TtlCache = new TtlCache(); @@ -50,17 +48,8 @@ export class MapiClient { throw new Error(`Management API URL ("${Constants.SettingNames.managementApiUrl}") setting is missing in configuration file.`); } - this.managementApiUrlBase = new URL(managementApiUrl).origin; this.managementApiUrl = Utils.ensureUrlArmified(managementApiUrl); - const managementApiVersion = settings[Constants.SettingNames.managementApiVersion]; - - if (!managementApiVersion) { - throw new Error(`Management API version ("${Constants.SettingNames.managementApiVersion}") setting is missing in configuration file.`); - } - - this.managementApiVersion = managementApiVersion; - const managementApiAccessToken = settings[Constants.SettingNames.managementApiAccessToken]; if (managementApiAccessToken) { @@ -132,7 +121,7 @@ export class MapiClient { } httpRequest.url = `${this.managementApiUrl}${Utils.ensureLeadingSlash(httpRequest.url)}`; - httpRequest.url = Utils.addQueryParameter(httpRequest.url, `api-version=${this.managementApiVersion}`); + httpRequest.url = Utils.addQueryParameter(httpRequest.url, `api-version=${Constants.managementApiVersion}`); let response: HttpResponse; diff --git a/src/services/provisioningService.ts b/src/services/provisioningService.ts index 9b482d8fe..6665b6dc9 100644 --- a/src/services/provisioningService.ts +++ b/src/services/provisioningService.ts @@ -32,18 +32,8 @@ export class ProvisionService { return Utils.ensureUrlArmified(managementApiUrl); } - private async getManagementApiVersion(): Promise { - const settings = await this.settingsProvider.getSettings(); - const managementApiVersion = settings[Constants.SettingNames.managementApiVersion]; - if (!managementApiVersion) { - throw new Error(`Management API version ("managementApiVersion") setting is missing in configuration file.`); - } - return managementApiVersion; - } - public async provision(): Promise { const managementApiUrl = await this.getManagementUrl(); - const managementApiVersion = await this.getManagementApiVersion(); const dataUrl = `/editors/themes/default.json`; try { @@ -57,7 +47,7 @@ export class ProvisionService { for (const key of keys) { const contentItem = dataObj[key]; - const url = `${managementApiUrl}${Utils.ensureLeadingSlash(key)}?api-version=${managementApiVersion}`; + const url = `${managementApiUrl}${Utils.ensureLeadingSlash(key)}?api-version=${Constants.managementApiVersion}`; const request: HttpRequest = { url: url, @@ -87,8 +77,7 @@ export class ProvisionService { private async cleanupContent(): Promise { const managementApiUrl = await this.getManagementUrl(); - const managementApiVersion = await this.getManagementApiVersion(); - const url = `${managementApiUrl}/contentTypes?api-version=${managementApiVersion}`; + const url = `${managementApiUrl}/contentTypes?api-version=${Constants.managementApiVersion}`; const accessToken = await this.authenticator.getAccessToken(); try { @@ -106,7 +95,7 @@ export class ProvisionService { for (const contentType of contentTypes) { const contentTypeName = contentType["name"]; const curReq: HttpRequest = { - url: `${managementApiUrl}/contentTypes/${contentTypeName}/contentItems?api-version=${managementApiVersion}`, + url: `${managementApiUrl}/contentTypes/${contentTypeName}/contentItems?api-version=${Constants.managementApiVersion}`, method: "GET", headers: [ { name: "If-Match", value: "*" }, @@ -118,7 +107,7 @@ export class ProvisionService { const items = Object.values(itemsResponse["value"]); for (const item of items) { const itemReq: HttpRequest = { - url: `${managementApiUrl}${item["id"]}?api-version=${managementApiVersion}`, + url: `${managementApiUrl}${item["id"]}?api-version=${Constants.managementApiVersion}`, method: "DELETE", headers: [ { name: "If-Match", value: "*" }, diff --git a/src/services/usersService.ts b/src/services/usersService.ts index 57d1ee4cd..356fc61ca 100644 --- a/src/services/usersService.ts +++ b/src/services/usersService.ts @@ -263,7 +263,6 @@ export class UsersService { public async createUserWithOAuth(provider: string, idToken: string, firstName: string, lastName: string, email: string): Promise { const managementApiUrl = await this.settingsProvider.getSetting("managementApiUrl"); - const managementApiVersion = await this.settingsProvider.getSetting("managementApiVersion"); const jwtToken = Utils.parseJwt(idToken); const user: UserPropertiesContract = { @@ -277,7 +276,7 @@ export class UsersService { }; const response = await this.httpClient.send({ - url: `${managementApiUrl}/users?api-version=${managementApiVersion}`, + url: `${managementApiUrl}/users?api-version=${Constants.managementApiVersion}`, method: "POST", headers: [ { name: "Content-Type", value: "application/json" },