@@ -3,30 +3,23 @@ import { KubeFastifyInstance, OauthFastifyRequest } from '../../../types';
33import { getAccessToken , getDirectCallOptions } from '../../../utils/directCallUtils' ;
44import { secureRoute } from '../../../utils/route-security' ;
55import { getNamespaces } from '../../../utils/notebookUtils' ;
6- import { orderBy } from 'lodash' ;
76import {
87 parseNamespacesData ,
98 getClientConfigs ,
109 fetchFromRegistry ,
1110 fetchConfigMap ,
12- batchFetchConfigMapsByNamespace ,
1311 type ClientConfigInfo ,
1412 handleError ,
1513} from './featureStoreUtils' ;
16- import { V1ConfigMap } from '@kubernetes/client-node' ;
17-
18- interface WorkbenchFeatureStoreConfig {
19- namespace : string ;
20- configName : string ;
21- configMap : V1ConfigMap | null ;
22- hasAccessToFeatureStore : boolean ;
23- }
2414
2515interface WorkbenchResponse {
26- clientConfigs : WorkbenchFeatureStoreConfig [ ] ;
2716 namespaces : Array < {
2817 namespace : string ;
29- clientConfigs : string [ ] ;
18+ clientConfigs : Array < {
19+ configName : string ;
20+ projectName : string ;
21+ hasAccessToFeatureStore : boolean ;
22+ } > ;
3023 } > ;
3124}
3225
@@ -38,7 +31,10 @@ async function checkFeatureStoreAccess(
3831) : Promise < boolean > {
3932 try {
4033 const projects = await fetchFromRegistry ( fastify , registryUrl , userToken ) ;
41- const hasAccess = projects && projects . length > 0 ;
34+ if ( ! projects || projects . length === 0 ) {
35+ return false ;
36+ }
37+ const hasAccess = projects . some ( ( p ) => p . name === projectName || p . project === projectName ) ;
4238 return hasAccess ;
4339 } catch ( error ) {
4440 fastify . log . info (
@@ -74,32 +70,6 @@ async function checkMultipleFeatureStoreAccess(
7470 return accessResults ;
7571}
7672
77- async function processNamespaceConfigs (
78- fastify : KubeFastifyInstance ,
79- namespace : string ,
80- clientConfigs : string [ ] ,
81- token ?: string ,
82- ) : Promise < WorkbenchFeatureStoreConfig [ ] > {
83- const clientConfigsData = await getClientConfigs ( fastify , { [ namespace ] : clientConfigs } ) ;
84-
85- if ( clientConfigsData . length === 0 ) {
86- return [ ] ;
87- }
88-
89- const accessResults = await checkMultipleFeatureStoreAccess ( fastify , clientConfigsData , token ) ;
90-
91- const configMapMap = await batchFetchConfigMapsByNamespace ( fastify , clientConfigsData ) ;
92-
93- const configsWithAccess = clientConfigsData . map ( ( config ) => ( {
94- namespace : config . namespace ,
95- configName : config . configName ,
96- configMap : configMapMap . get ( `${ config . namespace } /${ config . configName } ` ) || null ,
97- hasAccessToFeatureStore : accessResults . get ( config . projectName ) || false ,
98- } ) ) ;
99-
100- return orderBy ( configsWithAccess , [ 'hasAccessToFeatureStore' ] , [ 'desc' ] ) ;
101- }
102-
10373export default async ( fastify : KubeFastifyInstance ) : Promise < void > => {
10474 fastify . get (
10575 '/workbench-integration' ,
@@ -114,7 +84,6 @@ export default async (fastify: KubeFastifyInstance): Promise<void> => {
11484
11585 if ( ! feastConfig || ! feastConfig . data ?. namespaces ) {
11686 return reply . send ( {
117- clientConfigs : [ ] ,
11887 namespaces : [ ] ,
11988 } ) ;
12089 }
@@ -129,20 +98,38 @@ export default async (fastify: KubeFastifyInstance): Promise<void> => {
12998
13099 const token = await getAccessToken ( await getDirectCallOptions ( fastify , req , '' ) ) ;
131100
132- const namespacePromises = namespaces . map ( ( { namespace : ns , clientConfigs } ) =>
133- processNamespaceConfigs ( fastify , ns , clientConfigs , token ) ,
101+ const allClientConfigsData = await getClientConfigs (
102+ fastify ,
103+ Object . fromEntries (
104+ namespaces . map ( ( { namespace, clientConfigs } ) => [ namespace , clientConfigs ] ) ,
105+ ) ,
134106 ) ;
135107
136- const namespaceResults = await Promise . all ( namespacePromises ) ;
137- const allClientConfigs = orderBy (
138- namespaceResults . flat ( ) ,
139- [ 'hasAccessToFeatureStore' ] ,
140- [ 'desc' ] ,
108+ const accessResults = await checkMultipleFeatureStoreAccess (
109+ fastify ,
110+ allClientConfigsData ,
111+ token ,
141112 ) ;
142113
114+ const namespaceResults = namespaces . map ( ( { namespace } ) => {
115+ const namespaceConfigs = allClientConfigsData . filter (
116+ ( config ) => config . namespace === namespace ,
117+ ) ;
118+ const accessibleConfigs = namespaceConfigs
119+ . filter ( ( config ) => accessResults . get ( config . projectName ) )
120+ . map ( ( config ) => ( {
121+ configName : config . configName ,
122+ projectName : config . projectName ,
123+ hasAccessToFeatureStore : accessResults . get ( config . projectName ) ?? false ,
124+ } ) ) ;
125+ return {
126+ namespace,
127+ clientConfigs : accessibleConfigs ,
128+ } ;
129+ } ) ;
130+
143131 const response : WorkbenchResponse = {
144- clientConfigs : allClientConfigs ,
145- namespaces,
132+ namespaces : namespaceResults . filter ( ( ns ) => ns . clientConfigs . length > 0 ) ,
146133 } ;
147134
148135 return reply . send ( response ) ;
0 commit comments