@sap/cds-dk 6.0.2 → 6.1.1

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 (105) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/bin/add.js +29 -16
  3. package/bin/cds.js +7 -3
  4. package/bin/compile/index.js +6 -1
  5. package/bin/deploy/index.js +7 -1
  6. package/bin/fix-redirects.js +4 -2
  7. package/bin/init.js +5 -0
  8. package/bin/login.js +8 -2
  9. package/bin/pull.js +58 -0
  10. package/bin/push.js +52 -0
  11. package/bin/subscribe.js +45 -0
  12. package/lib/bind/bindingResolver.js +1 -2
  13. package/lib/bind/bindingUtil.js +1 -2
  14. package/lib/bind/cfKeyProvider.js +3 -3
  15. package/lib/client/activate.js +1 -1
  16. package/lib/client/auth_manager.js +7 -3
  17. package/lib/client/extend.js +1 -1
  18. package/lib/client/helper/cf_helper.js +1 -0
  19. package/lib/client/helper/url_helper.js +7 -3
  20. package/lib/client/index.js +1 -1
  21. package/lib/client/params.js +4 -2
  22. package/lib/client/pull.js +51 -0
  23. package/lib/client/push.js +49 -0
  24. package/lib/client/settings_manager.js +74 -21
  25. package/lib/compile/openapi/csdl2openapi.js +135 -163
  26. package/lib/compile/openapi/index.js +0 -1
  27. package/lib/import/common.js +9 -1
  28. package/lib/import/odata/metadataconverter/MetadataConverter.js +17 -4
  29. package/lib/import/odata/v2parser.js +0 -1
  30. package/lib/import/odata/v4parser.js +103 -29
  31. package/lib/import/openapi/importOpenAPI.js +3 -3
  32. package/lib/init/constants.js +9 -3
  33. package/lib/init/template/_merging/registry-mta.js +290 -0
  34. package/lib/init/template/approuter/index.js +22 -32
  35. package/lib/init/template/auditlog/index.js +7 -9
  36. package/lib/init/template/extensibility/files/cds.package.json +7 -0
  37. package/lib/init/template/extensibility/files/cds.package.json.hbs +9 -0
  38. package/lib/init/template/extensibility/files/xs-security.json.hbs +26 -0
  39. package/lib/init/template/extensibility/index.js +48 -0
  40. package/lib/init/template/hana/files/java/cdsrc.json.hbs +1 -1
  41. package/lib/init/template/hana/files/java/profile.cdsrc.json.hbs +2 -2
  42. package/lib/init/template/hana/files/mta.yaml.hbs +10 -0
  43. package/lib/init/template/hana/files/nodejs/cds.package.json.hbs +1 -1
  44. package/lib/init/template/hana/files/nodejs/cds.profile.package.json.hbs +2 -2
  45. package/lib/init/template/hana/index.js +76 -63
  46. package/lib/init/template/kibana-logging/index.js +31 -37
  47. package/lib/init/template/lint/files/.eslint/rules/no-entity-moo.js +14 -14
  48. package/lib/init/template/lint/index.js +1 -1
  49. package/lib/init/template/mta/files/mta.yaml.hbs +1 -1
  50. package/lib/init/template/mta/index.js +13 -7
  51. package/lib/init/template/mtx/index.js +2 -142
  52. package/lib/init/template/multitenancy/files/cds.package.json +7 -0
  53. package/lib/init/template/multitenancy/files/cds.package.json.hbs +9 -0
  54. package/lib/init/template/{mtx → multitenancy}/files/dependencies.package.json +1 -1
  55. package/lib/init/template/multitenancy/files/java/.cdsrc.json +19 -0
  56. package/lib/init/template/multitenancy/files/java/package.json +31 -0
  57. package/lib/init/template/{mtx → multitenancy}/files/mta.yaml.hbs +13 -6
  58. package/lib/init/template/multitenancy/files/xs-security.json.hbs +18 -0
  59. package/lib/init/template/multitenancy/index.js +109 -0
  60. package/lib/init/template/nodejs/files/package.json.hbs +3 -0
  61. package/lib/init/template/templateBase.js +4 -3
  62. package/lib/init/template/toggles/files/cds.package.json +7 -0
  63. package/lib/init/template/toggles/files/cds.package.json.hbs +9 -0
  64. package/lib/init/template/toggles/index.js +24 -0
  65. package/lib/init/template/xsuaa/files/mta.yaml.hbs +10 -0
  66. package/lib/init/template/xsuaa/index.js +44 -33
  67. package/lib/init/util/projectReader.js +13 -8
  68. package/lib/init/util/templateUtil.js +112 -110
  69. package/lib/k8s/ChartAdder.js +11 -3
  70. package/lib/k8s/ChartBuilder.js +6 -0
  71. package/lib/k8s/buildModel.js +1 -3
  72. package/lib/k8s/connectivity/index.js +11 -5
  73. package/lib/k8s/connectivity/templates/connectivity-proxy-info.yaml +7 -3
  74. package/lib/k8s/deployment/index.js +2 -4
  75. package/lib/k8s/deployment/subchart/Chart.yaml +1 -1
  76. package/lib/k8s/deployment/subchart/templates/_helpers.tpl +22 -11
  77. package/lib/k8s/deployment/subchart/templates/deployment.yaml +12 -5
  78. package/lib/k8s/deployment/subchart/templates/network-policy.yaml +3 -1
  79. package/lib/k8s/deployment/subchart/templates/pod-disruption-budget.yaml +1 -1
  80. package/lib/k8s/deployment/subchart/values.md +812 -0
  81. package/lib/k8s/deployment/subchart/values.schema.json +125 -30
  82. package/lib/k8s/deployment/subchart/values.yaml +7 -3
  83. package/lib/k8s/hana-deployer/index.js +10 -0
  84. package/lib/k8s/hana-deployer/templates/hana-deployer-job.yaml +8 -0
  85. package/lib/k8s/html5-apps-deployer/index.js +10 -0
  86. package/lib/k8s/html5-apps-deployer/templates/html5-apps-deployer-job.yaml +8 -0
  87. package/lib/k8s/index.js +2 -2
  88. package/lib/k8s/resources/helm/chart/templates/_deployment_helpers.tpl +1 -159
  89. package/lib/k8s/resources/helm/chart/templates/_helpers.tpl +0 -33
  90. package/lib/k8s/resources/helm/chart/templates/_sapcp_helpers.tpl +1 -1
  91. package/lib/k8s/resources/helm/chart/values.schema.json +449 -0
  92. package/lib/k8s/xsuaa/lib.js +10 -7
  93. package/lib/lint/Linter.js +155 -158
  94. package/lib/lint/generators.js +1 -1
  95. package/lib/lint/io.js +13 -5
  96. package/npm-shrinkwrap.json +1053 -136
  97. package/package.json +5 -4
  98. package/lib/init/template/_merging/existences.js +0 -297
  99. package/lib/init/template/mtx/files/cds.package.json +0 -12
  100. package/lib/init/template/mtx/files/cds.package.json.hbs +0 -14
  101. package/lib/init/template/mtx/files/java/.cdsrc.json +0 -17
  102. package/lib/init/template/mtx/files/java/package.json +0 -43
  103. package/lib/init/template/mtx/files/java/server.js +0 -30
  104. package/lib/init/template/mtx/files/xs-security.json.hbs +0 -48
  105. package/lib/lint/.eslintrc.js +0 -3
@@ -1,14 +1,6 @@
1
- const cds = require('../../../cds'), { fs, path } = cds.utils
2
1
  const TemplateBase = require('../templateBase')
3
2
  const ProjectReader = require('../../util/projectReader')
4
- const { OPTION_HANA, OPTION_XSUAA } = require('../../constants')
5
-
6
- const {
7
- srvNode, srvJava, // Server
8
- mtxSidecar, // Additional Modules
9
- saasRegistry, xsuaa, // BTP Services
10
- providedMtxAPI, srvAPI, providedMtxSidecarAPI, requiredMtxSidecarAPI // APIs
11
- } = require('../_merging/existences');
3
+ const { OPTION_MULTITENANCY, OPTION_TOGGLES, OPTION_EXTENSIBILITY } = require('../../constants')
12
4
 
13
5
  module.exports = class MtxTemplate extends TemplateBase {
14
6
  constructor(projectPath, generator) {
@@ -17,138 +9,6 @@ module.exports = class MtxTemplate extends TemplateBase {
17
9
  }
18
10
 
19
11
  async getDependencies() {
20
- return [OPTION_HANA, OPTION_XSUAA]
21
- }
22
-
23
- async runDependentMerging() {
24
- const projectDescriptor = await this.projectReader.read()
25
-
26
- const mtaYAMLPath = path.join(this.projectPath, 'mta.yaml')
27
-
28
- if (fs.existsSync(mtaYAMLPath)) {
29
- const mergingRules = projectDescriptor.cap.isNodejs ?
30
- {
31
- existences: [srvNode, saasRegistry, providedMtxAPI, xsuaa],
32
- overwrites: [{
33
- in: xsuaa,
34
- keyPath: ["parameters", "config", "tenant-mode"],
35
- replacement: "shared"
36
- }],
37
- relationships: [{
38
- in: srvNode,
39
- inKeyPath: ["requires"],
40
- into: "name",
41
- existences: [saasRegistry],
42
- existenceKeyPath: ["name"],
43
- }],
44
- }
45
- :
46
- {
47
- existences: [srvJava, srvAPI, mtxSidecar, xsuaa, saasRegistry, providedMtxAPI, providedMtxSidecarAPI, requiredMtxSidecarAPI],
48
- overwrites: [{
49
- in: xsuaa,
50
- keyPath: ["parameters", "config", "tenant-mode"],
51
- replacement: "shared"
52
- }],
53
- relationships: [{
54
- in: srvJava,
55
- inKeyPath: ["requires"],
56
- into: "name",
57
- existences: [saasRegistry],
58
- existenceKeyPath: ["name"],
59
- }],
60
- }
61
-
62
- await this.templateUtil.mergeYAML(
63
- mtaYAMLPath,
64
- path.join(__dirname, `files`, `mta.yaml.hbs`),
65
- projectDescriptor,
66
- mergingRules
67
- )
68
- }
69
-
70
- if (projectDescriptor.cap.hasApprouter) {
71
- const ApprouterTemplate = require(`../approuter`)
72
- const template = new ApprouterTemplate(this.projectPath, this.generator)
73
- await template.runDependentMerging()
74
- }
75
- }
76
-
77
- async runXSSecurityMerging() {
78
- const projectDescriptor = await this.projectReader.read()
79
- await this.templateUtil.mergeJSON(
80
- path.join(this.projectPath, 'xs-security.json'),
81
- path.join(__dirname, 'files', 'xs-security.json.hbs'),
82
- projectDescriptor,
83
- {
84
- existences: [{
85
- ref: "scope-subscription",
86
- keyPath: ["scopes"],
87
- constraints: [{
88
- comparisonKeyPath: ["name"],
89
- value: "$XSAPPNAME.mtcallback"
90
- }],
91
- }, {
92
- ref: "scope-update",
93
- keyPath: ["scopes"],
94
- constraints: [{
95
- comparisonKeyPath: ["name"],
96
- value: "$XSAPPNAME.mtdeployment"
97
- }],
98
- }, {
99
- ref: "scope-diagnose",
100
- keyPath: ["scopes"],
101
- constraints: [{
102
- comparisonKeyPath: ["name"],
103
- value: "$XSAPPNAME.MtxDiagnose"
104
- }],
105
- }, {
106
- ref: "scope-extend",
107
- keyPath: ["scopes"],
108
- constraints: [{
109
- comparisonKeyPath: ["name"],
110
- value: "$XSAPPNAME.ExtendCDS"
111
- }],
112
- }, {
113
- ref: "scope-extend-delete",
114
- keyPath: ["scopes"],
115
- constraints: [{
116
- comparisonKeyPath: ["name"],
117
- value: "$XSAPPNAME.ExtendCDSdelete"
118
- }],
119
- }, {
120
- ref: "template-extension-developer",
121
- keyPath: ["role-templates"],
122
- constraints: [{
123
- comparisonKeyPath: ["name"],
124
- value: "ExtensionDeveloper"
125
- }],
126
- }, {
127
- ref: "template-extension-developer-undeploy",
128
- keyPath: ["role-templates"],
129
- constraints: [{
130
- comparisonKeyPath: ["name"],
131
- value: "ExtensionDeveloperUndeploy"
132
- }],
133
- }],
134
- }
135
- )
136
- }
137
-
138
- async run() {
139
- const projectDescriptor = await this.projectReader.read(this.options)
140
- if (projectDescriptor.cap.isNodejs) {
141
- const packageJSONPath = path.join(this.projectPath, 'package.json')
142
- const cdsTemplateFile = projectDescriptor.cap.for ? 'cds.package.json.hbs' : 'cds.package.json'
143
- await this.templateUtil.mergeJSON(packageJSONPath, path.join(__dirname, 'files', cdsTemplateFile), projectDescriptor)
144
- await this.templateUtil.mergeJSON(packageJSONPath, path.join(__dirname, 'files', 'dependencies.package.json'))
145
- await this.templateUtil.sortDependencies(packageJSONPath)
146
- } else {
147
- const cdsrcJSONPath = path.join(this.projectPath, '.cdsrc.json')
148
- await this.templateUtil.mergeJSON(cdsrcJSONPath, path.join(__dirname, 'files', 'java', '.cdsrc.json'))
149
- await fs.copy(path.join(__dirname, 'files', 'java'), path.join(this.projectPath, 'mtx-sidecar'))
150
- }
151
- await this.runXSSecurityMerging()
152
- await this.runDependentMerging()
12
+ return [OPTION_MULTITENANCY, OPTION_TOGGLES, OPTION_EXTENSIBILITY]
153
13
  }
154
14
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "cds": {
3
+ "requires": {
4
+ "multitenancy": true
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "cds": {
3
+ "requires": {
4
+ "[{{cap.for}}]": {
5
+ "multitenancy": true
6
+ }
7
+ }
8
+ }
9
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "dependencies": {
3
- "@sap/cds-mtx": "^2"
3
+ "@sap/cds-mtxs": "^1"
4
4
  }
5
5
  }
@@ -0,0 +1,19 @@
1
+ {
2
+ "build": {
3
+ "target": ".",
4
+ "tasks": [
5
+ {
6
+ "for": "java"
7
+ },
8
+ {
9
+ "for": "mtx-sidecar"
10
+ },
11
+ {
12
+ "for": "hana",
13
+ "options": {
14
+ "deploy-format": "hdbtable"
15
+ }
16
+ }
17
+ ]
18
+ }
19
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "cap-mtx-sidecar",
3
+ "dependencies": {
4
+ "@sap/cds": "^6.0.2",
5
+ "@sap/cds-mtxs": "^1.0.1",
6
+ "@sap/hdi-deploy": "^4.4.1",
7
+ "@sap/xssec": "^3.2.13",
8
+ "express": "^4.18.1",
9
+ "hdb": "^0.19.3",
10
+ "passport": "^0.6.0"
11
+ },
12
+ "scripts": {
13
+ "start": "cds run",
14
+ "build": "npm ci && npx -p @sap/cds-dk@^6 cds build ../.. --for mtx-sidecar --production && cd gen && npm ci"
15
+ },
16
+ "engines": {
17
+ "node": "^16.15.0"
18
+ },
19
+ "cds": {
20
+ "requires": {
21
+ "db": {
22
+ "kind": "sqlite",
23
+ "[production]": {
24
+ "kind": "hana-mt"
25
+ }
26
+ },
27
+ "cds.xt.ModelProviderService": "in-sidecar",
28
+ "cds.xt.SaasProvisioningService": true
29
+ }
30
+ }
31
+ }
@@ -8,6 +8,7 @@ modules:
8
8
  {{#cap.isJava}}
9
9
  - name: mtx-sidecar
10
10
  properties:
11
+ CDS_MULTITENANCY_MTXS_ENABLED: true
11
12
  CDS_MULTITENANCY_SIDECAR_URL: ~{url}
12
13
  {{/cap.isJava}}
13
14
  provides:
@@ -21,17 +22,23 @@ modules:
21
22
  {{#cap.isJava}}
22
23
  - name: {{cap.appName}}-mtx-sidecar
23
24
  type: nodejs
24
- path: mtx-sidecar
25
+ path: mtx/sidecar
26
+ build-parameters:
27
+ builder: custom
28
+ build-result: gen
29
+ commands:
30
+ - npm run build
25
31
  parameters:
26
32
  memory: 256M
27
33
  disk-quota: 512M
28
- requires:
29
- - name: {{cap.appName}}-db
30
- - name: {{cap.appName}}-auth
31
34
  provides:
32
35
  - name: mtx-sidecar
33
36
  properties:
34
37
  url: ${default-url}
38
+ {{#cap.hasXsuaa}}
39
+ requires:
40
+ - name: {{cap.appName}}-auth
41
+ {{/cap.hasXsuaa}}
35
42
  {{/cap.isJava}}
36
43
 
37
44
  resources:
@@ -55,8 +62,8 @@ resources:
55
62
  category: 'Category'
56
63
  appUrls:
57
64
  {{#cap.isNodejs}}
58
- getDependencies: ~{mtx-api/mtx-url}/mtx/v1/provisioning/dependencies
59
- onSubscription: ~{mtx-api/mtx-url}/mtx/v1/provisioning/tenant/{tenantId}
65
+ getDependencies: ~{mtx-api/mtx-url}/-/cds/saas-provisioning/dependencies
66
+ onSubscription: ~{mtx-api/mtx-url}/-/cds/saas-provisioning/tenant/{tenantId}
60
67
  {{/cap.isNodejs}}
61
68
  {{#cap.isJava}}
62
69
  getDependencies: ~{srv-api/srv-url}/mt/v1.0/subscriptions/dependencies
@@ -0,0 +1,18 @@
1
+ {
2
+ "scopes": [
3
+ {
4
+ "name": "$XSAPPNAME.mtcallback",
5
+ "description": "Subscription via SaaS Registry",
6
+ "grant-as-authority-to-apps": [
7
+ "$XSAPPNAME(application,sap-provisioning,tenant-onboarding)"
8
+ ]
9
+ },
10
+ {
11
+ "name": "$XSAPPNAME.cds.Subscriber",
12
+ "description": "Subscribe to applications"
13
+ }
14
+ ],
15
+ "authorities": [
16
+ "$XSAPPNAME.cds.Subscriber"
17
+ ]
18
+ }
@@ -0,0 +1,109 @@
1
+ const cds = require('../../../cds'), { fs, path } = cds.utils
2
+ const TemplateBase = require('../templateBase')
3
+ const ProjectReader = require('../../util/projectReader')
4
+
5
+ const {
6
+ srvNode, srvJava, // Server
7
+ mtxSidecar, // Additional Modules
8
+ saasRegistry, serviceManager, xsuaa, // BTP Services
9
+ providedMtxAPI, srvAPI, providedMtxSidecarAPI, requiredMtxSidecarAPI // APIs
10
+ } = require('../_merging/registry-mta');
11
+
12
+ module.exports = class MultitenancyTemplate extends TemplateBase {
13
+ constructor(projectPath, generator) {
14
+ super(projectPath, generator, __dirname)
15
+ this.projectReader = new ProjectReader(this)
16
+ }
17
+
18
+ async runDependentMerging() {
19
+ const projectDescriptor = await this.projectReader.read()
20
+ const { isNodejs, isJava, hasMtaDeployment, hasApprouter, hasXsuaa, hasHana } = projectDescriptor.cap
21
+
22
+ if (hasMtaDeployment) {
23
+ const modules = isNodejs ? [srvNode] : [srvJava, mtxSidecar]
24
+ const srv = isNodejs ? srvNode : srvJava
25
+ const services = [saasRegistry]
26
+ if (hasXsuaa) services.push(xsuaa)
27
+ const apis = isNodejs ? [providedMtxAPI] : [srvAPI, providedMtxAPI, providedMtxSidecarAPI, requiredMtxSidecarAPI]
28
+ const relationships = [{
29
+ insert: [saasRegistry, 'name'],
30
+ into: [srv, 'requires', 'name']
31
+ }]
32
+
33
+ if (isJava) {
34
+ if (hasXsuaa) {
35
+ relationships.push({
36
+ insert: [xsuaa, 'name'],
37
+ into: [mtxSidecar, 'requires', 'name']
38
+ })
39
+ }
40
+ if (hasHana) {
41
+ relationships.push({
42
+ insert: [serviceManager, 'name'],
43
+ into: [mtxSidecar, 'requires', 'name'],
44
+ })
45
+ }
46
+ }
47
+
48
+ const mergingRules = {
49
+ additions: [...modules, ...services, ...apis],
50
+ overwrites: hasXsuaa ? [{ // TODO: the hasXsuaa should not be necessary
51
+ item: [xsuaa, 'parameters.config.tenant-mode'],
52
+ withValue: 'shared'
53
+ }] : undefined,
54
+ relationships,
55
+ }
56
+ const mtaPath = path.join(this.projectPath, 'mta.yaml')
57
+ const templateMtaPath = path.join(__dirname, `files`, `mta.yaml.hbs`)
58
+ await this.templateUtil.mergeYAML(mtaPath, templateMtaPath, projectDescriptor, mergingRules)
59
+ }
60
+
61
+ if (hasApprouter) {
62
+ const ApprouterTemplate = require(`../approuter`)
63
+ const template = new ApprouterTemplate(this.projectPath, this.generator)
64
+ await template.runDependentMerging()
65
+ }
66
+
67
+ if (hasHana) {
68
+ const HanaTemplate = require(`../hana`)
69
+ const template = new HanaTemplate(this.projectPath, this.generator)
70
+ await template.runDependentMerging()
71
+ }
72
+
73
+ if (hasXsuaa) {
74
+ await this.templateUtil.mergeJSON(
75
+ path.join(this.projectPath, 'xs-security.json'),
76
+ path.join(__dirname, 'files', 'xs-security.json.hbs'),
77
+ projectDescriptor,
78
+ {
79
+ additions: [{
80
+ ref: 'scope-mtcallback',
81
+ in: 'scopes',
82
+ where: [{ property: 'name', isEqualTo: '$XSAPPNAME.mtcallback' }],
83
+ }, {
84
+ ref: 'scope-subscriber',
85
+ in: 'scopes',
86
+ where: [{ property: 'name', isEqualTo: '$XSAPPNAME.cds.Subscriber' }],
87
+ }]
88
+ }
89
+ )
90
+ }
91
+ }
92
+
93
+ async run() {
94
+ const projectDescriptor = await this.projectReader.read(this.options)
95
+ const { for: forProfile, isNodejs, isJava } = projectDescriptor.cap
96
+ if (isNodejs) {
97
+ const packageJSONPath = path.join(this.projectPath, 'package.json')
98
+ const cdsTemplateFile = forProfile ? 'cds.package.json.hbs' : 'cds.package.json'
99
+ await this.templateUtil.mergeJSON(packageJSONPath, path.join(__dirname, 'files', cdsTemplateFile), projectDescriptor)
100
+ await this.templateUtil.mergeJSON(packageJSONPath, path.join(__dirname, 'files', 'dependencies.package.json'))
101
+ await this.templateUtil.sortDependencies(packageJSONPath)
102
+ } else if (isJava) {
103
+ const cdsrcJSONPath = path.join(this.projectPath, '.cdsrc.json')
104
+ await this.templateUtil.mergeJSON(cdsrcJSONPath, path.join(__dirname, 'files', 'java', '.cdsrc.json'))
105
+ await fs.copy(path.join(__dirname, 'files', 'java', 'package.json'), path.join(this.projectPath, 'mtx', 'sidecar', 'package.json'))
106
+ }
107
+ await this.runDependentMerging()
108
+ }
109
+ }
@@ -15,6 +15,9 @@
15
15
  "scripts": {
16
16
  "start": "cds run"
17
17
  },
18
+ "engines": {
19
+ "node": "^16.15"
20
+ },
18
21
  "eslintConfig": {
19
22
  "extends": "eslint:recommended",
20
23
  "env": {
@@ -1,5 +1,5 @@
1
+ const cds = require('@sap/cds');
1
2
  const path = require('path');
2
- const Config = require('@sap/cds/lib/env');
3
3
 
4
4
  const TemplateUtil = require('../util/templateUtil');
5
5
 
@@ -59,18 +59,19 @@ module.exports = class TemplateBase {
59
59
  projectPath = this.cwd;
60
60
  }
61
61
 
62
- return Config.for('cds', projectPath);
62
+ return cds.env.for('cds', projectPath);
63
63
  }
64
64
 
65
65
  /**
66
66
  * @abstract
67
- * Executes the given template's merging steps.
67
+ * Executes the given template's merging steps which are dependent on another template.
68
68
  * The separation from `run()` is necessary to preserve templating associativity,
69
69
  * i.e. the order in which you apply them does not matter.
70
70
  * Ex.: Assume `cds add hana` is called before `cds add mta`. We want `cds add mta`
71
71
  * to create the base mta.yaml template and merge the hana mta.yaml in, but _don't_
72
72
  * want any other steps from the hana template performed (e.g. creating the .hdiconfig).
73
73
  * Separating the two let's us run this _only_ the merging part of the template.
74
+ * In addition, this partial merging avoids cyclic template dependencies.
74
75
  */
75
76
  async runDependentMerging() {
76
77
 
@@ -0,0 +1,7 @@
1
+ {
2
+ "cds": {
3
+ "requires": {
4
+ "toggles": true
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "cds": {
3
+ "requires": {
4
+ "[{{cap.for}}]": {
5
+ "toggles": true
6
+ }
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,24 @@
1
+ const cds = require('../../../cds'), { path } = cds.utils
2
+ const TemplateBase = require('../templateBase')
3
+ const ProjectReader = require('../../util/projectReader')
4
+
5
+ module.exports = class TogglesTemplate extends TemplateBase {
6
+ constructor(projectPath, generator) {
7
+ super(projectPath, generator, __dirname)
8
+ this.projectReader = new ProjectReader(this)
9
+ }
10
+
11
+ async run() {
12
+ const projectDescriptor = await this.projectReader.read(this.options)
13
+ const { for: forProfile, isNodejs, isJava } = projectDescriptor.cap
14
+ if (isNodejs) {
15
+ const packageJSONPath = path.join(this.projectPath, 'package.json')
16
+ const cdsTemplateFile = forProfile ? 'cds.package.json.hbs' : 'cds.package.json'
17
+ await this.templateUtil.mergeJSON(packageJSONPath, path.join(__dirname, 'files', cdsTemplateFile), projectDescriptor)
18
+ await this.templateUtil.sortDependencies(packageJSONPath)
19
+ } else if (isJava) {
20
+ // TODO: implement
21
+ }
22
+ await this.runDependentMerging()
23
+ }
24
+ }
@@ -5,6 +5,16 @@ modules:
5
5
  requires:
6
6
  - name: {{cap.appName}}-auth
7
7
 
8
+ {{#cap.isJava}}
9
+ {{#cap.isMultitenant}}
10
+ - name: {{cap.appName}}-mtx-sidecar
11
+ type: nodejs
12
+ path: mtx/sidecar
13
+ requires:
14
+ - name: {{cap.appName}}-auth
15
+ {{/cap.isMultitenant}}
16
+ {{/cap.isJava}}
17
+
8
18
  resources:
9
19
  - name: {{cap.appName}}-auth
10
20
  type: org.cloudfoundry.managed-service
@@ -1,9 +1,8 @@
1
- const fs = require('fs')
2
1
  const path = require('path')
3
2
  const TemplateBase = require('../templateBase')
4
3
  const ProjectReader = require('../../util/projectReader')
5
- const { srvNode, srvJava, xsuaa } = require('../_merging/existences')
6
- const { PROJECT_TYPE, OPTION_HELM_UPDATE } = require('../../constants');
4
+ const { srvNode, srvJava, xsuaa, mtxSidecar } = require('../_merging/registry-mta')
5
+ const { PROJECT_TYPE, OPTION_HELM_UPDATE } = require('../../constants')
7
6
 
8
7
  module.exports = class XsuaaTemplate extends TemplateBase {
9
8
  constructor(projectPath, generator) {
@@ -13,35 +12,46 @@ module.exports = class XsuaaTemplate extends TemplateBase {
13
12
 
14
13
  async runDependentMerging() {
15
14
  const projectDescriptor = await this.projectReader.read(this.options)
16
- const { projectPath } = this
15
+ const { isMultitenant, isExtensible, hasMtaDeployment, isNodejs, isJava } = projectDescriptor.cap
17
16
 
18
- const mtaYAMLPath = path.join(projectPath, 'mta.yaml')
19
- if (!fs.existsSync(mtaYAMLPath)) return
17
+ if (hasMtaDeployment) {
18
+ const srv = isNodejs ? srvNode : srvJava
19
+ const additions = [srv, xsuaa]
20
+ if (isMultitenant && isJava) additions.push(mtxSidecar)
20
21
 
21
- const srv = projectDescriptor.cap.isNodejs ? srvNode : srvJava
22
- await this.templateUtil.mergeYAML(
23
- mtaYAMLPath,
24
- `${__dirname}/files/mta.yaml.hbs`,
25
- projectDescriptor,
26
- {
27
- existences: [srv, xsuaa],
28
- relationships: [{
29
- in: srv,
30
- inKeyPath: ["requires"],
31
- into: "name",
32
- existences: [xsuaa],
33
- existenceKeyPath: ["name"],
34
- }],
35
- }
36
- )
22
+ const mtaYAMLPath = path.join(this.projectPath, 'mta.yaml')
23
+ const relationships = [{
24
+ insert: [xsuaa, 'name'],
25
+ into: [srv, 'requires', 'name']
26
+ }]
27
+ relationships.push({
28
+ insert: [xsuaa, 'name'],
29
+ into: [mtxSidecar, 'requires', 'name']
30
+ })
31
+
32
+ await this.templateUtil.mergeYAML(
33
+ mtaYAMLPath,
34
+ `${__dirname}/files/mta.yaml.hbs`,
35
+ projectDescriptor,
36
+ {
37
+ additions,
38
+ relationships
39
+ }
40
+ )
41
+ }
37
42
 
38
43
  // Re-applying the merging part of `cds add mtx` because cds.compile.to.xsuaa
39
44
  // has overwritten the existing `xs-security.json`.
40
45
  // TODO: Find a generic solution for situation like these.
41
- if (projectDescriptor.cap.isMultitenant) {
42
- const MtxTemplate = require(`../mtx`)
43
- const mtxTemplate = new MtxTemplate(this.projectPath, this.generator)
44
- await mtxTemplate.runDependentMerging()
46
+ if (isMultitenant) {
47
+ const MultitenancyTemplate = require(`../multitenancy`)
48
+ const multitenancyTemplate = new MultitenancyTemplate(this.projectPath, this.generator)
49
+ await multitenancyTemplate.runDependentMerging()
50
+ }
51
+ if (isExtensible) {
52
+ const ExtensibilityTemplate = require(`../extensibility`)
53
+ const extensibilityTemplate = new ExtensibilityTemplate(this.projectPath, this.generator)
54
+ await extensibilityTemplate.runDependentMerging()
45
55
  }
46
56
  }
47
57
 
@@ -49,19 +59,20 @@ module.exports = class XsuaaTemplate extends TemplateBase {
49
59
  const { projectPath } = this
50
60
  const templatePath = path.join(__dirname, 'files')
51
61
  const projectDescriptor = await this.projectReader.read(this.options)
62
+ const { for: forProfile } = projectDescriptor.cap
52
63
 
53
64
  const projectType = await this.getProjectType();
54
65
  switch (projectType) {
55
66
  case PROJECT_TYPE.java: {
56
67
  const cdsrcJSONPath = path.join(projectPath, '.cdsrc.json')
57
- const cdsTemplateFile = projectDescriptor.cap.for ? 'cds.cdsrc.json.hbs' : 'cds.cdsrc.json'
68
+ const cdsTemplateFile = forProfile ? 'cds.cdsrc.json.hbs' : 'cds.cdsrc.json'
58
69
  const cdsTemplatePath = path.join(templatePath, cdsTemplateFile)
59
70
  await this.templateUtil.mergeJSON(cdsrcJSONPath, cdsTemplatePath, projectDescriptor)
60
71
  break
61
72
  }
62
73
  case PROJECT_TYPE.nodejs: {
63
74
  const packageJSONPath = path.join(projectPath, 'package.json')
64
- const cdsTemplateFile = projectDescriptor.cap.for ? 'cds.package.json.hbs' : 'cds.package.json'
75
+ const cdsTemplateFile = forProfile ? 'cds.package.json.hbs' : 'cds.package.json'
65
76
  const cdsTemplatePath = path.join(templatePath, cdsTemplateFile)
66
77
  await this.templateUtil.mergeJSON(packageJSONPath, cdsTemplatePath, projectDescriptor)
67
78
  const dependenciesTemplatePath = path.join(templatePath, 'dependencies.package.json')
@@ -76,12 +87,12 @@ module.exports = class XsuaaTemplate extends TemplateBase {
76
87
  } catch (error) { /* ignore */ }
77
88
  })() || { scopes: [], attributes: [], 'role-templates': [], 'authorities-inheritance': false }
78
89
 
79
- const mergingSemantics = { existences: xsuaa.scopes.map(scope => ({
90
+ const mergingSemantics = { additions: xsuaa.scopes.map(scope => ({
80
91
  ref: scope.name,
81
- keyPath: ["scopes"],
82
- constraints: [{
83
- comparisonKeyPath: ["name"],
84
- value: scope.name
92
+ in: 'scopes',
93
+ where: [{
94
+ property: 'name',
95
+ isEqualTo: scope.name
85
96
  }],
86
97
  }))}
87
98
  const xsSecurityPath = path.join(projectPath, 'xs-security.json')