|
| 1 | +const debug = require('debug')('codefresh:cli:create:context:secret-store:kubernetes'); |
| 2 | +const Command = require('../../../../../Command'); |
| 3 | +const CFError = require('cf-errors'); |
| 4 | +const cmd = require('../base.cmd'); |
| 5 | +const { sdk } = require('../../../../../../../logic'); |
| 6 | + |
| 7 | +const command = new Command({ |
| 8 | + command: 'kubernetes-runtime <name>', |
| 9 | + parent: cmd, |
| 10 | + description: 'Create a secret-store Kubernetes-Runtime context', |
| 11 | + usage: 'Create a secret store to use hybrid runtime to access K8S secret/configmap and use it as secret store', |
| 12 | + webDocs: { |
| 13 | + category: 'Create Secret-Store Context', |
| 14 | + subCategory: 'kubernetes-Runtime', |
| 15 | + title: 'kubernetes-runtime', |
| 16 | + weight: 10, |
| 17 | + }, |
| 18 | + builder: (yargs) => { |
| 19 | + yargs |
| 20 | + .option('runtimes', { |
| 21 | + describe: 'Names of the runtime-environment to be used as secret store', |
| 22 | + type: 'array', |
| 23 | + default: ['*'], |
| 24 | + }) |
| 25 | + .option('resource-type', { |
| 26 | + describe: 'Type of the resource in Kubernetes', |
| 27 | + required: true, |
| 28 | + choices: ['secret', 'configmap'], |
| 29 | + }) |
| 30 | + .option('resource-name', { |
| 31 | + describe: 'Name of the resource in Kubernetes', |
| 32 | + required: true, |
| 33 | + }); |
| 34 | + return yargs; |
| 35 | + }, |
| 36 | + handler: async (argv) => { |
| 37 | + let runtimes = []; |
| 38 | + if (argv.runtime) { |
| 39 | + runtimes = argv.runtime; |
| 40 | + } |
| 41 | + const data = { |
| 42 | + apiVersion: 'v1', |
| 43 | + kind: 'context', |
| 44 | + metadata: { |
| 45 | + name: argv.name, |
| 46 | + }, |
| 47 | + spec: { |
| 48 | + type: 'secret-store.kubernetes-runtime', |
| 49 | + data: { |
| 50 | + sharingPolicy: argv.sharingPolicy, |
| 51 | + resourceType: argv.resourceType, |
| 52 | + resourceName: argv.resourceName, |
| 53 | + runtimes, |
| 54 | + }, |
| 55 | + }, |
| 56 | + }; |
| 57 | + |
| 58 | + |
| 59 | + if (!data.metadata.name || !data.spec.type) { |
| 60 | + throw new CFError('Name and type must be provided'); |
| 61 | + } |
| 62 | + await sdk.contexts.create(data); |
| 63 | + console.log(`Context: ${data.metadata.name} created`); |
| 64 | + }, |
| 65 | +}); |
| 66 | + |
| 67 | +module.exports = command; |
0 commit comments