@fbl-plugins/k8s-kubectl
Version:
FBL plugin for K8s Kubectl CLI
103 lines • 4.14 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApplyDockerSecretActionProcessor = void 0;
const Joi = require("joi");
const BaseActionProcessor_1 = require("../BaseActionProcessor");
const fbl_1 = require("fbl");
class ApplyDockerSecretActionProcessor extends BaseActionProcessor_1.BaseActionProcessor {
/**
* @inheritdoc
*/
getValidationSchema() {
return ApplyDockerSecretActionProcessor.validationSchema;
}
/**
* @inheritdoc
*/
execute() {
return __awaiter(this, void 0, void 0, function* () {
const args = yield this.prepareCLIArgs();
yield this.execKubectlCommand(args, this.options.debug);
});
}
/**
* Prepare CLI args
*/
prepareCLIArgs() {
return __awaiter(this, void 0, void 0, function* () {
const args = ['apply'];
let dockerconfigjson;
if (this.options.inline) {
const { username, password, email, server } = this.options.inline;
dockerconfigjson = Buffer.from(JSON.stringify({
auths: {
[server]: {
username,
password,
email,
auth: Buffer.from(`${username}:${password}`).toString('base64'),
},
},
})).toString('base64');
}
else {
const path = fbl_1.FSUtil.getAbsolutePath(this.options.path, this.snapshot.wd);
const fileContents = yield fbl_1.FSUtil.readFile(path);
dockerconfigjson = fileContents.toString('base64');
}
const secretFilePaht = yield this.writeJsonToTempFile({
apiVersion: 'v1',
kind: 'Secret',
metadata: {
name: this.options.name,
namespace: this.options.namespace,
labels: this.options.labels,
},
data: {
'.dockerconfigjson': dockerconfigjson,
},
type: 'kubernetes.io/dockerconfigjson',
});
args.push('-f', secretFilePaht);
if (this.options.extra) {
args.push(...this.options.extra);
}
return args;
});
}
}
exports.ApplyDockerSecretActionProcessor = ApplyDockerSecretActionProcessor;
ApplyDockerSecretActionProcessor.validationSchema = Joi.object({
name: Joi.string().min(1).required(),
path: Joi.string().min(1),
inline: Joi.object({
username: Joi.string().required().min(1),
password: Joi.string().required().min(1),
email: Joi.string().required().min(1),
server: Joi.string().required().min(1),
}).options({
allowUnknown: false,
abortEarly: true,
}),
labels: Joi.object().pattern(Joi.string().min(1).required(), Joi.string().required().min(1)),
// enable verbose output
debug: Joi.boolean(),
// Namespace
namespace: Joi.string(),
// extra arguments to append to the command
// refer to `kubectl apply --help` for all available options
extra: Joi.array().items(Joi.string()),
})
.xor('path', 'inline')
.required()
.options({ abortEarly: true });
//# sourceMappingURL=ApplyDockerSercretActionProcessor.js.map