diff --git a/src/common/cluster/cluster.ts b/src/common/cluster/cluster.ts index c8e7e69e90..ff0857869d 100644 --- a/src/common/cluster/cluster.ts +++ b/src/common/cluster/cluster.ts @@ -20,12 +20,12 @@ import { disposer, isDefined, isRequestError, toJS } from "../utils"; import type { Response } from "request"; import { clusterListNamespaceForbiddenChannel } from "../ipc/cluster"; import type { CanI } from "./authorization-review.injectable"; -import type { ListNamespaces } from "./list-namespaces.injectable"; +import type { ListNamespacesFor } from "./list-namespaces.injectable"; import assert from "assert"; import type { Logger } from "../logger"; import type { BroadcastMessage } from "../ipc/broadcast-message.injectable"; import type { LoadConfigfromFile } from "../kube-helpers/load-config-from-file.injectable"; -import type { CanListResource, RequestNamespaceListPermissions, RequestNamespaceListPermissionsFor } from "./request-namespace-list-permissions.injectable"; +import type { RequestNamespaceListPermissions, RequestNamespaceListPermissionsFor } from "./request-namespace-list-permissions.injectable"; import type { RequestApiResources } from "../../main/cluster/request-api-resources.injectable"; export interface ClusterDependencies { @@ -38,7 +38,7 @@ export interface ClusterDependencies { createAuthorizationReview: (config: KubeConfig) => CanI; requestApiResources: RequestApiResources; requestNamespaceListPermissionsFor: RequestNamespaceListPermissionsFor; - createListNamespaces: (config: KubeConfig) => ListNamespaces; + listNamespacesFor: ListNamespacesFor; createVersionDetector: (cluster: Cluster) => VersionDetector; broadcastMessage: BroadcastMessage; loadConfigfromFile: LoadConfigfromFile; @@ -644,7 +644,7 @@ export class Cluster implements ClusterModel { } try { - const listNamespaces = this.dependencies.createListNamespaces(proxyConfig); + const listNamespaces = this.dependencies.listNamespacesFor(proxyConfig); return await listNamespaces(); } catch (error) { @@ -672,10 +672,9 @@ export class Cluster implements ClusterModel { const canListResourceCheckers = await Promise.all(( this.allowedNamespaces.map(namespace => apiLimit(() => requestNamespaceListPermissions(namespace))) )); - const canListNamespacedResource: CanListResource = (resource) => canListResourceCheckers.some(fn => fn(resource)); return this.knownResources - .filter(canListNamespacedResource) + .filter((resource) => canListResourceCheckers.some(fn => fn(resource))) .map(formatKubeApiResource); } catch (error) { return []; diff --git a/src/common/cluster/list-namespaces.injectable.ts b/src/common/cluster/list-namespaces.injectable.ts index 468ff3ac2e..055feade9d 100644 --- a/src/common/cluster/list-namespaces.injectable.ts +++ b/src/common/cluster/list-namespaces.injectable.ts @@ -8,22 +8,21 @@ import { getInjectable } from "@ogre-tools/injectable"; import { isDefined } from "../utils"; export type ListNamespaces = () => Promise; +export type ListNamespacesFor = (config: KubeConfig) => ListNamespaces; -export function listNamespaces(config: KubeConfig): ListNamespaces { - const coreApi = config.makeApiClient(CoreV1Api); +const listNamespacesForInjectable = getInjectable({ + id: "list-namespaces-for", + instantiate: (): ListNamespacesFor => (config) => { + const coreApi = config.makeApiClient(CoreV1Api); - return async () => { - const { body: { items }} = await coreApi.listNamespace(); + return async () => { + const { body: { items }} = await coreApi.listNamespace(); - return items - .map(ns => ns.metadata?.name) - .filter(isDefined); - }; -} - -const listNamespacesInjectable = getInjectable({ - id: "list-namespaces", - instantiate: () => listNamespaces, + return items + .map(ns => ns.metadata?.name) + .filter(isDefined); + }; + }, }); -export default listNamespacesInjectable; +export default listNamespacesForInjectable; diff --git a/src/features/__snapshots__/extension-special-characters-in-page-registrations.test.tsx.snap b/src/features/__snapshots__/extension-special-characters-in-page-registrations.test.tsx.snap index ccf3a4153f..8f343f2a97 100644 --- a/src/features/__snapshots__/extension-special-characters-in-page-registrations.test.tsx.snap +++ b/src/features/__snapshots__/extension-special-characters-in-page-registrations.test.tsx.snap @@ -2,6 +2,9 @@ exports[`extension special characters in page registrations renders 1`] = `
+
@@ -285,6 +288,9 @@ exports[`extension special characters in page registrations renders 1`] = ` exports[`extension special characters in page registrations when navigating to route with ID having special characters renders 1`] = `
+
diff --git a/src/features/__snapshots__/navigate-to-extension-page.test.tsx.snap b/src/features/__snapshots__/navigate-to-extension-page.test.tsx.snap index b66ac6c4b3..8c99c03458 100644 --- a/src/features/__snapshots__/navigate-to-extension-page.test.tsx.snap +++ b/src/features/__snapshots__/navigate-to-extension-page.test.tsx.snap @@ -2,6 +2,9 @@ exports[`navigate to extension page renders 1`] = `
+
@@ -285,6 +288,9 @@ exports[`navigate to extension page renders 1`] = ` exports[`navigate to extension page when extension navigates to child route renders 1`] = `
+
@@ -489,6 +495,9 @@ exports[`navigate to extension page when extension navigates to child route rend exports[`navigate to extension page when extension navigates to route with parameters renders 1`] = `
+
@@ -709,6 +718,9 @@ exports[`navigate to extension page when extension navigates to route with param exports[`navigate to extension page when extension navigates to route without parameters renders 1`] = `
+
@@ -929,6 +941,9 @@ exports[`navigate to extension page when extension navigates to route without pa exports[`navigate to extension page when extension navigates to route without parameters when changing page parameters renders 1`] = `
+
diff --git a/src/features/__snapshots__/navigating-between-routes.test.tsx.snap b/src/features/__snapshots__/navigating-between-routes.test.tsx.snap index 98b22c8ec3..826bf44742 100644 --- a/src/features/__snapshots__/navigating-between-routes.test.tsx.snap +++ b/src/features/__snapshots__/navigating-between-routes.test.tsx.snap @@ -2,6 +2,9 @@ exports[`navigating between routes given route with optional path parameters when navigating to route with path parameters renders 1`] = `
+
@@ -209,6 +212,9 @@ exports[`navigating between routes given route with optional path parameters whe exports[`navigating between routes given route without path parameters when navigating to route renders 1`] = `
+
diff --git a/src/features/add-cluster/__snapshots__/navigation-using-application-menu.test.tsx.snap b/src/features/add-cluster/__snapshots__/navigation-using-application-menu.test.tsx.snap index 28cdcc4b8d..57a7c90e05 100644 --- a/src/features/add-cluster/__snapshots__/navigation-using-application-menu.test.tsx.snap +++ b/src/features/add-cluster/__snapshots__/navigation-using-application-menu.test.tsx.snap @@ -2,6 +2,9 @@ exports[`add-cluster - navigation using application menu renders 1`] = `
+
@@ -285,6 +288,9 @@ exports[`add-cluster - navigation using application menu renders 1`] = ` exports[`add-cluster - navigation using application menu when navigating to add cluster using application menu renders 1`] = `
+
diff --git a/src/features/application-update/__snapshots__/installing-update.test.ts.snap b/src/features/application-update/__snapshots__/installing-update.test.ts.snap index 6e61ea5e5d..4a71c1b8b4 100644 --- a/src/features/application-update/__snapshots__/installing-update.test.ts.snap +++ b/src/features/application-update/__snapshots__/installing-update.test.ts.snap @@ -3,6 +3,9 @@ exports[`installing update when started renders 1`] = `
+
@@ -288,6 +291,9 @@ exports[`installing update when started renders 1`] = ` exports[`installing update when started when user checks for updates renders 1`] = `
+
@@ -573,6 +579,9 @@ exports[`installing update when started when user checks for updates renders 1`] exports[`installing update when started when user checks for updates when new update is discovered renders 1`] = `
+
@@ -858,6 +867,9 @@ exports[`installing update when started when user checks for updates when new up exports[`installing update when started when user checks for updates when new update is discovered when download fails renders 1`] = `
+
@@ -1168,6 +1180,9 @@ exports[`installing update when started when user checks for updates when new up exports[`installing update when started when user checks for updates when new update is discovered when download succeeds renders 1`] = `
+
@@ -1478,6 +1493,9 @@ exports[`installing update when started when user checks for updates when new up exports[`installing update when started when user checks for updates when no new update is discovered renders 1`] = `
+
diff --git a/src/features/application-update/child-features/application-update-using-top-bar/__snapshots__/installing-update-using-topbar-button.test.tsx.snap b/src/features/application-update/child-features/application-update-using-top-bar/__snapshots__/installing-update-using-topbar-button.test.tsx.snap index a4787d0de3..d15b6b1783 100644 --- a/src/features/application-update/child-features/application-update-using-top-bar/__snapshots__/installing-update-using-topbar-button.test.tsx.snap +++ b/src/features/application-update/child-features/application-update-using-top-bar/__snapshots__/installing-update-using-topbar-button.test.tsx.snap @@ -3,6 +3,9 @@ exports[`encourage user to update when sufficient time passed since update was downloaded when started given the update check when update downloaded given some time passes, when checking for updates again when checking for updates resolves with same version that was previously downloaded renders 1`] = `
+
@@ -313,6 +316,9 @@ exports[`encourage user to update when sufficient time passed since update was d exports[`encourage user to update when sufficient time passed since update was downloaded when started renders 1`] = `
+
diff --git a/src/features/application-update/child-features/application-update-using-tray/__snapshots__/installing-update-using-tray.test.ts.snap b/src/features/application-update/child-features/application-update-using-tray/__snapshots__/installing-update-using-tray.test.ts.snap index a2ea7a417b..855cdb8734 100644 --- a/src/features/application-update/child-features/application-update-using-tray/__snapshots__/installing-update-using-tray.test.ts.snap +++ b/src/features/application-update/child-features/application-update-using-tray/__snapshots__/installing-update-using-tray.test.ts.snap @@ -3,6 +3,9 @@ exports[`installing update using tray when started renders 1`] = `
+
@@ -288,6 +291,9 @@ exports[`installing update using tray when started renders 1`] = ` exports[`installing update using tray when started when user checks for updates using tray renders 1`] = `
+
@@ -573,6 +579,9 @@ exports[`installing update using tray when started when user checks for updates exports[`installing update using tray when started when user checks for updates using tray when new update is discovered renders 1`] = `
+
@@ -858,6 +867,9 @@ exports[`installing update using tray when started when user checks for updates exports[`installing update using tray when started when user checks for updates using tray when new update is discovered when download fails renders 1`] = `
+
@@ -1168,6 +1180,9 @@ exports[`installing update using tray when started when user checks for updates exports[`installing update using tray when started when user checks for updates using tray when new update is discovered when download succeeds renders 1`] = `
+
@@ -1478,6 +1493,9 @@ exports[`installing update using tray when started when user checks for updates exports[`installing update using tray when started when user checks for updates using tray when no new update is discovered renders 1`] = `
+
diff --git a/src/features/application-update/child-features/force-user-to-update-when-too-long-time-since-update-was-downloaded/__snapshots__/force-user-to-update-when-too-long-time-since-update-was-downloaded.test.ts.snap b/src/features/application-update/child-features/force-user-to-update-when-too-long-time-since-update-was-downloaded/__snapshots__/force-user-to-update-when-too-long-time-since-update-was-downloaded.test.ts.snap index 95101e8294..a485039706 100644 --- a/src/features/application-update/child-features/force-user-to-update-when-too-long-time-since-update-was-downloaded/__snapshots__/force-user-to-update-when-too-long-time-since-update-was-downloaded.test.ts.snap +++ b/src/features/application-update/child-features/force-user-to-update-when-too-long-time-since-update-was-downloaded/__snapshots__/force-user-to-update-when-too-long-time-since-update-was-downloaded.test.ts.snap @@ -3,6 +3,9 @@ exports[`force user to update when too long since update was downloaded when application is started given checking for updates and it resolves, when update was downloaded renders 1`] = `
+
@@ -313,6 +316,9 @@ exports[`force user to update when too long since update was downloaded when app exports[`force user to update when too long since update was downloaded when application is started given checking for updates and it resolves, when update was downloaded when enough time passes to consider that update must be installed renders 1`] = `
+
@@ -670,6 +676,9 @@ exports[`force user to update when too long since update was downloaded when app exports[`force user to update when too long since update was downloaded when application is started given checking for updates and it resolves, when update was downloaded when not enough time passes to consider that update must be installed renders 1`] = `
+
diff --git a/src/features/application-update/child-features/periodical-checking-of-updates/__snapshots__/periodical-checking-of-updates.test.ts.snap b/src/features/application-update/child-features/periodical-checking-of-updates/__snapshots__/periodical-checking-of-updates.test.ts.snap index 413477ef9a..0daa435ff0 100644 --- a/src/features/application-update/child-features/periodical-checking-of-updates/__snapshots__/periodical-checking-of-updates.test.ts.snap +++ b/src/features/application-update/child-features/periodical-checking-of-updates/__snapshots__/periodical-checking-of-updates.test.ts.snap @@ -3,6 +3,9 @@ exports[`periodical checking of updates given updater is enabled and configuration exists, when started renders 1`] = `
+
diff --git a/src/features/application-update/child-features/selection-of-update-stability/__snapshots__/selection-of-update-stability.test.ts.snap b/src/features/application-update/child-features/selection-of-update-stability/__snapshots__/selection-of-update-stability.test.ts.snap index 7da7f42004..bf24df91d4 100644 --- a/src/features/application-update/child-features/selection-of-update-stability/__snapshots__/selection-of-update-stability.test.ts.snap +++ b/src/features/application-update/child-features/selection-of-update-stability/__snapshots__/selection-of-update-stability.test.ts.snap @@ -3,6 +3,9 @@ exports[`selection of update stability when started renders 1`] = `
+
diff --git a/src/features/cluster/__snapshots__/order-of-sidebar-items.test.tsx.snap b/src/features/cluster/__snapshots__/order-of-sidebar-items.test.tsx.snap index faf31e0cd7..9e2c867380 100644 --- a/src/features/cluster/__snapshots__/order-of-sidebar-items.test.tsx.snap +++ b/src/features/cluster/__snapshots__/order-of-sidebar-items.test.tsx.snap @@ -2,6 +2,9 @@ exports[`cluster - order of sidebar items when rendered renders 1`] = `
+
- +