Remove one indirection for ConfigContext

Things like ConfigContext.BACKEND_ENDPOINT are dynamically changed, and assigning them statically like this only bypasses that mechanism :(

Co-authored-by: Steve Faulkner <471400+southpolesteve@users.noreply.github.com>
This commit is contained in:
Jordi Bunster
2020-10-06 15:30:24 -07:00
committed by GitHub
parent f5bbd52311
commit 0cc38868a6
13 changed files with 49 additions and 76 deletions

View File

@@ -12,8 +12,6 @@ import { configContext } from "../../ConfigContext";
import { userContext } from "../../UserContext";
export default class AuthHeadersUtil {
// TODO: Figure out a way to determine the extension endpoint and serverId at runtime
public static extensionEndpoint: string = Constants.BackendEndpoints.productionPortal;
public static serverId: string = Constants.ServerIds.productionPortal;
private static readonly _firstPartyAppId: string = "203f1145-856a-4232-83d4-a43568fba23d";
@@ -41,7 +39,7 @@ export default class AuthHeadersUtil {
public static getAccessInputMetadata(accessInput: string): Q.Promise<DataModels.AccessInputMetadata> {
const deferred: Q.Deferred<DataModels.AccessInputMetadata> = Q.defer<DataModels.AccessInputMetadata>();
const url: string = `${AuthHeadersUtil.extensionEndpoint}${Constants.ApiEndpoints.guestRuntimeProxy}/accessinputmetadata`;
const url = `${configContext.BACKEND_ENDPOINT}${Constants.ApiEndpoints.guestRuntimeProxy}/accessinputmetadata`;
const authType: string = (<any>window).authType;
const headers: { [headerName: string]: string } = {};
@@ -86,9 +84,7 @@ export default class AuthHeadersUtil {
}
public static generateEncryptedToken(): Q.Promise<DataModels.GenerateTokenResponse> {
const url: string = `${
AuthHeadersUtil.extensionEndpoint
}/api/tokens/generateToken${AuthHeadersUtil._generateResourceUrl()}`;
const url = configContext.BACKEND_ENDPOINT + "/api/tokens/generateToken" + AuthHeadersUtil._generateResourceUrl();
const explorer = window.dataExplorer;
const headers: any = { authorization: userContext.authorizationToken };
headers[Constants.HttpHeaders.getReadOnlyKey] = !explorer.hasWriteAccess();
@@ -109,7 +105,7 @@ export default class AuthHeadersUtil {
return Q.reject("None or empty connection string specified");
}
const url: string = `${AuthHeadersUtil.extensionEndpoint}/api/guest/tokens/generateToken`;
const url = configContext.BACKEND_ENDPOINT + "/api/guest/tokens/generateToken";
const headers: any = {};
headers[Constants.HttpHeaders.connectionString] = connectionString;

View File

@@ -24,12 +24,12 @@ import { SubscriptionUtilMappings } from "../../Shared/Constants";
import "../../Explorer/Tables/DataTable/DataTableBindingManager";
import Explorer from "../../Explorer/Explorer";
import { updateUserContext } from "../../UserContext";
import { configContext } from "../../ConfigContext";
export default class Main {
private static _databaseAccountId: string;
private static _encryptedToken: string;
private static _accessInputMetadata: AccessInputMetadata;
private static _defaultSubscriptionType: ViewModels.SubscriptionType = ViewModels.SubscriptionType.Free;
private static _features: { [key: string]: string };
// For AAD, Need to post message to hosted frame to do the auth
// Use local deferred variable as work around until we find better solution
@@ -315,7 +315,7 @@ export default class Main {
csmEndpoint: undefined,
dnsSuffix: null,
serverId: serverId,
extensionEndpoint: AuthHeadersUtil.extensionEndpoint,
extensionEndpoint: configContext.BACKEND_ENDPOINT,
subscriptionType: CollectionCreation.DefaultSubscriptionType,
quotaId: undefined,
addCollectionDefaultFlight: explorer.flight(),
@@ -335,7 +335,7 @@ export default class Main {
csmEndpoint: undefined,
dnsSuffix: null,
serverId: serverId,
extensionEndpoint: AuthHeadersUtil.extensionEndpoint,
extensionEndpoint: configContext.BACKEND_ENDPOINT,
subscriptionType: CollectionCreation.DefaultSubscriptionType,
quotaId: undefined,
addCollectionDefaultFlight: explorer.flight(),
@@ -365,7 +365,7 @@ export default class Main {
csmEndpoint: undefined,
dnsSuffix: null,
serverId: serverId,
extensionEndpoint: AuthHeadersUtil.extensionEndpoint,
extensionEndpoint: configContext.BACKEND_ENDPOINT,
subscriptionType: CollectionCreation.DefaultSubscriptionType,
quotaId: undefined,
addCollectionDefaultFlight: explorer.flight(),
@@ -453,11 +453,6 @@ export default class Main {
return connectionString && connectionString.includes("type=resource");
}
private static _getSubscriptionTypeFromQuotaId(quotaId: string): ViewModels.SubscriptionType {
const subscriptionType: ViewModels.SubscriptionType = SubscriptionUtilMappings.SubscriptionTypeMap[quotaId];
return subscriptionType || Main._defaultSubscriptionType;
}
private static _renewExplorerAccessWithResourceToken = (
explorer: Explorer,
connectionString: string