Enable phoenix based of allowed subscription and flights (#1291)

* Enable phoenix based of allowed subscription and flights
This commit is contained in:
Karthik chakravarthy 2022-06-15 17:08:06 -04:00 committed by GitHub
parent c731eb9cf9
commit 7abd65ac4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 6433 deletions

View File

@ -450,6 +450,12 @@ export interface IContainerData {
forwardingId: string;
}
export interface IDbAccountAllow {
status: number;
message?: string;
type?: string;
}
export interface IResponse<T> {
status: number;
data: T;
@ -563,4 +569,5 @@ export enum PhoenixErrorType {
RegionNotServicable = "RegionNotServicable",
SubscriptionNotAllowed = "SubscriptionNotAllowed",
UnknownError = "UnknownError",
PhoenixFlightFallback = "PhoenixFlightFallback",
}

View File

@ -4,12 +4,12 @@ import { PhoenixClient } from "Phoenix/PhoenixClient";
import create, { UseStore } from "zustand";
import { AuthType } from "../../AuthType";
import * as Constants from "../../Common/Constants";
import { ConnectionStatusType } from "../../Common/Constants";
import { ConnectionStatusType, HttpStatusCodes } from "../../Common/Constants";
import { getErrorMessage } from "../../Common/ErrorHandlingUtils";
import * as Logger from "../../Common/Logger";
import { configContext } from "../../ConfigContext";
import * as DataModels from "../../Contracts/DataModels";
import { ContainerConnectionInfo, ContainerInfo } from "../../Contracts/DataModels";
import { ContainerConnectionInfo, ContainerInfo, PhoenixErrorType } from "../../Contracts/DataModels";
import { useTabs } from "../../hooks/useTabs";
import { IPinnedRepo } from "../../Juno/JunoClient";
import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
@ -303,15 +303,23 @@ export const useNotebook: UseStore<NotebookState> = create((set, get) => ({
setContainerStatus: (containerStatus: ContainerInfo) => set({ containerStatus }),
getPhoenixStatus: async () => {
if (get().isPhoenixNotebooks === undefined || get().isPhoenixFeatures === undefined) {
let isPhoenix = false;
if (userContext.features.phoenixNotebooks || userContext.features.phoenixFeatures) {
const phoenixClient = new PhoenixClient();
isPhoenix = isPublicInternetAccessAllowed() && (await phoenixClient.isDbAcountWhitelisted());
let isPhoenixNotebooks = false;
let isPhoenixFeatures = false;
const isPublicInternetAllowed = isPublicInternetAccessAllowed();
const phoenixClient = new PhoenixClient();
const dbAccountAllowedInfo = await phoenixClient.getDbAccountAllowedStatus();
if (dbAccountAllowedInfo.status === HttpStatusCodes.OK) {
if (dbAccountAllowedInfo?.type === PhoenixErrorType.PhoenixFlightFallback) {
isPhoenixNotebooks = isPublicInternetAllowed && userContext.features.phoenixNotebooks;
isPhoenixFeatures = isPublicInternetAllowed && userContext.features.phoenixFeatures;
} else {
isPhoenixNotebooks = isPhoenixFeatures = isPublicInternetAllowed;
}
} else {
isPhoenixNotebooks = isPhoenixFeatures = false;
}
const isPhoenixNotebooks = userContext.features.phoenixNotebooks && isPhoenix;
const isPhoenixFeatures = userContext.features.phoenixFeatures && isPhoenix;
set({ isPhoenixNotebooks: isPhoenixNotebooks });
set({ isPhoenixFeatures: isPhoenixFeatures });
}

View File

@ -17,6 +17,7 @@ import {
ContainerConnectionInfo,
ContainerInfo,
IContainerData,
IDbAccountAllow,
IMaxAllocationTimeExceeded,
IMaxDbAccountsPerUserExceeded,
IMaxUsersPerDbAccountExceeded,
@ -161,15 +162,17 @@ export class PhoenixClient {
}
}
public async isDbAcountWhitelisted(): Promise<boolean> {
public async getDbAccountAllowedStatus(): Promise<IDbAccountAllow> {
const startKey = TelemetryProcessor.traceStart(Action.PhoenixDBAccountAllowed, {
dataExplorerArea: Areas.Notebook,
});
let responseJson;
try {
const response = await window.fetch(`${this.getPhoenixControlPlanePathPrefix()}`, {
method: "GET",
headers: PhoenixClient.getHeaders(),
});
responseJson = await response?.json();
if (response.status !== HttpStatusCodes.OK) {
throw new Error(`Received status code: ${response?.status}`);
}
@ -180,7 +183,11 @@ export class PhoenixClient {
},
startKey
);
return response.status === HttpStatusCodes.OK;
return {
status: response.status,
message: responseJson?.message,
type: responseJson?.type,
};
} catch (error) {
TelemetryProcessor.traceFailure(
Action.PhoenixDBAccountAllowed,
@ -192,7 +199,11 @@ export class PhoenixClient {
startKey
);
Logger.logError(getErrorMessage(error), "PhoenixClient/IsDbAcountWhitelisted");
return false;
return {
status: HttpStatusCodes.Forbidden,
message: responseJson?.message,
type: responseJson?.type,
};
}
}