@apigeeks/fbl-k8s-plugin
Version:
fbl wrapper plugin for helm and kubectl cli utilities
77 lines • 3.06 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const Joi = require("joi");
const typedi_1 = require("typedi");
const path_1 = require("path");
const fbl_1 = require("fbl");
const services_1 = require("../../services");
class K8sApplyGenericSecretActionHandler extends fbl_1.ActionHandler {
/* istanbul ignore next */
getMetadata() {
return K8sApplyGenericSecretActionHandler.metadata;
}
getValidationSchema() {
return K8sApplyGenericSecretActionHandler.schema;
}
execute(options, context, snapshot, parameters) {
return __awaiter(this, void 0, void 0, function* () {
const object = {
apiVersion: 'v1',
kind: 'Secret',
metadata: {
name: options.name,
},
data: {},
};
if (options.namespace) {
object.metadata.namespace = options.namespace;
}
if (options.inline) {
for (const key of Object.keys(options.inline)) {
object.data[key] = Buffer.from(options.inline[key].toString()).toString('base64');
}
}
if (options.files) {
for (const file of options.files) {
object.data[path_1.basename(file)] = (yield fbl_1.FSUtil.readFile(fbl_1.FSUtil.getAbsolutePath(file, snapshot.wd))).toString('base64');
}
}
yield typedi_1.Container.get(services_1.K8sKubectlService).applyObject(object, context);
});
}
}
K8sApplyGenericSecretActionHandler.metadata = {
id: 'a6s.k8s.kubectl.apply.Secret.generic',
aliases: [
'k8s.kubectl.apply.Secret.generic',
'kubectl.apply.Secret.generic',
'kubectl.Secret.generic',
'kubectl.Secret',
],
};
K8sApplyGenericSecretActionHandler.schema = Joi.object()
.keys({
name: Joi.string()
.required()
.min(1),
namespace: Joi.string().min(1),
files: Joi.array()
.min(1)
.items(Joi.string().required())
.optional(),
inline: Joi.object()
.pattern(/[\w|\d]+/, Joi.alternatives([Joi.string(), Joi.number()]))
.min(1)
.optional(),
})
.or(['files', 'inline']);
exports.K8sApplyGenericSecretActionHandler = K8sApplyGenericSecretActionHandler;
//# sourceMappingURL=K8sApplyGenericSecretActionHandler.js.map