karavan-core 4.8.0 → 99.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of karavan-core might be problematic. Click here for more details.
- package/index.js +3 -0
- package/package.json +8 -58
- package/.bebelrc +0 -3
- package/.mocharc.json +0 -11
- package/.prettierignore +0 -9
- package/.prettierrc +0 -14
- package/src/core/api/CamelDefinitionApi.ts +0 -3271
- package/src/core/api/CamelDefinitionApiExt.ts +0 -757
- package/src/core/api/CamelDefinitionYaml.ts +0 -412
- package/src/core/api/CamelDefinitionYamlStep.ts +0 -4733
- package/src/core/api/CamelDisplayUtil.ts +0 -143
- package/src/core/api/CamelUtil.ts +0 -360
- package/src/core/api/ComponentApi.ts +0 -368
- package/src/core/api/KameletApi.ts +0 -147
- package/src/core/api/MainConfigurationApi.ts +0 -47
- package/src/core/api/ProjectModelApi.ts +0 -75
- package/src/core/api/SpiBeanApi.ts +0 -104
- package/src/core/api/TemplateApi.ts +0 -58
- package/src/core/api/TopologyUtils.ts +0 -392
- package/src/core/api/VariableUtil.ts +0 -104
- package/src/core/model/CamelDefinition.ts +0 -3783
- package/src/core/model/CamelMetadata.ts +0 -2714
- package/src/core/model/ComponentModels.ts +0 -106
- package/src/core/model/IntegrationDefinition.ts +0 -188
- package/src/core/model/KameletModels.ts +0 -223
- package/src/core/model/MainConfigurationModel.ts +0 -37
- package/src/core/model/ProjectModel.ts +0 -43
- package/src/core/model/SpiBeanModels.ts +0 -53
- package/src/core/model/TopologyDefinition.ts +0 -117
- package/test/addStep.spec.ts +0 -124
- package/test/addStep1.yaml +0 -27
- package/test/allowableValues.camel.yaml +0 -19
- package/test/allowableValues.spec.ts +0 -30
- package/test/avro-serialize-action.kamelet.yaml +0 -70
- package/test/beans.spec.ts +0 -92
- package/test/beans1.yaml +0 -36
- package/test/beans2.yaml +0 -42
- package/test/beans3.yaml +0 -7
- package/test/checkRequired.spec.ts +0 -53
- package/test/circuitBreaker.spec.ts +0 -57
- package/test/circuitBreaker.yaml +0 -19
- package/test/cloneDefinition.spec.ts +0 -106
- package/test/createKamelet.spec.ts +0 -38
- package/test/cxf.json +0 -615
- package/test/cxf.spec.ts +0 -44
- package/test/cxf.yaml +0 -15
- package/test/deleteStep.spec.ts +0 -74
- package/test/demo.spec.ts +0 -49
- package/test/demo.yaml +0 -32
- package/test/doCatchOnWhen.camel.yaml +0 -20
- package/test/doCatchOnWhen.spec.ts +0 -36
- package/test/errorHandler.spec.ts +0 -38
- package/test/errorHandler1.yaml +0 -27
- package/test/expression.spec.ts +0 -55
- package/test/findStep.spec.ts +0 -112
- package/test/findStep.yaml +0 -65
- package/test/getElementProperties.spec.ts +0 -32
- package/test/getElementPropertiesByName.spec.ts +0 -31
- package/test/getExpressionLanguage.spec.ts +0 -40
- package/test/hasElementWithId.camel.yaml +0 -98
- package/test/hasElementWithId.spec.ts +0 -57
- package/test/hasElementWithId1.camel.yaml +0 -16
- package/test/hasElementWithIdError.camel.yaml +0 -98
- package/test/integration.spec.ts +0 -60
- package/test/integration1.yaml +0 -24
- package/test/integration2.yaml +0 -23
- package/test/integrationToYaml.spec.ts +0 -51
- package/test/intercept.spec.ts +0 -62
- package/test/intercept.yaml +0 -19
- package/test/is-not-integration.yaml +0 -5114
- package/test/isIntegration.spec.ts +0 -45
- package/test/kamelet.spec.ts +0 -61
- package/test/metadata/components.json +0 -697
- package/test/metadata/kamelets.yaml +0 -23414
- package/test/metadata/spiBeans.json +0 -3094
- package/test/multiObjectProperties.spec.ts +0 -46
- package/test/multiObjectProperties1.yaml +0 -19
- package/test/multiple.spec.ts +0 -38
- package/test/multiple.yaml +0 -29
- package/test/openapi.spec.ts +0 -48
- package/test/openapi.yaml +0 -7
- package/test/placeholder.spec.ts +0 -32
- package/test/placeholder.yaml +0 -133
- package/test/plain-try-catch.yaml +0 -31
- package/test/plain.spec.ts +0 -72
- package/test/plain1.yaml +0 -22
- package/test/plain2.yaml +0 -13
- package/test/plain3.yaml +0 -5
- package/test/plain4.yaml +0 -5
- package/test/postgresql-source.kamelet.yaml +0 -113
- package/test/restConfigDsl.yaml +0 -15
- package/test/restDsl.spec.ts +0 -83
- package/test/restDsl.yaml +0 -29
- package/test/routes.spec.ts +0 -37
- package/test/routes1.yaml +0 -31
- package/test/supported-components.json +0 -1221
- package/test/supportedComponents.spec.ts +0 -34
- package/test/template1.AggregationStrategy.java +0 -21
- package/test/template1.Processor.java +0 -13
- package/test/template2.AggregationStrategy.java +0 -21
- package/test/template2.Processor.java +0 -13
- package/test/templateApi.spec.ts +0 -45
- package/test/timer-source.kamelet.yaml +0 -75
- package/test/tod.spec.ts +0 -31
- package/test/tod.yaml +0 -9
- package/test/topology.spec.ts +0 -51
- package/test/topology1.camel.yaml +0 -56
- package/test/topology2.camel.yaml +0 -44
- package/test/topology3.camel.yaml +0 -27
- package/test/tsconfig.testing.json +0 -14
- package/test/updateStep.spec.ts +0 -72
- package/test/variable1.camel.yaml +0 -42
- package/test/variable2.camel.yaml +0 -42
- package/test/variables.spec.ts +0 -34
- package/tsconfig.json +0 -34
@@ -1,143 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Licensed to the Apache Software Foundation (ASF) under one or more
|
3
|
-
* contributor license agreements. See the NOTICE file distributed with
|
4
|
-
* this work for additional information regarding copyright ownership.
|
5
|
-
* The ASF licenses this file to You under the Apache License, Version 2.0
|
6
|
-
* (the "License"); you may not use this file except in compliance with
|
7
|
-
* the License. You may obtain a copy of the License at
|
8
|
-
*
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
*
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
* See the License for the specific language governing permissions and
|
15
|
-
* limitations under the License.
|
16
|
-
*/
|
17
|
-
import { Integration, CamelElement } from '../model/IntegrationDefinition';
|
18
|
-
import { CamelUtil } from './CamelUtil';
|
19
|
-
import { CamelDefinitionApi } from './CamelDefinitionApi';
|
20
|
-
import { CamelDefinitionApiExt } from './CamelDefinitionApiExt';
|
21
|
-
import { KameletModel } from '../model/KameletModels';
|
22
|
-
import { RouteDefinition } from '../model/CamelDefinition';
|
23
|
-
import { ComponentApi } from './ComponentApi';
|
24
|
-
import { CamelMetadataApi } from '../model/CamelMetadata';
|
25
|
-
|
26
|
-
export class CamelDisplayUtil {
|
27
|
-
private constructor() {}
|
28
|
-
|
29
|
-
static getTitle = (element: CamelElement): string => {
|
30
|
-
const k: KameletModel | undefined = CamelUtil.getKamelet(element);
|
31
|
-
if (k) {
|
32
|
-
return k.title();
|
33
|
-
} else if (element.dslName === 'RouteDefinition') {
|
34
|
-
const routeId = (element as RouteDefinition).id
|
35
|
-
return routeId ? routeId : CamelUtil.capitalizeName((element as any).stepName);
|
36
|
-
} else if ((element as any).uri && (['ToDefinition', 'FromDefinition', 'PollDefinition'].includes(element.dslName))) {
|
37
|
-
const uri = (element as any).uri
|
38
|
-
return ComponentApi.getComponentTitleFromUri(uri) || '';
|
39
|
-
} else {
|
40
|
-
const title = CamelMetadataApi.getCamelModelMetadataByClassName(element.dslName);
|
41
|
-
return title ? title.title : CamelUtil.capitalizeName((element as any).stepName);
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
static getDescription = (element: CamelElement): string => {
|
46
|
-
const kamelet: KameletModel | undefined = CamelUtil.getKamelet(element);
|
47
|
-
if (kamelet) {
|
48
|
-
return kamelet.spec.definition.description;
|
49
|
-
} else if ((element as any).uri && (['ToDefinition', 'FromDefinition', 'PollDefinition'].includes(element.dslName))) {
|
50
|
-
const uri = (element as any).uri
|
51
|
-
return ComponentApi.getComponentDescriptionFromUri(uri) || '';
|
52
|
-
} else {
|
53
|
-
const description = CamelMetadataApi.getCamelModelMetadataByClassName(element.dslName)?.description;
|
54
|
-
return description ? description : CamelDisplayUtil.getTitle(element);
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
static getStepDescription = (element: CamelElement): string => {
|
59
|
-
const description = (element as any).description;
|
60
|
-
return description ? description : CamelDisplayUtil.getTitle(element);
|
61
|
-
}
|
62
|
-
|
63
|
-
static isStepDefinitionExpanded = (integration: Integration, stepUuid: string, selectedUuid: string | undefined): boolean => {
|
64
|
-
const expandedUuids: string[] = [];
|
65
|
-
if (selectedUuid) {
|
66
|
-
expandedUuids.push(...CamelDisplayUtil.getParentStepDefinitions(integration, selectedUuid));
|
67
|
-
}
|
68
|
-
return expandedUuids.includes(stepUuid);
|
69
|
-
}
|
70
|
-
|
71
|
-
static getParentStepDefinitions = (integration: Integration, uuid: string): string[] => {
|
72
|
-
const result: string[] = [];
|
73
|
-
let meta = CamelDefinitionApiExt.findElementMetaInIntegration(integration, uuid);
|
74
|
-
let i = 0;
|
75
|
-
while (meta && meta.step?.dslName !== 'FromDefinition' && i < 100) {
|
76
|
-
i++;
|
77
|
-
if (meta.step?.dslName === 'StepDefinition') {
|
78
|
-
result.push(meta.step.uuid);
|
79
|
-
}
|
80
|
-
if (meta.parentUuid) {
|
81
|
-
meta = CamelDefinitionApiExt.findElementMetaInIntegration(integration, meta.parentUuid);
|
82
|
-
} else {
|
83
|
-
break;
|
84
|
-
}
|
85
|
-
}
|
86
|
-
return result;
|
87
|
-
}
|
88
|
-
|
89
|
-
static setIntegrationVisibility = (integration: Integration, selectedUuid: string | undefined): Integration => {
|
90
|
-
const clone: Integration = CamelUtil.cloneIntegration(integration);
|
91
|
-
const expandedUuids: string[] = [];
|
92
|
-
if (selectedUuid) {
|
93
|
-
expandedUuids.push(...CamelDisplayUtil.getParentStepDefinitions(integration, selectedUuid));
|
94
|
-
}
|
95
|
-
|
96
|
-
const flows: any[] = [];
|
97
|
-
for (const flow of clone.spec.flows || []) {
|
98
|
-
if (flow.dslName !== 'RouteDefinition') {
|
99
|
-
flows.push(flow);
|
100
|
-
} else {
|
101
|
-
const visibleRoute = CamelDisplayUtil.setElementVisibility(flow, true, expandedUuids);
|
102
|
-
if (Object.keys(visibleRoute).length !== 0) {
|
103
|
-
flows.push(visibleRoute);
|
104
|
-
}
|
105
|
-
}
|
106
|
-
}
|
107
|
-
|
108
|
-
clone.spec.flows = flows;
|
109
|
-
return clone;
|
110
|
-
}
|
111
|
-
|
112
|
-
static setElementVisibility = (step: CamelElement, showChildren: boolean, expandedUuids: string[]): CamelElement => {
|
113
|
-
const result = CamelDefinitionApi.createStep(step.dslName, step);
|
114
|
-
result.showChildren = showChildren;
|
115
|
-
if (result.dslName === 'StepDefinition') {
|
116
|
-
showChildren = expandedUuids.includes(result.uuid);
|
117
|
-
}
|
118
|
-
|
119
|
-
const elementChildDefinition = CamelDefinitionApiExt.getElementChildrenDefinition(step.dslName);
|
120
|
-
for (const element of elementChildDefinition) {
|
121
|
-
const camelElement = CamelDefinitionApiExt.getElementChildren(step, element);
|
122
|
-
if (element.multiple) {
|
123
|
-
(result as any)[element.name] = CamelDisplayUtil.setElementsVisibility((result as any)[element.name], showChildren, expandedUuids)
|
124
|
-
} else {
|
125
|
-
const prop = (result as any)[element.name];
|
126
|
-
if (prop && prop.hasOwnProperty('uuid')) {
|
127
|
-
(result as any)[element.name] = CamelDisplayUtil.setElementVisibility(camelElement[0], showChildren,expandedUuids)
|
128
|
-
}
|
129
|
-
}
|
130
|
-
}
|
131
|
-
return result;
|
132
|
-
}
|
133
|
-
|
134
|
-
static setElementsVisibility = (steps: CamelElement[] | undefined, showChildren: boolean, expandedUuids: string[]): CamelElement[] => {
|
135
|
-
const result: CamelElement[] = [];
|
136
|
-
if (steps) {
|
137
|
-
for (const step of steps) {
|
138
|
-
result.push(CamelDisplayUtil.setElementVisibility(step, showChildren, expandedUuids));
|
139
|
-
}
|
140
|
-
}
|
141
|
-
return result;
|
142
|
-
}
|
143
|
-
}
|
@@ -1,360 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Licensed to the Apache Software Foundation (ASF) under one or more
|
3
|
-
* contributor license agreements. See the NOTICE file distributed with
|
4
|
-
* this work for additional information regarding copyright ownership.
|
5
|
-
* The ASF licenses this file to You under the Apache License, Version 2.0
|
6
|
-
* (the "License"); you may not use this file except in compliance with
|
7
|
-
* the License. You may obtain a copy of the License at
|
8
|
-
*
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
*
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
* See the License for the specific language governing permissions and
|
15
|
-
* limitations under the License.
|
16
|
-
*/
|
17
|
-
import { Integration, CamelElement, Beans, MetadataLabels, KameletTypes } from '../model/IntegrationDefinition';
|
18
|
-
import { CamelDefinitionApi } from './CamelDefinitionApi';
|
19
|
-
import {
|
20
|
-
KameletDefinition,
|
21
|
-
BeanFactoryDefinition,
|
22
|
-
RouteConfigurationDefinition,
|
23
|
-
ToDefinition,
|
24
|
-
} from '../model/CamelDefinition';
|
25
|
-
import { KameletApi } from './KameletApi';
|
26
|
-
import { KameletModel, Property } from '../model/KameletModels';
|
27
|
-
import { ComponentProperty } from '../model/ComponentModels';
|
28
|
-
import { ComponentApi } from './ComponentApi';
|
29
|
-
import { CamelMetadataApi, SensitiveKeys } from '../model/CamelMetadata';
|
30
|
-
import { CamelDefinitionApiExt } from './CamelDefinitionApiExt';
|
31
|
-
import { v4 as uuidv4 } from 'uuid';
|
32
|
-
import { CamelDefinitionYaml } from './CamelDefinitionYaml';
|
33
|
-
|
34
|
-
export class CamelUtil {
|
35
|
-
private constructor() {
|
36
|
-
}
|
37
|
-
|
38
|
-
static cloneIntegration = (integration: Integration): Integration => {
|
39
|
-
const clone = JSON.parse(JSON.stringify(integration));
|
40
|
-
const int: Integration = new Integration({ ...clone });
|
41
|
-
const flows: any[] = [];
|
42
|
-
|
43
|
-
for (const flow of int.spec.flows || []) {
|
44
|
-
if (flow.dslName !== 'Beans') {
|
45
|
-
flows.push(CamelDefinitionApi.createStep(flow.dslName, flow));
|
46
|
-
} else {
|
47
|
-
const newBeans = new Beans();
|
48
|
-
newBeans.beans.push(...(flow as Beans).beans.map(bean => CamelUtil.cloneBean(bean)));
|
49
|
-
flows.push(newBeans);
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
for (const routeConfiguration of int.spec.flows?.filter(flow => flow.dslName === 'RouteConfiguration') || []) {
|
54
|
-
const newRouteConfiguration = CamelUtil.cloneRouteConfiguration(routeConfiguration);
|
55
|
-
flows.push(newRouteConfiguration);
|
56
|
-
}
|
57
|
-
|
58
|
-
int.spec.flows = flows;
|
59
|
-
return int;
|
60
|
-
};
|
61
|
-
|
62
|
-
static cloneStep = (step: CamelElement, generateUuids: boolean = false): CamelElement => {
|
63
|
-
const clone = JSON.parse(
|
64
|
-
JSON.stringify(step, (key, value) => {
|
65
|
-
if (generateUuids && key === 'uuid') {
|
66
|
-
return uuidv4();
|
67
|
-
} else {
|
68
|
-
return value;
|
69
|
-
}
|
70
|
-
}),
|
71
|
-
);
|
72
|
-
return CamelDefinitionApi.createStep(step.dslName, clone, true);
|
73
|
-
};
|
74
|
-
|
75
|
-
static cloneBean = (bean: BeanFactoryDefinition): BeanFactoryDefinition => {
|
76
|
-
const clone = JSON.parse(JSON.stringify(bean));
|
77
|
-
const newBean = new BeanFactoryDefinition(clone);
|
78
|
-
newBean.uuid = bean.uuid;
|
79
|
-
return newBean;
|
80
|
-
};
|
81
|
-
|
82
|
-
static cloneRouteConfiguration = (
|
83
|
-
routeConfiguration: RouteConfigurationDefinition,
|
84
|
-
): RouteConfigurationDefinition => {
|
85
|
-
const clone = JSON.parse(JSON.stringify(routeConfiguration));
|
86
|
-
const RouteConfiguration = new RouteConfigurationDefinition(clone);
|
87
|
-
RouteConfiguration.uuid = routeConfiguration.uuid;
|
88
|
-
return RouteConfiguration;
|
89
|
-
};
|
90
|
-
|
91
|
-
static capitalizeName = (name: string): string => {
|
92
|
-
if (name.length === 0) {
|
93
|
-
return name;
|
94
|
-
}
|
95
|
-
return name[0].toUpperCase() + name.substring(1);
|
96
|
-
};
|
97
|
-
|
98
|
-
static camelizeName = (name: string, separator: string, firstSmall: boolean): string => {
|
99
|
-
if (name.length === 0) return name;
|
100
|
-
const res = name
|
101
|
-
.split(separator)
|
102
|
-
.map(value => CamelUtil.capitalizeName(value))
|
103
|
-
.join('');
|
104
|
-
return firstSmall ? res[0].toLowerCase() + res.substring(1) : res;
|
105
|
-
};
|
106
|
-
|
107
|
-
static camelizeBody = (name: string, body: any, clone: boolean): any => {
|
108
|
-
if (body && Object.keys(body).length > 0) {
|
109
|
-
const oldKey = Object.keys(body)[0];
|
110
|
-
const key = CamelUtil.camelizeName(oldKey, '-', true);
|
111
|
-
return !clone && key === name ? { [key]: body[oldKey] } : body;
|
112
|
-
} else {
|
113
|
-
return {};
|
114
|
-
}
|
115
|
-
};
|
116
|
-
|
117
|
-
static camelizeObject = (body: any): any => {
|
118
|
-
if (Array.isArray(body)) {
|
119
|
-
return body.map(value => (typeof value === 'object' ? CamelUtil.camelizeObject(value) : value));
|
120
|
-
} else if (typeof body === 'object') {
|
121
|
-
const result: any = {};
|
122
|
-
for (const key in body) {
|
123
|
-
if (body?.hasOwnProperty(key)) {
|
124
|
-
const newKey = CamelUtil.camelizeName(key, '-', true);
|
125
|
-
const value = body[key];
|
126
|
-
if (typeof value === 'object' || Array.isArray(value)) {
|
127
|
-
result[newKey] = CamelUtil.camelizeObject(value);
|
128
|
-
} else {
|
129
|
-
result[newKey] = value;
|
130
|
-
}
|
131
|
-
}
|
132
|
-
}
|
133
|
-
return result;
|
134
|
-
} else {
|
135
|
-
return body;
|
136
|
-
}
|
137
|
-
};
|
138
|
-
|
139
|
-
static isKameletComponent = (element: CamelElement | undefined): boolean => {
|
140
|
-
if (element?.dslName === 'KameletDefinition') {
|
141
|
-
return true;
|
142
|
-
} else if (element?.dslName === 'FromDefinition' || element?.dslName === 'ToDefinition') {
|
143
|
-
const uri: string = (element as any).uri;
|
144
|
-
return uri !== undefined && uri.startsWith('kamelet:');
|
145
|
-
} else {
|
146
|
-
return false;
|
147
|
-
}
|
148
|
-
};
|
149
|
-
|
150
|
-
static getKamelet = (element: CamelElement): KameletModel | undefined => {
|
151
|
-
if (element.dslName === 'KameletDefinition') {
|
152
|
-
return KameletApi.findKameletByName((element as KameletDefinition).name || '');
|
153
|
-
} else if (element.dslName === 'ToDefinition' && (element as ToDefinition).uri?.startsWith('kamelet:')) {
|
154
|
-
const kameletName = (element as ToDefinition).uri?.replace('kamelet:', '');
|
155
|
-
return KameletApi.findKameletByName(kameletName);
|
156
|
-
} else if (['FromDefinition', 'FromDefinition', 'ToDefinition'].includes(element.dslName)) {
|
157
|
-
const uri: string = (element as any).uri;
|
158
|
-
return uri !== undefined ? KameletApi.findKameletByUri(uri) : undefined;
|
159
|
-
} else {
|
160
|
-
return undefined;
|
161
|
-
}
|
162
|
-
};
|
163
|
-
|
164
|
-
static getKameletProperties = (element: any, requiredOnly: boolean = false): Property[] => {
|
165
|
-
const kamelet = CamelUtil.getKamelet(element);
|
166
|
-
const props: Property[] = kamelet ? KameletApi.getKameletProperties(kamelet?.metadata.name) : [];
|
167
|
-
if (requiredOnly) {
|
168
|
-
const required = kamelet?.spec.definition.required;
|
169
|
-
return props.filter(value => required?.includes(value.id));
|
170
|
-
} else {
|
171
|
-
return props;
|
172
|
-
}
|
173
|
-
};
|
174
|
-
|
175
|
-
static getKameletRequiredParameters = (element: any): string[] => {
|
176
|
-
const kamelet = CamelUtil.getKamelet(element);
|
177
|
-
return kamelet ? kamelet.spec.definition.required : [];
|
178
|
-
};
|
179
|
-
|
180
|
-
static getComponentProperties = (element: any): ComponentProperty[] => {
|
181
|
-
const dslName: string = (element as any).dslName;
|
182
|
-
const uri: string = (element as any).uri;
|
183
|
-
const name = ComponentApi.getComponentNameFromUri(uri);
|
184
|
-
|
185
|
-
if (dslName === 'ToDynamicDefinition') {
|
186
|
-
const component = ComponentApi.findByName(dslName);
|
187
|
-
return component ? ComponentApi.getComponentProperties(component?.component.name, 'producer') : [];
|
188
|
-
} else {
|
189
|
-
if (name) {
|
190
|
-
const component = ComponentApi.findByName(name);
|
191
|
-
return component
|
192
|
-
? ComponentApi.getComponentProperties(
|
193
|
-
component?.component.name,
|
194
|
-
element.dslName === 'FromDefinition' ? 'consumer' : 'producer',
|
195
|
-
)
|
196
|
-
: [];
|
197
|
-
} else {
|
198
|
-
return [];
|
199
|
-
}
|
200
|
-
}
|
201
|
-
};
|
202
|
-
|
203
|
-
static checkRequired = (element: CamelElement): [boolean, string[]] => {
|
204
|
-
const result: [boolean, string[]] = [true, []];
|
205
|
-
const className = element.dslName;
|
206
|
-
let elementMeta = CamelMetadataApi.getCamelModelMetadataByClassName(className);
|
207
|
-
|
208
|
-
if (elementMeta === undefined && className.endsWith('Expression')) {
|
209
|
-
elementMeta = CamelMetadataApi.getCamelLanguageMetadataByClassName(className);
|
210
|
-
}
|
211
|
-
|
212
|
-
if (elementMeta) {
|
213
|
-
for (const property of elementMeta.properties.filter(p => p.required)) {
|
214
|
-
const value = (element as any)[property.name];
|
215
|
-
if (property.type === 'string' && !property.isArray && (value === undefined || !value.trim())) {
|
216
|
-
result[0] = false;
|
217
|
-
result[1].push(`${property.displayName} is required`);
|
218
|
-
} else if (['ExpressionSubElementDefinition', 'ExpressionDefinition'].includes(property.type)) {
|
219
|
-
const expressionMeta = CamelMetadataApi.getCamelModelMetadataByClassName('ExpressionDefinition');
|
220
|
-
const expressionCheck = expressionMeta && value !== undefined && expressionMeta?.properties.some(ep => {
|
221
|
-
const expValue = value[ep.name];
|
222
|
-
if (expValue) {
|
223
|
-
const checkedExpression = CamelUtil.checkRequired(expValue);
|
224
|
-
return checkedExpression[0];
|
225
|
-
}
|
226
|
-
return false;
|
227
|
-
});
|
228
|
-
result[0] = !!expressionCheck;
|
229
|
-
if (!expressionCheck) {
|
230
|
-
result[1].push('Expression is not defined');
|
231
|
-
}
|
232
|
-
}
|
233
|
-
}
|
234
|
-
}
|
235
|
-
|
236
|
-
if (className === 'FromDefinition' || className === 'ToDefinition') {
|
237
|
-
if (!CamelUtil.isKameletComponent(element)) {
|
238
|
-
const requiredProperties = CamelUtil.getComponentProperties(element).filter(p => p.required);
|
239
|
-
for (const property of requiredProperties) {
|
240
|
-
const value = CamelDefinitionApiExt.getParametersValue(element, property.name, property.kind === 'path');
|
241
|
-
if (value === undefined || (property.type === 'string' && value.trim().length === 0)) {
|
242
|
-
result[0] = false;
|
243
|
-
result[1].push(`${property.displayName} is required`);
|
244
|
-
}
|
245
|
-
}
|
246
|
-
const secretProperties = CamelUtil.getComponentProperties(element).filter(p => p.secret);
|
247
|
-
for (const property of secretProperties) {
|
248
|
-
const value = CamelDefinitionApiExt.getParametersValue(element, property.name, property.kind === 'path');
|
249
|
-
if (value !== undefined && property.type === 'string'
|
250
|
-
&& (!value?.trim()?.startsWith("{{") || !value?.trim()?.endsWith('}}'))) {
|
251
|
-
result[0] = false;
|
252
|
-
result[1].push(`${property.displayName} is set in plain text`);
|
253
|
-
}
|
254
|
-
}
|
255
|
-
} else {
|
256
|
-
const kamelet = CamelUtil.getKamelet(element);
|
257
|
-
let allSet = true;
|
258
|
-
const elementAsAny = (element as any);
|
259
|
-
const filledParameters = elementAsAny ? Object.keys(elementAsAny.parameters) : [];
|
260
|
-
const missingParameters =
|
261
|
-
kamelet?.spec.definition.required?.filter(name => !filledParameters.includes(name)) || [];
|
262
|
-
if (missingParameters.length > 0) {
|
263
|
-
allSet = false;
|
264
|
-
result[1].push(...missingParameters.map(name => `${name} is required`));
|
265
|
-
}
|
266
|
-
const sensitiveParameters = filledParameters.filter(p => CamelUtil.checkIfKameletParameterSensitive(p, kamelet));
|
267
|
-
sensitiveParameters.forEach(p => {
|
268
|
-
const value = elementAsAny?.parameters[p];
|
269
|
-
if (value !== undefined && (!value?.trim()?.startsWith("{{") || !value?.trim()?.endsWith('}}'))) {
|
270
|
-
result[0] = false;
|
271
|
-
result[1].push(`${p} is set in plain text`);
|
272
|
-
}
|
273
|
-
});
|
274
|
-
result[0] = allSet;
|
275
|
-
}
|
276
|
-
}
|
277
|
-
if (result[1] && result[1].length > 0) {
|
278
|
-
result[0] = false;
|
279
|
-
}
|
280
|
-
return result;
|
281
|
-
};
|
282
|
-
|
283
|
-
static checkIfKameletParameterSensitive(parameter: string, kamelet?: KameletModel): boolean {
|
284
|
-
if (SensitiveKeys.includes(parameter)) {
|
285
|
-
return true;
|
286
|
-
} else {
|
287
|
-
return (kamelet?.spec.definition.properties?.[parameter] as any)?.type === 'password';
|
288
|
-
}
|
289
|
-
}
|
290
|
-
|
291
|
-
static findPlaceholdersInObject = (item: any, result: Set<string> = new Set<string>()): Set<string> => {
|
292
|
-
if (typeof item === 'object') {
|
293
|
-
for (const value of Object.values(item)) {
|
294
|
-
if (value == undefined) {
|
295
|
-
continue;
|
296
|
-
} else if (Array.isArray(value)) {
|
297
|
-
CamelUtil.findPlaceholdersInArray(value, result);
|
298
|
-
} else if (typeof value === 'object') {
|
299
|
-
CamelUtil.findPlaceholdersInObject(value, result);
|
300
|
-
} else {
|
301
|
-
const placeholder = CamelUtil.findPlaceholder(value.toString());
|
302
|
-
if (placeholder[0] && placeholder[1]) {
|
303
|
-
result.add(placeholder[1]);
|
304
|
-
}
|
305
|
-
}
|
306
|
-
}
|
307
|
-
} else {
|
308
|
-
const placeholder = CamelUtil.findPlaceholder(item.toString());
|
309
|
-
if (placeholder[0] && placeholder[1]) {
|
310
|
-
result.add(placeholder[1]);
|
311
|
-
}
|
312
|
-
}
|
313
|
-
return result;
|
314
|
-
};
|
315
|
-
|
316
|
-
static findPlaceholdersInArray = (
|
317
|
-
items: any[] | undefined,
|
318
|
-
result: Set<string> = new Set<string>(),
|
319
|
-
): Set<string> => {
|
320
|
-
if (items) {
|
321
|
-
for (const item of items) {
|
322
|
-
if (typeof item === 'object') {
|
323
|
-
CamelUtil.findPlaceholdersInObject(item, result);
|
324
|
-
} else {
|
325
|
-
const placeholder = CamelUtil.findPlaceholder(item.toString());
|
326
|
-
if (placeholder[0] && placeholder[1]) {
|
327
|
-
result.add(placeholder[1]);
|
328
|
-
}
|
329
|
-
}
|
330
|
-
}
|
331
|
-
}
|
332
|
-
return result;
|
333
|
-
};
|
334
|
-
|
335
|
-
static findPlaceholder = (value: string): [boolean, string?] => {
|
336
|
-
const val = value?.trim();
|
337
|
-
const result = val?.includes('{{') && val?.includes('}}');
|
338
|
-
const start = val?.search('{{') + 2;
|
339
|
-
const end = val?.search('}}');
|
340
|
-
const placeholder = val?.substring(start, end)?.trim();
|
341
|
-
return [result, placeholder];
|
342
|
-
};
|
343
|
-
|
344
|
-
static createNewKameletCode = (kameletName: string, kameletType: KameletTypes, copyFromKameletName?: string): string => {
|
345
|
-
const integration = Integration.createNew(kameletName, 'kamelet');
|
346
|
-
const meta: MetadataLabels = new MetadataLabels({ 'camel.apache.org/kamelet.type': kameletType });
|
347
|
-
integration.metadata.labels = meta;
|
348
|
-
if (copyFromKameletName !== undefined && copyFromKameletName !== '') {
|
349
|
-
const kamelet = KameletApi.getKamelets().filter(k => k.metadata.name === copyFromKameletName).at(0);
|
350
|
-
if (kamelet) {
|
351
|
-
(integration as any).spec = kamelet.spec;
|
352
|
-
(integration as any).metadata.labels = kamelet.metadata.labels;
|
353
|
-
(integration as any).metadata.annotations = kamelet.metadata.annotations;
|
354
|
-
const i = CamelUtil.cloneIntegration(integration);
|
355
|
-
return CamelDefinitionYaml.integrationToYaml(i);
|
356
|
-
}
|
357
|
-
}
|
358
|
-
return CamelDefinitionYaml.integrationToYaml(integration);
|
359
|
-
};
|
360
|
-
}
|