diff --git a/client/src/services/apiProxy.ts b/client/src/services/apiProxy.ts index d144c03..82ba7fc 100644 --- a/client/src/services/apiProxy.ts +++ b/client/src/services/apiProxy.ts @@ -2,7 +2,7 @@ import _ from 'lodash'; import {getToken, logout} from './auth'; import log from '../utils/log'; import {ApiItem} from '../utils/types'; -import {isProtoEligible, isProtoEnabled, protoParser} from '../utils/protoHelpers'; +import {isProtoEligible, protoParser} from '../utils/protoHelpers'; type StreamCallback = (data: T) => void; type ErrorCallback = (err: Error) => void; @@ -62,7 +62,7 @@ async function requestInner(path: string, params?: any, autoLogoutOnAuthError = } export async function request(path: string, params?: any, autoLogoutOnAuthError = true) { - if (isProtoEligible(path) && isProtoEnabled()) { + if (isProtoEligible(path)) { return requestProto(path, params, autoLogoutOnAuthError); } return requestJson(path, params, autoLogoutOnAuthError); diff --git a/client/src/utils/protoHelpers.ts b/client/src/utils/protoHelpers.ts index 5a2eda2..3618c86 100644 --- a/client/src/utils/protoHelpers.ts +++ b/client/src/utils/protoHelpers.ts @@ -18,36 +18,36 @@ export const kindMap: { | typeof EventList | typeof NodeList | typeof PodList, - path: string + paths: string[] } } = { NodeMetrics: { proto: NodeMetrics, - path: '/apis/metrics.k8s.io/v1beta1/node', + paths: ['/apis/metrics.k8s.io/v1beta1/node'], }, NodeMetricsList: { proto: NodeMetricsList, - path: '/apis/metrics.k8s.io/v1beta1/nodes', + paths: ['/apis/metrics.k8s.io/v1beta1/nodes'], }, PodMetrics: { proto: PodMetrics, - path: '/apis/metrics.k8s.io/v1beta1/pod', + paths: ['/apis/metrics.k8s.io/v1beta1/pod'], }, PodMetricsList: { proto: PodMetricsList, - path: '/apis/metrics.k8s.io/v1beta1/pods', + paths: ['/apis/metrics.k8s.io/v1beta1/pods'], }, EventList: { proto: EventList, - path: 'api/v1/events', + paths: ['api/v1/events'], }, NodeList: { proto: NodeList, - path: 'api/v1/nodes', + paths: ['api/v1/nodes'], }, PodList: { proto: PodList, - path: 'api/v1/pods', + paths: ['api/v1/pods', 'v1beta1/namespaces/kube-system/pods', 'v1/namespaces/kube-system/pods'], }, }; @@ -67,23 +67,11 @@ export function protoParser(raw: Uint8Array) { return {}; } -export function isProtoEnabled(): boolean { - return window.localStorage.getItem('protoEnabled') === 'true'; -} - export function isProtoEligible(url: string) { for (const value of Object.values(kindMap)) { - if (url.includes(value.path)) { + if (value.paths.some(path => url.includes(path))) { return true; } } return false; } - -export function enableProto(): void { - window.localStorage.setItem('protoEnabled', 'true'); -} - -export function disableProto(): void { - window.localStorage.setItem('protoEnabled', 'false'); -}