-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgenerateCrd.js
More file actions
115 lines (108 loc) · 2.74 KB
/
generateCrd.js
File metadata and controls
115 lines (108 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const fs = require('fs');
const yaml = require('js-yaml');
// Load YAML file
function loadYAML(filePath) {
return yaml.load(fs.readFileSync(filePath, 'utf8'));
}
// Generate CRD
function generateCRD(openApiData, propertiesData) {
const plans = propertiesData.apiKeyEnabled
? {
API_KEY: {
name: "API Key plan",
description: "API key plan needs a key to authenticate",
security: {
type: "API_KEY",
},
},
}
: {
KeyLess: {
name: "Free plan",
description: "This plan does not require any authentication",
security: {
type: "KEY_LESS",
},
},
};
const crd = {
apiVersion: "gravitee.io/v1alpha1",
kind: "ApiV4Definition",
metadata: {
/* name: openApiData.info.title.toLowerCase().replace(/ /g, "-"), */
name: "generated-crd",
namespace: "default",
},
spec: {
name: openApiData.info.title,
description: openApiData.info.description,
version: openApiData.info.version,
type: "PROXY",
definitionContext: {
origin: "KUBERNETES",
syncFrom: "MANAGEMENT"
},
contextRef: {
name: propertiesData.environment,
namespace: "default"
},
listeners: [
{
type: "HTTP",
paths: [
{
path: propertiesData.entrypoint,
},
],
entrypoints: [
{
type: "http-proxy",
qos: "AUTO",
},
],
},
],
endpointGroups: [
{
name: "Default HTTP proxy group",
type: "http-proxy",
endpoints: [
{
name: "Default HTTP proxy",
type: "http-proxy",
inheritConfiguration: false,
configuration: {
target: propertiesData.endpoint,
},
secondary: false,
},
],
},
],
flowExecution: {
mode: "DEFAULT",
matchRequired: false,
},
plans: plans,
},
};
return yaml.dump(crd);
}
// Main function
function main() {
const [,, openApiFilePath, propertiesFilePath] = process.argv;
if (!openApiFilePath || !propertiesFilePath) {
console.error("Please provide both OpenAPI and properties file paths.");
return;
}
try {
const openApiData = loadYAML(openApiFilePath);
const propertiesData = loadYAML(propertiesFilePath);
const crd = generateCRD(openApiData, propertiesData);
fs.writeFileSync("gravitee-crd.yaml", crd);
console.log("Generated CRD file: gravitee-crd.yaml");
} catch (error) {
console.error("Error generating CRD:", error);
}
}
main();