@sap/cds-dk 6.1.5 → 6.2.0

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.
Files changed (152) hide show
  1. package/CHANGELOG.md +30 -2
  2. package/bin/cds.js +7 -5
  3. package/bin/deploy/index.js +3 -2
  4. package/bin/deploy/to-sqlite.js +4 -3
  5. package/bin/help.js +4 -0
  6. package/bin/init.js +2 -1
  7. package/bin/login.js +23 -9
  8. package/bin/mock.js +1 -0
  9. package/bin/pull.js +24 -19
  10. package/bin/push.js +20 -9
  11. package/bin/subscribe.js +40 -10
  12. package/bin/watch.js +15 -10
  13. package/lib/bind/kubernetesCredentialsProvider.js +1 -0
  14. package/lib/client/activate.js +42 -51
  15. package/lib/client/auth_manager.js +7 -8
  16. package/lib/client/base_command.js +5 -2
  17. package/lib/client/extend.js +33 -38
  18. package/lib/client/helper/cf_helper.js +11 -11
  19. package/lib/client/helper/dependency_helper.js +2 -2
  20. package/lib/client/helper/errors.js +4 -3
  21. package/lib/client/helper/logging.js +17 -23
  22. package/lib/client/params.js +5 -5
  23. package/lib/client/pull.js +19 -21
  24. package/lib/client/push.js +16 -15
  25. package/lib/client/settings_manager.js +54 -55
  26. package/lib/compile/openapi/csdl2openapi.js +18 -12
  27. package/lib/import/message.js +1 -1
  28. package/lib/import/odata/metadataconverter/MetadataConverter.js +23 -17
  29. package/lib/import/odata/v2parser.js +43 -17
  30. package/lib/import/odata/v4parser.js +77 -22
  31. package/lib/init/constants.js +5 -2
  32. package/lib/init/index.js +16 -4
  33. package/lib/init/template/_merging/registry-mta.js +13 -0
  34. package/lib/init/template/approuter/index.js +9 -0
  35. package/lib/{k8s/connectivity/templates/connectivity.yaml → init/template/auditlog/files/auditlog.yaml} +0 -0
  36. package/lib/init/template/auditlog/index.js +46 -27
  37. package/lib/{k8s/connectivity/templates → init/template/connectivity/files}/connectivity-binding.yaml +0 -0
  38. package/lib/{k8s/connectivity/templates → init/template/connectivity/files}/connectivity-proxy-info.yaml +1 -1
  39. package/lib/init/template/connectivity/files/connectivity.yaml +1 -0
  40. package/lib/init/template/connectivity/files/values.yaml.hbs +26 -0
  41. package/lib/init/template/connectivity/index.js +41 -0
  42. package/lib/init/template/data/index.js +8 -8
  43. package/lib/init/template/destinations/files/destination.yaml +1 -0
  44. package/lib/init/template/destinations/index.js +44 -0
  45. package/lib/init/template/enterprise-messaging/files/cds.package.json +10 -0
  46. package/lib/init/template/enterprise-messaging/files/cds.profile.package.json.hbs +12 -0
  47. package/lib/init/template/enterprise-messaging/files/cdsrc.json +8 -0
  48. package/lib/init/template/enterprise-messaging/files/cdsrc.json.hbs +10 -0
  49. package/lib/init/template/enterprise-messaging/files/event-mesh.yaml +1 -0
  50. package/lib/init/template/enterprise-messaging/files/mta.yaml.hbs +13 -0
  51. package/lib/init/template/enterprise-messaging/files/values.yaml +8 -0
  52. package/lib/init/template/enterprise-messaging/index.js +56 -0
  53. package/lib/init/template/extensibility/files/cdsrc.json +5 -0
  54. package/lib/init/template/extensibility/files/cdsrc.json.hbs +7 -0
  55. package/lib/init/template/extensibility/index.js +18 -13
  56. package/lib/{k8s/hana-deployer/templates → init/template/hana/files}/hana-deployer-job.yaml +0 -0
  57. package/lib/init/template/hana/files/java/{cdsrc.json.hbs → cds.json.hbs} +0 -0
  58. package/lib/init/template/hana/files/java/{profile.cdsrc.json.hbs → cds.profile.json.hbs} +0 -0
  59. package/lib/init/template/hana/files/java/cds.shortcut.json.hbs +5 -0
  60. package/lib/init/template/hana/files/java/cds.shortcut.profile.json.hbs +8 -0
  61. package/lib/init/template/hana/files/java/db/package.json +2 -1
  62. package/lib/init/template/hana/files/mta.yaml.hbs +6 -0
  63. package/lib/init/template/hana/files/nodejs/{cds.package.json.hbs → cds.json.hbs} +0 -0
  64. package/lib/init/template/hana/files/nodejs/{cds.profile.package.json.hbs → cds.profile.json.hbs} +0 -0
  65. package/lib/init/template/hana/files/nodejs/cds.shortcut.json.hbs +7 -0
  66. package/lib/init/template/hana/files/nodejs/cds.shortcut.profile.json.hbs +10 -0
  67. package/lib/init/template/hana/files/values.yaml.hbs +19 -0
  68. package/lib/init/template/hana/index.js +29 -29
  69. package/lib/{k8s → init/template/helm}/Model.d.ts +0 -0
  70. package/lib/{k8s/resources → init/template}/helm/chart/templates/NOTES.txt +0 -0
  71. package/lib/{k8s/resources → init/template}/helm/chart/templates/_deployment_helpers.tpl +0 -0
  72. package/lib/{k8s/resources → init/template}/helm/chart/templates/_helpers.tpl +4 -5
  73. package/lib/{k8s/resources → init/template}/helm/chart/templates/_sapcp_helpers.tpl +0 -0
  74. package/lib/{k8s/resources/helm/chart/schemas → init/template/helm/chart}/values.root.schema.json +0 -0
  75. package/lib/{k8s/resources/helm/chart/schemas → init/template/helm/chart}/values.schema.json +0 -0
  76. package/lib/init/template/helm/files/Chart.yaml.hbs +13 -0
  77. package/lib/init/template/helm/files/values.yaml.hbs +26 -0
  78. package/lib/init/template/helm/index.js +74 -14
  79. package/lib/{k8s/deployment → init/template/helm}/subchart/Chart.yaml +0 -0
  80. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/_helpers.tpl +0 -0
  81. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/api-rule.yaml +0 -0
  82. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/deployment.yaml +0 -0
  83. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/network-policy.yaml +0 -0
  84. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/pod-disruption-budget.yaml +0 -0
  85. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/secret.yaml +0 -0
  86. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/service-binding.yaml +0 -0
  87. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/service.yaml +0 -0
  88. package/lib/{k8s/deployment → init/template/helm}/subchart/values-lint.yaml +0 -0
  89. package/lib/{k8s/deployment → init/template/helm}/subchart/values.md +0 -0
  90. package/lib/{k8s/deployment → init/template/helm}/subchart/values.schema.json +0 -0
  91. package/lib/{k8s/deployment → init/template/helm}/subchart/values.yaml +0 -0
  92. package/lib/{k8s/html5-apps-deployer/templates → init/template/html5-repo/files}/_html5_deployment_helpers.tpl +0 -0
  93. package/lib/{k8s/html5-apps-deployer/templates → init/template/html5-repo/files}/html5-apps-deployer-job.yaml +1 -1
  94. package/lib/{k8s/html5-apps-repo-host/templates → init/template/html5-repo/files}/html5-apps-repo-host.yaml +0 -0
  95. package/lib/init/template/html5-repo/index.js +59 -0
  96. package/lib/init/template/kibana-logging/index.js +8 -0
  97. package/lib/init/template/lint/index.js +1 -4
  98. package/lib/init/template/mta/files/mta.yaml.hbs +3 -2
  99. package/lib/init/template/mta/index.js +6 -1
  100. package/lib/init/template/multitenancy/files/java/.cdsrc.json +3 -0
  101. package/lib/init/template/multitenancy/files/java/package.json +2 -6
  102. package/lib/{k8s/multitenancy/templates → init/template/multitenancy/files}/saas-registry.yaml +3 -3
  103. package/lib/init/template/multitenancy/files/xsuaa.yaml +1 -0
  104. package/lib/init/template/multitenancy/index.js +53 -26
  105. package/lib/init/template/nodejs/files/.gitignore.hbs +1 -0
  106. package/lib/init/template/templateBase.js +1 -1
  107. package/lib/init/template/xsuaa/files/values.yaml.hbs +10 -0
  108. package/lib/init/template/xsuaa/files/xsuaa.yaml +1 -0
  109. package/lib/init/template/xsuaa/index.js +34 -22
  110. package/lib/init/util/fsUtil.js +11 -5
  111. package/lib/init/util/projectReader.js +24 -32
  112. package/lib/init/util/templateUtil.js +17 -5
  113. package/lib/lint/Linter.js +9 -17
  114. package/lib/lint/checks.js +0 -1
  115. package/lib/lint/generators.js +2 -192
  116. package/lib/lint/io.js +1 -3
  117. package/lib/watch/node-watch.js +2 -2
  118. package/npm-shrinkwrap.json +1400 -779
  119. package/package.json +5 -4
  120. package/lib/init/template/helm/update/index.js +0 -28
  121. package/lib/k8s/ChartAdder.js +0 -75
  122. package/lib/k8s/ChartBuilder.js +0 -192
  123. package/lib/k8s/Context.js +0 -71
  124. package/lib/k8s/ImageUtil.js +0 -21
  125. package/lib/k8s/auditlog/index.js +0 -29
  126. package/lib/k8s/auditlog/templates/auditlog.yaml +0 -1
  127. package/lib/k8s/buildModel.js +0 -68
  128. package/lib/k8s/connectivity/index.js +0 -80
  129. package/lib/k8s/deployment/index.js +0 -79
  130. package/lib/k8s/deployment/subchart-override/templates/_web_application_helpers.tpl +0 -81
  131. package/lib/k8s/destinations/index.js +0 -40
  132. package/lib/k8s/destinations/lib.js +0 -16
  133. package/lib/k8s/destinations/templates/destinations.yaml +0 -1
  134. package/lib/k8s/docker/push.js +0 -8
  135. package/lib/k8s/event-mesh/index.js +0 -53
  136. package/lib/k8s/event-mesh/lib.js +0 -9
  137. package/lib/k8s/event-mesh/templates/event-mesh.yaml +0 -1
  138. package/lib/k8s/hana-deployer/index.js +0 -48
  139. package/lib/k8s/helm/Release.js +0 -80
  140. package/lib/k8s/html5-apps-deployer/index.js +0 -53
  141. package/lib/k8s/html5-apps-repo-host/index.js +0 -26
  142. package/lib/k8s/html5-apps-repo-host/lib.js +0 -16
  143. package/lib/k8s/index.js +0 -153
  144. package/lib/k8s/modules.js +0 -36
  145. package/lib/k8s/multitenancy/index.js +0 -24
  146. package/lib/k8s/multitenancy/lib.js +0 -25
  147. package/lib/k8s/readProject.js +0 -14
  148. package/lib/k8s/util.js +0 -186
  149. package/lib/k8s/wrapFeature.js +0 -55
  150. package/lib/k8s/xsuaa/index.js +0 -64
  151. package/lib/k8s/xsuaa/lib.js +0 -17
  152. package/lib/k8s/xsuaa/templates/xsuaa.yaml +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cds-dk",
3
- "version": "6.1.5",
3
+ "version": "6.2.0",
4
4
  "description": "Command line client and development toolkit for the SAP Cloud Application Programming Model",
5
5
  "homepage": "https://cap.cloud.sap/",
6
6
  "keywords": [
@@ -16,9 +16,9 @@
16
16
  },
17
17
  "main": "lib/index.js",
18
18
  "dependencies": {
19
- "@sap/cds": "^6.1.0",
19
+ "@sap/cds": "^6.2.0",
20
20
  "@sap/cds-foss": "^4",
21
- "@sap/eslint-plugin-cds": "^2.5.0",
21
+ "@sap/eslint-plugin-cds": "^2.6.0",
22
22
  "axios": ">=0.21",
23
23
  "connect-livereload": "^0.6.1",
24
24
  "eslint": "^8",
@@ -34,7 +34,8 @@
34
34
  "xml-js": "^1.6.11"
35
35
  },
36
36
  "optionalDependencies": {
37
- "sqlite3": "5.0.11"
37
+ "@sap/cds-mtxs": "^1.2.0",
38
+ "sqlite3": "^5.0.4"
38
39
  },
39
40
  "files": [
40
41
  "bin/",
@@ -1,28 +0,0 @@
1
- /* eslint-disable no-unused-vars */
2
- /* eslint-disable no-unreachable */
3
- const path = require('path');
4
- const TemplateBase = require('../../templateBase');
5
- const ProjectReader = require('../../../util/projectReader');
6
- const { OPTION_HELM } = require('../../../constants');
7
-
8
- module.exports = class HelmUpdateTemplate extends TemplateBase {
9
- constructor(projectPath, generator) {
10
- super(projectPath, generator, __dirname, true);
11
- this.projectReader = new ProjectReader(this);
12
- }
13
-
14
- async getDependencies() {
15
- return [ OPTION_HELM ];
16
- }
17
-
18
- async checkEnabled() {
19
- return await this.fsUtil.pathExists(this.chartPath());
20
- }
21
-
22
- chartPath() {
23
- return path.join(this.projectPath, 'chart');
24
- }
25
-
26
- async run() {
27
- }
28
- };
@@ -1,75 +0,0 @@
1
-
2
-
3
- const { yaml } = require('./modules');
4
- const path = require('path');
5
- const fs = require('fs').promises;
6
- const FsUtil = require('../../lib/init/util/fsUtil')
7
- const TemplateUtil = require('../../lib/init/util/templateUtil')
8
-
9
- class ChartAdder {
10
- /**
11
- *
12
- * @param {{ builder: import('./ChartBuilder') }} param0
13
- */
14
- constructor({ builder, resources, chartValues, chartDependencies, app, mergeSemantics }) {
15
- this.builder = builder;
16
- this.resources = resources;
17
- this.chartValues = chartValues;
18
- this.app = app;
19
- this.mergeSemantics = mergeSemantics;
20
- this.dependencies = chartDependencies;
21
- this.templateUtil = new TemplateUtil(null, new FsUtil());
22
- }
23
-
24
- async execute() {
25
- await this.copyTemplates();
26
- await this.copySchema();
27
- await this.addChartValues();
28
- await this.addChartFile();
29
- }
30
-
31
- async copyTemplates() {
32
- await this.builder.addAllTemplates(this.resources);
33
- }
34
-
35
- async copySchema() {
36
- let valuesSchema = JSON.parse(await fs.readFile(path.join(this.resources, 'schemas', 'values.schema.json'), { encoding: 'utf8' }))
37
- let valuesRootSchema = JSON.parse(await fs.readFile(path.join(this.resources, 'schemas', 'values.root.schema.json'), { encoding: 'utf8' }))
38
-
39
- await this.builder.writeChartFile('values.schema.json', JSON.stringify(valuesSchema, null, 4));
40
- await this.builder.writeChartFile('values.root.schema.json', JSON.stringify(valuesRootSchema, null, 4));
41
- }
42
-
43
- async addChartValues() {
44
- const values = this.chartValues;
45
- const valuesYaml = yaml.stringify(JSON.parse(JSON.stringify(values)));
46
-
47
- await this.builder.mergeChartFile('values.yaml', valuesYaml, this.mergeSemantics)
48
- }
49
-
50
- async addChartFile() {
51
- const chart = {
52
- apiVersion: 'v2',
53
- name: this.app.name,
54
- description: this.app.description,
55
- type: 'application',
56
- version: this.app.version, // should be Chart version
57
- appVersion: this.app.version,
58
- dependencies: this.dependencies
59
- };
60
-
61
- const header = `#
62
- # This file is generated by "cds add helm"
63
- `
64
-
65
- const chartYaml = header + yaml.stringify(JSON.parse(JSON.stringify(chart)));
66
- await this.builder.writeChartFile('Chart.yaml', chartYaml);
67
- }
68
-
69
- async getSavedValues() {
70
- return yaml.parse(await fs.readFile(this.builder.chartPath('values.yaml'), 'utf-8'));
71
- }
72
- }
73
-
74
-
75
- module.exports = ChartAdder;
@@ -1,192 +0,0 @@
1
- const { cds, yaml } = require('./modules');
2
- const { readFileIfExists, throwError, parseMd5File, writeMd5File } = require('./util');
3
- const FsUtil = require('../../lib/init/util/fsUtil')
4
- const TemplateUtil = require('../../lib/init/util/templateUtil')
5
- const fs = require('fs').promises;
6
- const Path = require('path');
7
- const LOG = cds.log('k8s');
8
-
9
- /**
10
- *
11
- */
12
-
13
- const crypto = require('crypto');
14
-
15
- class ChartBuilder {
16
- constructor({ path, rootPath = process.cwd() }) {
17
- this.path = path;
18
- this.rootPath = rootPath;
19
- this.tackedFiles = [];
20
- this.oldTrackingData = undefined;
21
- this.newTrackingData = {};
22
- this.templateUtil = new TemplateUtil(null, new FsUtil());
23
- this.ended = false;
24
- }
25
-
26
- async begin() {
27
- await this.loadOldTrackingData();
28
- await this.makeDirs();
29
- }
30
-
31
- async makeDirs() {
32
- await fs.mkdir(Path.join(this.path, 'templates'), { recursive: true });
33
- }
34
-
35
- async writeChartFile(fileName, data) {
36
- if (this.ended) throwError `Internal Error: Cannot write file ${fileName} after end()`;
37
-
38
- const filePath = Path.join(this.path, fileName);
39
- if (!await this.checkAndWarnIfChartFileIsModified(filePath)) {
40
- await fs.writeFile(filePath, data);
41
- }
42
- this.track(filePath, data);
43
- }
44
-
45
- async mergeChartFile(fileName, data, mergeSemantics) {
46
- const filePath = Path.join(this.path, fileName);
47
- const modified = await this.isChartFileModified(filePath);
48
- if (modified) {
49
- LOG(`Merging updates into modified file "${filePath}"`);
50
- const newYamlContent = yaml.parseDocument(data);
51
-
52
- await this.templateUtil.mergeYAML(filePath, newYamlContent, null, mergeSemantics);
53
- } else {
54
-
55
- const header = `
56
- # yaml-language-server: $schema=./values.root.schema.json
57
-
58
- `
59
- data = header + data;
60
- await this.writeChartFile(fileName, data);
61
- }
62
-
63
- this.track(filePath, data);
64
- }
65
-
66
- async addChartFile(sourcePath, { fileName = Path.basename(sourcePath), merge = false, optional = false, mergeSemantics } = {}) {
67
- if (!Path.isAbsolute(sourcePath)) {
68
- sourcePath = Path.join(this.rootPath, sourcePath);
69
- }
70
-
71
- const data = await readFileIfExists(sourcePath, 'utf-8');
72
- if (typeof data === "undefined") {
73
- if (optional)
74
- return false;
75
- else
76
- throwError `File *${sourcePath}* not found.`;
77
- }
78
-
79
- if (merge) {
80
- await this.mergeChartFile(fileName, data, mergeSemantics);
81
- } else {
82
- await this.writeChartFile(fileName, data);
83
- }
84
-
85
- return true;
86
- }
87
-
88
- async addTemplate(sourcePath, sourceFileName, { targetFileName = sourceFileName, merge = false } = {}) {
89
- await this.addChartFile(Path.join(sourcePath, sourceFileName), { fileName: Path.join('templates', targetFileName), merge });
90
- }
91
-
92
- async addSubchartFiles(sourceBasePath, subchart) {
93
- await this.addAllFiles(sourceBasePath, Path.join('charts', subchart));
94
- await this.addAllFiles(Path.join(sourceBasePath, 'templates'), Path.join('charts', subchart, 'templates'));
95
- }
96
-
97
- async addAllTemplates(sourceBasePath, templatesDir = 'templates') {
98
- await this.addAllFiles(Path.join(sourceBasePath, templatesDir), 'templates');
99
- }
100
-
101
- async addAllFiles(sourcePath, targetPath = '.') {
102
- await fs.mkdir(this.chartPath(targetPath), { recursive: true });
103
- for (const sourceFile of await fs.readdir(sourcePath, { withFileTypes: true })) {
104
- if (sourceFile.isFile()) {
105
- await this.addChartFile(Path.join(sourcePath, sourceFile.name), { fileName: Path.join(targetPath, sourceFile.name) });
106
- }
107
- }
108
- }
109
-
110
-
111
- async loadOldTrackingData() {
112
- this.oldTrackingData = await parseMd5File(Path.join(this.path, '.cds-add-helm-files.md5'));
113
- }
114
-
115
- async track(path, data) {
116
- const key = pathKey(this.path, path);
117
- this.newTrackingData[key] = hash(data);
118
- }
119
-
120
- async checkAndWarnIfChartFileIsModified(path) {
121
- if (await this.isChartFileModified(path)) {
122
- LOG.warn(modifiedMsg(path));
123
- return true;
124
- } else {
125
- return false;
126
- }
127
- }
128
-
129
- async isChartFileModified(path) {
130
- const data = await readFileIfExists(path, 'utf-8');
131
- if(data == undefined) {
132
- return false;
133
- }
134
-
135
- const key = pathKey(this.path, path);
136
- const currentHash = hash(data);
137
- return this.oldTrackingData != undefined && this.oldTrackingData[key] != currentHash;
138
- }
139
-
140
- async end() {
141
- this.ended = true;
142
-
143
- for (const path of this.obsoleteFiles()) {
144
- if (await this.isChartFileModified(path)) {
145
- LOG.warn(`Kept no longer used file "${path}" because it is modified`);
146
- } else {
147
- LOG.warn(`Removing no longer used file "${path}" from chart`);
148
- try {
149
- await fs.unlink(path);
150
- } catch(error) {
151
- if (error.code !== 'ENOENT') throw error;
152
- }
153
- }
154
- }
155
-
156
- await this.writeNewTrackingData();
157
- }
158
-
159
- obsoleteFiles() {
160
- return Object.keys(this.oldTrackingData).filter( path => !this.newTrackingData[path]).map( path => this.a(path) );
161
- }
162
-
163
- async writeNewTrackingData() {
164
- await writeMd5File(Path.join(this.path, '.cds-add-helm-files.md5'), this.newTrackingData)
165
- }
166
-
167
- a(path) {
168
- return Path.join(this.path, path)
169
- }
170
-
171
- chartPath(...path) {
172
- return Path.join(this.path, ...path);
173
- }
174
- }
175
-
176
- function hash(data) {
177
- return crypto.createHash('md5').update(data).digest('base64');
178
- }
179
-
180
- function pathKey(basePath, path) {
181
- return Path.posix.normalize(toPosix(Path.relative(basePath, path)))
182
- }
183
-
184
- function toPosix(path) {
185
- return path.replace(/\\/g, '/');
186
- }
187
-
188
- function modifiedMsg(path) {
189
- return `Chart file "${path}" has been modified and will not be updated.`;
190
- }
191
-
192
- module.exports = ChartBuilder;
@@ -1,71 +0,0 @@
1
- const { throwError } = require('./util');
2
-
3
- /**
4
- * The context holds elements that are used to build up the CAP project. It allows
5
- * decoupling between this objects. It should be used in a way that the Context is initialized
6
- * with the elements (also referred to as "plugins") and each of them implements the required
7
- * interface for the type of element.
8
- */
9
- class Context {
10
- constructor(objs) {
11
- this.modified = true;
12
- this.objs = objs || {};
13
- }
14
-
15
- async get(name) {
16
- if (this.objs[name]) {
17
- if (typeof this.objs[name] === 'function') {
18
- this.objs[name] = await this.objs[name](this) || {};
19
- }
20
-
21
- return this.objs[name];
22
- } else {
23
- throwError `Unknown module *${name}*`;
24
- }
25
- }
26
-
27
- async loadAll() {
28
- while (this.modified) {
29
- this.modified = false;
30
- for (const name in this.objs) {
31
- await this.get(name);
32
- }
33
- }
34
- }
35
-
36
- add(name, obj) {
37
- this.modified = true;
38
- this.objs[name] = obj;
39
- }
40
-
41
- has(name) {
42
- return !!this.objs[name];
43
- }
44
-
45
- async filter(name) {
46
- await this.loadAll();
47
- return Object.values(this.objs).filter( obj => obj[name] );
48
- }
49
-
50
- async forEach(name, call) {
51
- const filtered = await this.filter(name);
52
- for (const plugin of filtered) {
53
- await call(plugin);
54
- }
55
- }
56
-
57
- async collect(name) {
58
- let obj = {};
59
- await this.forEach(name, async (plugin) => obj = {...obj, ...await plugin[name]()});
60
- return Object.keys(obj).length > 0 ? obj : undefined;
61
- }
62
-
63
- async collectBool(name) {
64
- let bool = false;
65
- await this.forEach(name, async (plugin) => bool = bool || await plugin[name]());
66
- return bool;
67
- }
68
-
69
- }
70
-
71
- module.exports = Context;
@@ -1,21 +0,0 @@
1
- const { throwError } = require('./util');
2
-
3
- class ImageUtil {
4
- constructor(config) {
5
- this.config = config.images;
6
- }
7
- imageName(imageSuffix) {
8
- const imagePrefix = this.config.imagePrefix || throwError `Expect *images.prefix* property.`;
9
- return `${imagePrefix}-${imageSuffix}`;
10
- }
11
-
12
- get imageRegistry() {
13
- return this.config.imageRegistry || throwError `Expect *images.registry* property.`;
14
- }
15
-
16
- fullImageName(suffix) {
17
- return `${this.imageRegistry}/${this.imageName(suffix)}:latest`;
18
- }
19
- }
20
-
21
- module.exports = ImageUtil;
@@ -1,29 +0,0 @@
1
- const wrapFeature = require('../wrapFeature');
2
-
3
- module.exports = wrapFeature('auditlog', {
4
- getServiceBindings() {
5
- return {
6
- auditlog: {
7
- serviceInstanceName: 'auditlog'
8
- }
9
- };
10
- },
11
-
12
- getChartCapabilities() {
13
- return {
14
- auditlog: {
15
- serviceOfferingName: 'auditlog-api',
16
- servicePlanName: 'default'
17
- }
18
- }
19
- },
20
-
21
- async addToChart(builder, { auditlog }) {
22
- await builder.addAllTemplates(__dirname);
23
-
24
- const { config } = auditlog;
25
- if (config) {
26
- await builder.addChartFile(config);
27
- }
28
- }
29
- });
@@ -1 +0,0 @@
1
- {{- include "cap.service-instance" . }}
@@ -1,68 +0,0 @@
1
- const { throwError } = require('./util');
2
- const readProject = require('./readProject');
3
- const Path = require('path');
4
-
5
- /**
6
- * Build data model of the CAP project for Kubernetes build, push, charts and chart deployment
7
- *
8
- * @returns
9
- */
10
- async function buildModel(context) {
11
- const k8s = await context.get('config');
12
- const projectPath = await context.get('projectPath');
13
-
14
- const project = await readProject(projectPath);
15
- const cap = project.cap;
16
-
17
- const services = buildServices(cap);
18
- const isJava = typeof k8s.isJava !== 'undefined' ? k8s.isJava : cap.isJava;
19
- const language = isJava ? 'Java' : 'Node';
20
-
21
- const model = {
22
- app: {
23
- name: cap.appName,
24
- description: cap.appDescription,
25
- version: cap.appVersion
26
- },
27
- isMultiTenant: cap.isMultitenant,
28
- isJava,
29
- language,
30
- services
31
- }
32
-
33
- model.getChartValues = function() {
34
- return {
35
- global: {
36
- domain: null,
37
- imagePullSecret: {}
38
- }
39
- }
40
- };
41
-
42
- model.path = function(path = '.') {
43
- return Path.join(projectPath, path);
44
- }
45
-
46
- return model;
47
- }
48
-
49
- function buildServices(cap) {
50
- const prefix = `${cap.appName}-`;
51
- let services = {};
52
- for (const req of cap.requires) {
53
- const resource = req.resource;
54
- if (!resource.name.startsWith(prefix)) throwError `Unexpected resource name _${resource.name}_. Should start with _${prefix}_`;
55
- const name = resource.name.substr(prefix.length);
56
-
57
- if (name === 'db') continue; // TODO: hard coded with srv.bindings.db.secret;
58
-
59
- // TODO: needs improvement
60
- services[name] = {
61
- label: resource.service
62
- };
63
- }
64
-
65
- return services;
66
- }
67
-
68
- module.exports = buildModel;
@@ -1,80 +0,0 @@
1
- const wrapFeature = require('../wrapFeature');
2
-
3
- module.exports = wrapFeature('connectivity', {
4
- async extendChartDeployment(context, name, deployment, mergeSemantics) {
5
- const model = await context.get('model');
6
- const prefix = model.app.name;
7
-
8
- deployment.env = {
9
- ...(deployment.env || {}),
10
- CDS_ENVIRONMENT_K8S_SERVICEBINDINGS_CONNECTIVITY_SECRETSPATH: '/bindings/connectivity',
11
- CDS_ENVIRONMENT_K8S_SERVICEBINDINGS_CONNECTIVITY_SERVICE: 'connectivity'
12
- };
13
-
14
- deployment.additionalVolumes = deployment.additionalVolumes || [];
15
- deployment.additionalVolumes.push(
16
- {
17
- name: "connectivity-secret",
18
- volumeMount: {
19
- mountPath: "/bindings/connectivity",
20
- readOnly: true
21
- },
22
- projected: {
23
- sources: [
24
- {
25
- secret: {
26
- name: `${prefix}-connectivity-binding`,
27
- optional: false
28
- }
29
- },
30
- {
31
- secret: {
32
- name: `${prefix}-connectivity-binding`,
33
- optional: false,
34
- items: [
35
- {
36
- key: "token_service_url",
37
- path: "url"
38
- }
39
- ]
40
- }
41
- },
42
- {
43
- configMap: {
44
- name: `${prefix}-connectivity-proxy-info`,
45
- optional: false
46
- }
47
- }
48
- ]
49
- }
50
- }
51
- );
52
-
53
- mergeSemantics.additions.push({
54
- ref: `{name}-additional-volumes`,
55
- in: `${name}.additionalVolumes`,
56
- where: [{
57
- property: 'name',
58
- isEqualTo: 'connectivity-secret'
59
- }]
60
- });
61
- },
62
-
63
- async getChartCapabilities(context) {
64
- const model = await context.get('model');
65
- const prefix = model.app.name;
66
-
67
- return {
68
- connectivity: {
69
- serviceOfferingName: 'connectivity',
70
- servicePlanName: 'connectivity_proxy',
71
- secretName: `${prefix}-connectivity-binding`,
72
- configMapName: `${prefix}-connectivity-proxy-info`
73
- }
74
- }
75
- },
76
-
77
- async addToChart(builder) {
78
- await builder.addAllTemplates(__dirname);
79
- }
80
- });
@@ -1,79 +0,0 @@
1
- const fs = require('fs').promises;
2
- const Path = require('path');
3
- const { yaml } = require('../modules');
4
-
5
- class Deployment {
6
- constructor({context, name, language}) {
7
- this.context = context;
8
- this.name = name;
9
- this.language = language;
10
- }
11
-
12
- async getChartDeployments(context) {
13
- const model = await context.get('model');
14
-
15
- let bindings = {};
16
- await context.forEach('getServiceBindings',
17
- async plugin => bindings = {...bindings, ...await plugin.getServiceBindings(context)}
18
- );
19
-
20
- const language = this.language || model.language;
21
- const memory = language === 'Java' ? '1G' : '500M';
22
- const cpu = language === 'Java' ? '1000m' : '500m';
23
- const env = language === 'Java' ? {SPRING_PROFILES_ACTIVE: "cloud"} : undefined;
24
-
25
- return {
26
- [this.name]: {
27
- bindings,
28
- image: {
29
- repository: '<your-container-registry>/'+model.app.name+'-'+this.name,
30
- tag: 'latest'
31
- },
32
- env,
33
- resources: {
34
- limits: {
35
- 'ephemeral-storage': '1G',
36
- memory
37
- },
38
- requests: {
39
- cpu,
40
- 'ephemeral-storage': '1G',
41
- memory
42
- }
43
- },
44
- health_check: {
45
- liveness: {
46
- path: '/'
47
- },
48
- readiness: {
49
- path: '/'
50
- }
51
- }
52
- }
53
- }
54
- }
55
-
56
- async getChartDependencies() {
57
- return [{
58
- name: 'web-application',
59
- alias: this.name,
60
- version: await webApplicationChartVersion()
61
- }]
62
- }
63
-
64
- async addToChart(builder) {
65
- await builder.addSubchartFiles(webApplicationChartPath, 'web-application');
66
- }
67
- }
68
-
69
- const webApplicationChartPath = process.env.WEB_APPLICATION_CHART || Path.join(__dirname, 'subchart');
70
-
71
- async function webApplicationChartVersion() {
72
- const chartFilePath = Path.join(webApplicationChartPath, 'Chart.yaml');
73
- const chartFile = await fs.readFile(chartFilePath, 'utf-8');
74
- return yaml.parse(chartFile).version;
75
- }
76
-
77
- module.exports = function (context) {
78
- return new Deployment({context, name: 'srv'});
79
- }