Skip to content

Commit

Permalink
Moved managementApiVersion setting to constant. (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
azaslonov authored Aug 27, 2020
1 parent 4fdcecc commit 15865fe
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 42 deletions.
5 changes: 0 additions & 5 deletions src/components/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ export class App {
return;
}

if (!settings["managementApiVersion"]) {
this.viewManager.addToast(startupError, `Management API version is missing. See setting <i>managementApiVersion</i> in the configuration file <i>config.design.json</i>`);
return;
}

try {
const token = await this.authenticator.getAccessToken();

Expand Down
2 changes: 0 additions & 2 deletions src/config.design.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"managementApiUrl": "https://<service-name>.management.azure-api.net",
"managementApiVersion": "2019-12-01",
"managementApiAccessToken": "SharedAccessSignature ...",
"managementApiUserId": "1",
"blobStorageContainer": "content",
"blobStorageUrl": "https://<account>.blob.core.windows.net?st=...",
"environment": "development",
Expand Down
1 change: 0 additions & 1 deletion src/config.publish.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"managementApiUrl": "https://<service-name>.management.azure-api.net",
"managementApiVersion": "2019-12-01",
"managementApiAccessToken": "SharedAccessSignature...",
"blobStorageContainer": "content",
"blobStorageConnectionString": "DefaultEndpointsProtocol=...",
Expand Down
1 change: 0 additions & 1 deletion src/config.runtime.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"managementApiUrl": "https://<service-name>.management.azure-api.net",
"managementApiVersion": "2019-12-01",
"environment": "runtime",
"backendUrl": "https://<service-name>.developer.azure-api.net"
}
5 changes: 3 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export const AppType = "developerPortal";
export enum SettingNames {
backendUrl = "backendUrl",
managementApiUrl = "managementApiUrl",
managementApiVersion = "managementApiVersion",
managementApiAccessToken = "managementApiAccessToken"
}

Expand All @@ -113,4 +112,6 @@ export enum GrantTypes {
* the context of a user.
*/
clientCredentials = "clientCredentials"
}
}

export const managementApiVersion = "2019-12-01";
3 changes: 1 addition & 2 deletions src/services/aadService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ export class AadService {
private async exchangeIdToken(idToken: string, provider: string): Promise<void> {
let managementApiUrl = await this.settingsProvider.getSetting<string>(Constants.SettingNames.managementApiUrl);
managementApiUrl = Utils.ensureUrlArmified(managementApiUrl);
const managementApiVersion = await this.settingsProvider.getSetting<string>(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}"` }]
};
Expand Down
13 changes: 1 addition & 12 deletions src/services/mapiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
private requestCache: TtlCache = new TtlCache();
Expand All @@ -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) {
Expand Down Expand Up @@ -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<T>;

Expand Down
19 changes: 4 additions & 15 deletions src/services/provisioningService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,8 @@ export class ProvisionService {
return Utils.ensureUrlArmified(managementApiUrl);
}

private async getManagementApiVersion(): Promise<string> {
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<void> {
const managementApiUrl = await this.getManagementUrl();
const managementApiVersion = await this.getManagementApiVersion();
const dataUrl = `/editors/themes/default.json`;

try {
Expand All @@ -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,
Expand Down Expand Up @@ -87,8 +77,7 @@ export class ProvisionService {

private async cleanupContent(): Promise<void> {
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 {
Expand All @@ -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: "*" },
Expand All @@ -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: "*" },
Expand Down
3 changes: 1 addition & 2 deletions src/services/usersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ export class UsersService {

public async createUserWithOAuth(provider: string, idToken: string, firstName: string, lastName: string, email: string): Promise<void> {
const managementApiUrl = await this.settingsProvider.getSetting<string>("managementApiUrl");
const managementApiVersion = await this.settingsProvider.getSetting<string>("managementApiVersion");
const jwtToken = Utils.parseJwt(idToken);

const user: UserPropertiesContract = {
Expand All @@ -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" },
Expand Down

0 comments on commit 15865fe

Please sign in to comment.