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; forwardingId: string;
} }
export interface IDbAccountAllow {
status: number;
message?: string;
type?: string;
}
export interface IResponse<T> { export interface IResponse<T> {
status: number; status: number;
data: T; data: T;
@ -563,4 +569,5 @@ export enum PhoenixErrorType {
RegionNotServicable = "RegionNotServicable", RegionNotServicable = "RegionNotServicable",
SubscriptionNotAllowed = "SubscriptionNotAllowed", SubscriptionNotAllowed = "SubscriptionNotAllowed",
UnknownError = "UnknownError", UnknownError = "UnknownError",
PhoenixFlightFallback = "PhoenixFlightFallback",
} }

View File

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

View File

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