@kapeta/local-cluster-service 0.20.1 → 0.20.3
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.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/src/assetManager.d.ts +3 -2
- package/dist/cjs/src/assetManager.js +11 -0
- package/dist/cjs/src/config/routes.js +16 -5
- package/dist/cjs/src/configManager.d.ts +1 -0
- package/dist/cjs/src/configManager.js +9 -0
- package/dist/cjs/src/instanceManager.js +1 -8
- package/dist/cjs/src/networkManager.d.ts +2 -1
- package/dist/cjs/src/proxy/routes.js +1 -1
- package/dist/cjs/src/types.d.ts +1 -11
- package/dist/esm/src/assetManager.d.ts +3 -2
- package/dist/esm/src/assetManager.js +11 -0
- package/dist/esm/src/config/routes.js +16 -5
- package/dist/esm/src/configManager.d.ts +1 -0
- package/dist/esm/src/configManager.js +9 -0
- package/dist/esm/src/instanceManager.js +1 -8
- package/dist/esm/src/networkManager.d.ts +2 -1
- package/dist/esm/src/proxy/routes.js +1 -1
- package/dist/esm/src/types.d.ts +1 -11
- package/package.json +1 -1
- package/src/assetManager.ts +18 -3
- package/src/config/routes.ts +17 -6
- package/src/configManager.ts +15 -1
- package/src/instanceManager.ts +1 -10
- package/src/networkManager.ts +2 -2
- package/src/proxy/routes.ts +1 -1
- package/src/types.ts +1 -7
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## [0.20.3](https://github.com/kapetacom/local-cluster-service/compare/v0.20.2...v0.20.3) (2023-09-12)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* Resolve configuration when returning it for instance ([#77](https://github.com/kapetacom/local-cluster-service/issues/77)) ([e1f9ee6](https://github.com/kapetacom/local-cluster-service/commit/e1f9ee62877efcd87b8c5b21c42609f10842ece2))
|
7
|
+
|
8
|
+
## [0.20.2](https://github.com/kapetacom/local-cluster-service/compare/v0.20.1...v0.20.2) (2023-09-12)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* bump nodejs-registry-utils dependency ([408ec86](https://github.com/kapetacom/local-cluster-service/commit/408ec865791b7fd10170c3e27c1a174b8052d9c2))
|
14
|
+
|
1
15
|
## [0.20.1](https://github.com/kapetacom/local-cluster-service/compare/v0.20.0...v0.20.1) (2023-09-12)
|
2
16
|
|
3
17
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Definition } from '@kapeta/local-cluster-config';
|
2
|
-
import { BlockDefinition } from '@kapeta/schemas';
|
2
|
+
import { BlockDefinition, BlockInstance, Plan } from '@kapeta/schemas';
|
3
3
|
import { SourceOfChange } from './types';
|
4
4
|
export interface EnrichedAsset {
|
5
5
|
ref: string;
|
@@ -19,7 +19,8 @@ declare class AssetManager {
|
|
19
19
|
*/
|
20
20
|
getAssets(assetKinds?: string[]): Promise<EnrichedAsset[]>;
|
21
21
|
getPlans(): Promise<EnrichedAsset[]>;
|
22
|
-
getPlan(ref: string, noCache?: boolean): Promise<
|
22
|
+
getPlan(ref: string, noCache?: boolean): Promise<Plan>;
|
23
|
+
getBlockInstance(systemId: string, instanceId: string): Promise<BlockInstance>;
|
23
24
|
getAsset(ref: string, noCache?: boolean, autoFetch?: boolean): Promise<EnrichedAsset | undefined>;
|
24
25
|
createAsset(path: string, yaml: BlockDefinition, sourceOfChange?: SourceOfChange): Promise<EnrichedAsset[]>;
|
25
26
|
updateAsset(ref: string, yaml: BlockDefinition, sourceOfChange?: SourceOfChange): Promise<void>;
|
@@ -68,11 +68,22 @@ class AssetManager {
|
|
68
68
|
}
|
69
69
|
async getPlan(ref, noCache = false) {
|
70
70
|
const asset = await this.getAsset(ref, noCache);
|
71
|
+
if (!asset) {
|
72
|
+
throw new Error('Plan was not found: ' + ref);
|
73
|
+
}
|
71
74
|
if ('core/plan' !== asset?.kind) {
|
72
75
|
throw new Error('Asset was not a plan: ' + ref);
|
73
76
|
}
|
74
77
|
return asset.data;
|
75
78
|
}
|
79
|
+
async getBlockInstance(systemId, instanceId) {
|
80
|
+
const plan = await this.getPlan(systemId, true);
|
81
|
+
const instance = plan.spec.blocks?.find((instance) => instance.id === instanceId);
|
82
|
+
if (!instance) {
|
83
|
+
throw new Error(`Instance not found: ${instanceId} in plan ${systemId}`);
|
84
|
+
}
|
85
|
+
return instance;
|
86
|
+
}
|
76
87
|
async getAsset(ref, noCache = false, autoFetch = true) {
|
77
88
|
ref = (0, utils_1.normalizeKapetaUri)(ref);
|
78
89
|
const cacheKey = toKey(ref);
|
@@ -18,11 +18,22 @@ router.use('/', stringBody_1.stringBody);
|
|
18
18
|
/**
|
19
19
|
* Returns the full configuration for a given service.
|
20
20
|
*/
|
21
|
-
router.get('/instance', (req, res) => {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
router.get('/instance', async (req, res) => {
|
22
|
+
try {
|
23
|
+
let config = {};
|
24
|
+
if (req.kapeta.instanceId) {
|
25
|
+
config = await configManager_1.configManager.getConfigForBlockInstance(req.kapeta.systemId, req.kapeta.instanceId);
|
26
|
+
}
|
27
|
+
else {
|
28
|
+
config = configManager_1.configManager.getConfigForSystem(req.kapeta.systemId);
|
29
|
+
}
|
30
|
+
res.send(config);
|
31
|
+
}
|
32
|
+
catch (err) {
|
33
|
+
console.error('Failed to get instance config', err);
|
34
|
+
res.status(400).send({ error: err.message });
|
35
|
+
return;
|
36
|
+
}
|
26
37
|
});
|
27
38
|
/**
|
28
39
|
* Updates the full configuration for a given service.
|
@@ -12,6 +12,7 @@ declare class ConfigManager {
|
|
12
12
|
_forSystem(systemId: string): any;
|
13
13
|
setConfigForSystem(systemId: string, config: AnyMap): void;
|
14
14
|
getConfigForSystem(systemId: string): AnyMap;
|
15
|
+
getConfigForBlockInstance(systemId: string, instanceId: string): Promise<import("./types").AnyMap>;
|
15
16
|
setConfigForSection(systemId: string, sectionId: string, config: AnyMap): void;
|
16
17
|
getConfigForSection(systemId: string, sectionId: string): any;
|
17
18
|
/**
|
@@ -27,6 +27,15 @@ class ConfigManager {
|
|
27
27
|
systemId = (0, utils_1.normalizeKapetaUri)(systemId);
|
28
28
|
return this._forSystem(systemId);
|
29
29
|
}
|
30
|
+
async getConfigForBlockInstance(systemId, instanceId) {
|
31
|
+
const blockInstance = await assetManager_1.assetManager.getBlockInstance(systemId, instanceId);
|
32
|
+
const blockAsset = await assetManager_1.assetManager.getAsset(blockInstance.block.ref, true);
|
33
|
+
if (!blockAsset) {
|
34
|
+
throw new Error(`Block definition not found: ${blockInstance.block.ref}`);
|
35
|
+
}
|
36
|
+
const instanceConfig = this.getConfigForSection(systemId, instanceId);
|
37
|
+
return (0, utils_1.getResolvedConfiguration)(blockAsset.data.spec.configuration, instanceConfig, blockInstance.defaultConfiguration);
|
38
|
+
}
|
30
39
|
setConfigForSection(systemId, sectionId, config) {
|
31
40
|
systemId = (0, utils_1.normalizeKapetaUri)(systemId);
|
32
41
|
let systemConfig = this._forSystem(systemId);
|
@@ -319,14 +319,7 @@ class InstanceManager {
|
|
319
319
|
async start(systemId, instanceId) {
|
320
320
|
return this.exclusive(systemId, instanceId, async () => {
|
321
321
|
systemId = (0, utils_1.normalizeKapetaUri)(systemId);
|
322
|
-
const
|
323
|
-
if (!plan) {
|
324
|
-
throw new Error('Plan not found: ' + systemId);
|
325
|
-
}
|
326
|
-
const blockInstance = plan.spec && plan.spec.blocks ? lodash_1.default.find(plan.spec.blocks, { id: instanceId }) : null;
|
327
|
-
if (!blockInstance) {
|
328
|
-
throw new Error('Block instance not found: ' + instanceId);
|
329
|
-
}
|
322
|
+
const blockInstance = await assetManager_1.assetManager.getBlockInstance(systemId, instanceId);
|
330
323
|
const blockRef = (0, utils_1.normalizeKapetaUri)(blockInstance.block.ref);
|
331
324
|
const blockAsset = await assetManager_1.assetManager.getAsset(blockRef, true);
|
332
325
|
if (!blockAsset) {
|
@@ -35,7 +35,7 @@ router.all('/:systemId/:consumerInstanceId/:consumerResourceName/:type/*', async
|
|
35
35
|
const plan = await assetManager_1.assetManager.getPlan(req.params.systemId);
|
36
36
|
// We can find the connection by the consumer information alone since
|
37
37
|
// only 1 provider can be connected to a consumer resource at a time
|
38
|
-
const connection =
|
38
|
+
const connection = plan.spec.connections.find((connection) => {
|
39
39
|
return (connection.consumer.blockId.toLowerCase() === req.params.consumerInstanceId.toLowerCase() &&
|
40
40
|
connection.consumer.resourceName.toLowerCase() === req.params.consumerResourceName.toLowerCase());
|
41
41
|
});
|
package/dist/cjs/src/types.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import express from 'express';
|
2
|
-
import { Resource } from '@kapeta/schemas';
|
2
|
+
import { Connection, Resource } from '@kapeta/schemas';
|
3
3
|
import { StringBodyRequest } from './middleware/stringBody';
|
4
4
|
import { KapetaRequest } from './middleware/kapeta';
|
5
5
|
export type StringMap = {
|
@@ -68,16 +68,7 @@ export type InstanceInfo = {
|
|
68
68
|
pid?: number | string | null;
|
69
69
|
portType?: string;
|
70
70
|
};
|
71
|
-
interface ResourceRef {
|
72
|
-
blockId: string;
|
73
|
-
resourceName: string;
|
74
|
-
}
|
75
71
|
export type ProxyRequestHandler = (req: StringBodyRequest, res: express.Response, info: ProxyRequestInfo) => void;
|
76
|
-
export interface Connection {
|
77
|
-
mapping: any;
|
78
|
-
provider: ResourceRef;
|
79
|
-
consumer: ResourceRef;
|
80
|
-
}
|
81
72
|
export interface OperatorInfo {
|
82
73
|
host: string;
|
83
74
|
port: string;
|
@@ -105,4 +96,3 @@ export interface SimpleRequest {
|
|
105
96
|
body: any;
|
106
97
|
}
|
107
98
|
export type KapetaBodyRequest = KapetaRequest & StringBodyRequest;
|
108
|
-
export {};
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Definition } from '@kapeta/local-cluster-config';
|
2
|
-
import { BlockDefinition } from '@kapeta/schemas';
|
2
|
+
import { BlockDefinition, BlockInstance, Plan } from '@kapeta/schemas';
|
3
3
|
import { SourceOfChange } from './types';
|
4
4
|
export interface EnrichedAsset {
|
5
5
|
ref: string;
|
@@ -19,7 +19,8 @@ declare class AssetManager {
|
|
19
19
|
*/
|
20
20
|
getAssets(assetKinds?: string[]): Promise<EnrichedAsset[]>;
|
21
21
|
getPlans(): Promise<EnrichedAsset[]>;
|
22
|
-
getPlan(ref: string, noCache?: boolean): Promise<
|
22
|
+
getPlan(ref: string, noCache?: boolean): Promise<Plan>;
|
23
|
+
getBlockInstance(systemId: string, instanceId: string): Promise<BlockInstance>;
|
23
24
|
getAsset(ref: string, noCache?: boolean, autoFetch?: boolean): Promise<EnrichedAsset | undefined>;
|
24
25
|
createAsset(path: string, yaml: BlockDefinition, sourceOfChange?: SourceOfChange): Promise<EnrichedAsset[]>;
|
25
26
|
updateAsset(ref: string, yaml: BlockDefinition, sourceOfChange?: SourceOfChange): Promise<void>;
|
@@ -68,11 +68,22 @@ class AssetManager {
|
|
68
68
|
}
|
69
69
|
async getPlan(ref, noCache = false) {
|
70
70
|
const asset = await this.getAsset(ref, noCache);
|
71
|
+
if (!asset) {
|
72
|
+
throw new Error('Plan was not found: ' + ref);
|
73
|
+
}
|
71
74
|
if ('core/plan' !== asset?.kind) {
|
72
75
|
throw new Error('Asset was not a plan: ' + ref);
|
73
76
|
}
|
74
77
|
return asset.data;
|
75
78
|
}
|
79
|
+
async getBlockInstance(systemId, instanceId) {
|
80
|
+
const plan = await this.getPlan(systemId, true);
|
81
|
+
const instance = plan.spec.blocks?.find((instance) => instance.id === instanceId);
|
82
|
+
if (!instance) {
|
83
|
+
throw new Error(`Instance not found: ${instanceId} in plan ${systemId}`);
|
84
|
+
}
|
85
|
+
return instance;
|
86
|
+
}
|
76
87
|
async getAsset(ref, noCache = false, autoFetch = true) {
|
77
88
|
ref = (0, utils_1.normalizeKapetaUri)(ref);
|
78
89
|
const cacheKey = toKey(ref);
|
@@ -18,11 +18,22 @@ router.use('/', stringBody_1.stringBody);
|
|
18
18
|
/**
|
19
19
|
* Returns the full configuration for a given service.
|
20
20
|
*/
|
21
|
-
router.get('/instance', (req, res) => {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
router.get('/instance', async (req, res) => {
|
22
|
+
try {
|
23
|
+
let config = {};
|
24
|
+
if (req.kapeta.instanceId) {
|
25
|
+
config = await configManager_1.configManager.getConfigForBlockInstance(req.kapeta.systemId, req.kapeta.instanceId);
|
26
|
+
}
|
27
|
+
else {
|
28
|
+
config = configManager_1.configManager.getConfigForSystem(req.kapeta.systemId);
|
29
|
+
}
|
30
|
+
res.send(config);
|
31
|
+
}
|
32
|
+
catch (err) {
|
33
|
+
console.error('Failed to get instance config', err);
|
34
|
+
res.status(400).send({ error: err.message });
|
35
|
+
return;
|
36
|
+
}
|
26
37
|
});
|
27
38
|
/**
|
28
39
|
* Updates the full configuration for a given service.
|
@@ -12,6 +12,7 @@ declare class ConfigManager {
|
|
12
12
|
_forSystem(systemId: string): any;
|
13
13
|
setConfigForSystem(systemId: string, config: AnyMap): void;
|
14
14
|
getConfigForSystem(systemId: string): AnyMap;
|
15
|
+
getConfigForBlockInstance(systemId: string, instanceId: string): Promise<import("./types").AnyMap>;
|
15
16
|
setConfigForSection(systemId: string, sectionId: string, config: AnyMap): void;
|
16
17
|
getConfigForSection(systemId: string, sectionId: string): any;
|
17
18
|
/**
|
@@ -27,6 +27,15 @@ class ConfigManager {
|
|
27
27
|
systemId = (0, utils_1.normalizeKapetaUri)(systemId);
|
28
28
|
return this._forSystem(systemId);
|
29
29
|
}
|
30
|
+
async getConfigForBlockInstance(systemId, instanceId) {
|
31
|
+
const blockInstance = await assetManager_1.assetManager.getBlockInstance(systemId, instanceId);
|
32
|
+
const blockAsset = await assetManager_1.assetManager.getAsset(blockInstance.block.ref, true);
|
33
|
+
if (!blockAsset) {
|
34
|
+
throw new Error(`Block definition not found: ${blockInstance.block.ref}`);
|
35
|
+
}
|
36
|
+
const instanceConfig = this.getConfigForSection(systemId, instanceId);
|
37
|
+
return (0, utils_1.getResolvedConfiguration)(blockAsset.data.spec.configuration, instanceConfig, blockInstance.defaultConfiguration);
|
38
|
+
}
|
30
39
|
setConfigForSection(systemId, sectionId, config) {
|
31
40
|
systemId = (0, utils_1.normalizeKapetaUri)(systemId);
|
32
41
|
let systemConfig = this._forSystem(systemId);
|
@@ -319,14 +319,7 @@ class InstanceManager {
|
|
319
319
|
async start(systemId, instanceId) {
|
320
320
|
return this.exclusive(systemId, instanceId, async () => {
|
321
321
|
systemId = (0, utils_1.normalizeKapetaUri)(systemId);
|
322
|
-
const
|
323
|
-
if (!plan) {
|
324
|
-
throw new Error('Plan not found: ' + systemId);
|
325
|
-
}
|
326
|
-
const blockInstance = plan.spec && plan.spec.blocks ? lodash_1.default.find(plan.spec.blocks, { id: instanceId }) : null;
|
327
|
-
if (!blockInstance) {
|
328
|
-
throw new Error('Block instance not found: ' + instanceId);
|
329
|
-
}
|
322
|
+
const blockInstance = await assetManager_1.assetManager.getBlockInstance(systemId, instanceId);
|
330
323
|
const blockRef = (0, utils_1.normalizeKapetaUri)(blockInstance.block.ref);
|
331
324
|
const blockAsset = await assetManager_1.assetManager.getAsset(blockRef, true);
|
332
325
|
if (!blockAsset) {
|
@@ -35,7 +35,7 @@ router.all('/:systemId/:consumerInstanceId/:consumerResourceName/:type/*', async
|
|
35
35
|
const plan = await assetManager_1.assetManager.getPlan(req.params.systemId);
|
36
36
|
// We can find the connection by the consumer information alone since
|
37
37
|
// only 1 provider can be connected to a consumer resource at a time
|
38
|
-
const connection =
|
38
|
+
const connection = plan.spec.connections.find((connection) => {
|
39
39
|
return (connection.consumer.blockId.toLowerCase() === req.params.consumerInstanceId.toLowerCase() &&
|
40
40
|
connection.consumer.resourceName.toLowerCase() === req.params.consumerResourceName.toLowerCase());
|
41
41
|
});
|
package/dist/esm/src/types.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import express from 'express';
|
2
|
-
import { Resource } from '@kapeta/schemas';
|
2
|
+
import { Connection, Resource } from '@kapeta/schemas';
|
3
3
|
import { StringBodyRequest } from './middleware/stringBody';
|
4
4
|
import { KapetaRequest } from './middleware/kapeta';
|
5
5
|
export type StringMap = {
|
@@ -68,16 +68,7 @@ export type InstanceInfo = {
|
|
68
68
|
pid?: number | string | null;
|
69
69
|
portType?: string;
|
70
70
|
};
|
71
|
-
interface ResourceRef {
|
72
|
-
blockId: string;
|
73
|
-
resourceName: string;
|
74
|
-
}
|
75
71
|
export type ProxyRequestHandler = (req: StringBodyRequest, res: express.Response, info: ProxyRequestInfo) => void;
|
76
|
-
export interface Connection {
|
77
|
-
mapping: any;
|
78
|
-
provider: ResourceRef;
|
79
|
-
consumer: ResourceRef;
|
80
|
-
}
|
81
72
|
export interface OperatorInfo {
|
82
73
|
host: string;
|
83
74
|
port: string;
|
@@ -105,4 +96,3 @@ export interface SimpleRequest {
|
|
105
96
|
body: any;
|
106
97
|
}
|
107
98
|
export type KapetaBodyRequest = KapetaRequest & StringBodyRequest;
|
108
|
-
export {};
|
package/package.json
CHANGED
package/src/assetManager.ts
CHANGED
@@ -6,7 +6,7 @@ import { codeGeneratorManager } from './codeGeneratorManager';
|
|
6
6
|
import { ProgressListener } from './progressListener';
|
7
7
|
import { parseKapetaUri } from '@kapeta/nodejs-utils';
|
8
8
|
import { repositoryManager } from './repositoryManager';
|
9
|
-
import { BlockDefinition } from '@kapeta/schemas';
|
9
|
+
import { BlockDefinition, BlockInstance, Plan } from '@kapeta/schemas';
|
10
10
|
import { Actions } from '@kapeta/nodejs-registry-utils';
|
11
11
|
import { definitionsManager } from './definitionsManager';
|
12
12
|
import { normalizeKapetaUri } from './utils/utils';
|
@@ -86,14 +86,29 @@ class AssetManager {
|
|
86
86
|
return this.getAssets(['core/plan']);
|
87
87
|
}
|
88
88
|
|
89
|
-
async getPlan(ref: string, noCache: boolean = false) {
|
89
|
+
async getPlan(ref: string, noCache: boolean = false): Promise<Plan> {
|
90
90
|
const asset = await this.getAsset(ref, noCache);
|
91
91
|
|
92
|
+
if (!asset) {
|
93
|
+
throw new Error('Plan was not found: ' + ref);
|
94
|
+
}
|
95
|
+
|
92
96
|
if ('core/plan' !== asset?.kind) {
|
93
97
|
throw new Error('Asset was not a plan: ' + ref);
|
94
98
|
}
|
95
99
|
|
96
|
-
return asset.data;
|
100
|
+
return asset.data as Plan;
|
101
|
+
}
|
102
|
+
|
103
|
+
async getBlockInstance(systemId: string, instanceId: string): Promise<BlockInstance> {
|
104
|
+
const plan = await this.getPlan(systemId, true);
|
105
|
+
|
106
|
+
const instance = plan.spec.blocks?.find((instance) => instance.id === instanceId);
|
107
|
+
if (!instance) {
|
108
|
+
throw new Error(`Instance not found: ${instanceId} in plan ${systemId}`);
|
109
|
+
}
|
110
|
+
|
111
|
+
return instance;
|
97
112
|
}
|
98
113
|
|
99
114
|
async getAsset(
|
package/src/config/routes.ts
CHANGED
@@ -6,8 +6,10 @@ import { instanceManager } from '../instanceManager';
|
|
6
6
|
import { corsHandler } from '../middleware/cors';
|
7
7
|
import { kapetaHeaders, KapetaRequest } from '../middleware/kapeta';
|
8
8
|
import { stringBody } from '../middleware/stringBody';
|
9
|
-
import { KapetaBodyRequest } from '../types';
|
9
|
+
import { AnyMap, KapetaBodyRequest } from '../types';
|
10
10
|
import { Response } from 'express';
|
11
|
+
import { getResolvedConfiguration, normalizeKapetaUri } from '../utils/utils';
|
12
|
+
import { assetManager } from '../assetManager';
|
11
13
|
|
12
14
|
const router = Router();
|
13
15
|
|
@@ -18,12 +20,21 @@ router.use('/', stringBody);
|
|
18
20
|
/**
|
19
21
|
* Returns the full configuration for a given service.
|
20
22
|
*/
|
21
|
-
router.get('/instance', (req: KapetaBodyRequest, res: Response) => {
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
router.get('/instance', async (req: KapetaBodyRequest, res: Response) => {
|
24
|
+
try {
|
25
|
+
let config: AnyMap = {};
|
26
|
+
if (req.kapeta!.instanceId) {
|
27
|
+
config = await configManager.getConfigForBlockInstance(req.kapeta!.systemId, req.kapeta!.instanceId);
|
28
|
+
} else {
|
29
|
+
config = configManager.getConfigForSystem(req.kapeta!.systemId);
|
30
|
+
}
|
25
31
|
|
26
|
-
|
32
|
+
res.send(config);
|
33
|
+
} catch (err: any) {
|
34
|
+
console.error('Failed to get instance config', err);
|
35
|
+
res.status(400).send({ error: err.message });
|
36
|
+
return;
|
37
|
+
}
|
27
38
|
});
|
28
39
|
|
29
40
|
/**
|
package/src/configManager.ts
CHANGED
@@ -3,7 +3,7 @@ import { BlockInstance } from '@kapeta/schemas';
|
|
3
3
|
import { storageService } from './storageService';
|
4
4
|
import { assetManager } from './assetManager';
|
5
5
|
import { parseKapetaUri } from '@kapeta/nodejs-utils';
|
6
|
-
import { normalizeKapetaUri } from './utils/utils';
|
6
|
+
import { getResolvedConfiguration, normalizeKapetaUri } from './utils/utils';
|
7
7
|
|
8
8
|
export const SYSTEM_ID = '$plan';
|
9
9
|
type AnyMap = { [key: string]: any };
|
@@ -41,6 +41,20 @@ class ConfigManager {
|
|
41
41
|
return this._forSystem(systemId);
|
42
42
|
}
|
43
43
|
|
44
|
+
async getConfigForBlockInstance(systemId: string, instanceId: string) {
|
45
|
+
const blockInstance = await assetManager.getBlockInstance(systemId, instanceId);
|
46
|
+
const blockAsset = await assetManager.getAsset(blockInstance.block.ref, true);
|
47
|
+
if (!blockAsset) {
|
48
|
+
throw new Error(`Block definition not found: ${blockInstance.block.ref}`);
|
49
|
+
}
|
50
|
+
const instanceConfig = this.getConfigForSection(systemId, instanceId);
|
51
|
+
return getResolvedConfiguration(
|
52
|
+
blockAsset.data.spec.configuration,
|
53
|
+
instanceConfig,
|
54
|
+
blockInstance.defaultConfiguration
|
55
|
+
);
|
56
|
+
}
|
57
|
+
|
44
58
|
setConfigForSection(systemId: string, sectionId: string, config: AnyMap) {
|
45
59
|
systemId = normalizeKapetaUri(systemId);
|
46
60
|
let systemConfig = this._forSystem(systemId);
|
package/src/instanceManager.ts
CHANGED
@@ -407,16 +407,7 @@ export class InstanceManager {
|
|
407
407
|
public async start(systemId: string, instanceId: string): Promise<InstanceInfo | Task<InstanceInfo>> {
|
408
408
|
return this.exclusive(systemId, instanceId, async () => {
|
409
409
|
systemId = normalizeKapetaUri(systemId);
|
410
|
-
const
|
411
|
-
if (!plan) {
|
412
|
-
throw new Error('Plan not found: ' + systemId);
|
413
|
-
}
|
414
|
-
|
415
|
-
const blockInstance = plan.spec && plan.spec.blocks ? _.find(plan.spec.blocks, { id: instanceId }) : null;
|
416
|
-
if (!blockInstance) {
|
417
|
-
throw new Error('Block instance not found: ' + instanceId);
|
418
|
-
}
|
419
|
-
|
410
|
+
const blockInstance = await assetManager.getBlockInstance(systemId, instanceId);
|
420
411
|
const blockRef = normalizeKapetaUri(blockInstance.block.ref);
|
421
412
|
|
422
413
|
const blockAsset = await assetManager.getAsset(blockRef, true);
|
package/src/networkManager.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
import { Connection } from '@kapeta/schemas';
|
1
2
|
import uuid from 'node-uuid';
|
2
|
-
import {
|
3
|
-
import express from 'express';
|
3
|
+
import { SimpleRequest, SimpleResponse } from './types';
|
4
4
|
import { normalizeKapetaUri } from './utils/utils';
|
5
5
|
|
6
6
|
class NetworkManager {
|
package/src/proxy/routes.ts
CHANGED
@@ -42,7 +42,7 @@ router.all(
|
|
42
42
|
|
43
43
|
// We can find the connection by the consumer information alone since
|
44
44
|
// only 1 provider can be connected to a consumer resource at a time
|
45
|
-
const connection =
|
45
|
+
const connection = plan.spec.connections.find((connection) => {
|
46
46
|
return (
|
47
47
|
connection.consumer.blockId.toLowerCase() === req.params.consumerInstanceId.toLowerCase() &&
|
48
48
|
connection.consumer.resourceName.toLowerCase() === req.params.consumerResourceName.toLowerCase()
|
package/src/types.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import express from 'express';
|
2
|
-
import { Resource } from '@kapeta/schemas';
|
2
|
+
import { Connection, Resource } from '@kapeta/schemas';
|
3
3
|
import { StringBodyRequest } from './middleware/stringBody';
|
4
4
|
import { KapetaRequest } from './middleware/kapeta';
|
5
5
|
|
@@ -81,12 +81,6 @@ interface ResourceRef {
|
|
81
81
|
|
82
82
|
export type ProxyRequestHandler = (req: StringBodyRequest, res: express.Response, info: ProxyRequestInfo) => void;
|
83
83
|
|
84
|
-
export interface Connection {
|
85
|
-
mapping: any;
|
86
|
-
provider: ResourceRef;
|
87
|
-
consumer: ResourceRef;
|
88
|
-
}
|
89
|
-
|
90
84
|
export interface OperatorInfo {
|
91
85
|
host: string;
|
92
86
|
port: string;
|