UNPKG

@sap/cds-dk

Version:

Command line client and development toolkit for the SAP Cloud Application Programming Model

78 lines (64 loc) 2.78 kB
const { readProject } = require('../../projectReader') const { merge, sort } = require('../../merge') const { srv4 } = require('../../registries/mta') const mvn = require('../../mvn') module.exports = class AmsTemplate extends require('../../plugin') { static help() { return 'authorization via AMS' } requires() { return ['ias'] } static hasInProduction(env) { const { dependencies, devDependencies } = readProject() return env.requires?.auth?.ams || devDependencies?.['@sap/ams-dev'] || devDependencies?.['@sap/ams'] || dependencies?.['@sap/ams'] } async run() { const project = readProject() await merge(__dirname, 'files/package.json.hbs').into('package.json', { project, forceOverwrite: true }) project.isNodejs && await sort('package.json', 'dependencies') await sort('package.json', 'devDependencies') if (project.isJava) await mvn.add('ams') } async combine() { const project = readProject() const { addMta, addCfManifest, addKyma } = project if (addMta) { await this.#combineWithMta(project) } if (addCfManifest) { await this.#combineWithCfManifest(project) } if (addKyma) { await this.#combineWithHelm(project) await this.#combineWithContainerize(project) } } async #combineWithMta(project) { const srv = srv4(project.srvPath) const amsPoliciesDeployer = { in: 'modules', where: { 'name': `${project.appName}-ams-policies-deployer` } } await merge(__dirname, 'files/mta.yaml.hbs').into('mta.yaml', { project, additions: [srv, amsPoliciesDeployer] }) } async #combineWithCfManifest(project) { const amsPoliciesDeployer = { in: 'applications', where: { 'name': `${project.appName}-ams-policies-deployer` } } await merge(__dirname, 'files/manifest.yml.hbs').into('manifest.yml', { project, additions: [amsPoliciesDeployer] }) } async #combineWithHelm(project) { const amsPoliciesDeployer = { in: 'dependencies', where: { 'alias': 'ams-policies-deployer' } } await merge(__dirname, 'files/Chart.yaml.hbs').into('chart/Chart.yaml', { project, additions: [amsPoliciesDeployer] }) await merge(__dirname, 'files/values.yaml.hbs').into('chart/values.yaml', { project }) } async #combineWithContainerize(project) { const amsDeployer = { in: 'modules', where: { 'name': `${project.appName}-ams-policies-deployer` } } await merge(__dirname, 'files/containerize.yaml.hbs').into('containerize.yaml', { project, additions: [amsDeployer] }) } }