@platform-mesh/portal-server-lib 0.5.43 → 0.5.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
+ import { K8sRequestContext, K8sResourceDescriptor } from '../models/k8s.js';
1
2
  import { KcpKubernetesService } from '../services/kcp-k8s.service.js';
2
3
  import { processContentConfigurationForAccountHierarchy } from '../utils/account-hierarchy-resolver.js';
3
4
  import { welcomeNodeConfig } from './models/welcome-node-config.js';
4
- import { PromiseMiddlewareWrapper } from '@kubernetes/client-node/dist/gen/middleware.js';
5
5
  import { Injectable } from '@nestjs/common';
6
6
  import {
7
7
  ContentConfiguration,
@@ -31,20 +31,11 @@ export class KubernetesServiceProvidersService implements ServiceProviderService
31
31
  throw new Error('Context with organization is required');
32
32
  }
33
33
 
34
- const entity = !entities || !entities.length ? 'main' : entities[0];
35
-
36
- let response;
37
- try {
38
- response = await this.getKubernetesResources(entity, context, token);
39
- } catch (error) {
40
- console.error(error);
41
-
42
- if (error.code == 429 || error.statusCode == 429) {
43
- await new Promise((resolve) => setTimeout(resolve, 1000));
44
- console.log('Retry after 1 second reading kubernetes resources.');
45
- response = await this.getKubernetesResources(entity, context, token);
46
- }
47
- }
34
+ const response = await this.listContentConfigurationsForEntity(
35
+ token,
36
+ entities,
37
+ context as K8sRequestContext,
38
+ );
48
39
 
49
40
  if (!response.items) {
50
41
  return {
@@ -86,40 +77,39 @@ export class KubernetesServiceProvidersService implements ServiceProviderService
86
77
  };
87
78
  }
88
79
 
89
- private async getKubernetesResources(
90
- entity: string,
91
- requestContext: Record<string, any>,
80
+ private async listContentConfigurationsForEntity(
92
81
  token: string,
82
+ entities: string[],
83
+ context: K8sRequestContext,
93
84
  ) {
94
- const gvr = {
85
+ const entity = !entities || !entities.length ? 'main' : entities[0];
86
+ const gvr: K8sResourceDescriptor = {
95
87
  group: 'ui.platform-mesh.io',
96
88
  version: 'v1alpha1',
97
89
  plural: 'contentconfigurations',
98
90
  labelSelector: `ui.platform-mesh.io/entity=${entity}`,
99
91
  };
100
92
 
101
- const k8sApi = this.kcpKubernetesService.getKcpK8sApiClient();
102
- return await k8sApi.listClusterCustomObject(gvr, {
103
- middleware: [
104
- new PromiseMiddlewareWrapper({
105
- pre: async (context) => {
106
- const accountPath =
107
- requestContext?.accountPath ??
108
- requestContext?.['core_platform-mesh_io_account'];
93
+ try {
94
+ return await this.kcpKubernetesService.listClusterCustomObjectInKcpVirtualWorkspace(
95
+ gvr,
96
+ context,
97
+ token,
98
+ );
99
+ } catch (error) {
100
+ console.error(error);
109
101
 
110
- const kcpUrl = this.kcpKubernetesService.getKcpVirtualWorkspaceUrl(
111
- requestContext.organization,
112
- accountPath,
113
- );
114
- const path = `${kcpUrl}/apis/${gvr.group}/${gvr.version}/${gvr.plural}`;
102
+ if (error.code == 429 || error.statusCode == 429) {
103
+ await new Promise((resolve) => setTimeout(resolve, 1000));
104
+ console.log('Retry after 1 second reading kubernetes resources.');
105
+ return await this.kcpKubernetesService.listClusterCustomObjectInKcpVirtualWorkspace(
106
+ gvr,
107
+ context,
108
+ token,
109
+ );
110
+ }
111
+ }
115
112
 
116
- context.setUrl(path);
117
- context.setHeaderParam('Authorization', `Bearer ${token}`);
118
- return context;
119
- },
120
- post: async (context) => context,
121
- }),
122
- ],
123
- });
113
+ return {};
124
114
  }
125
115
  }