@controlplane/cli
Version:
Control Plane Corporation CLI
59 lines • 1.82 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const path = require("path");
const composeResource_1 = require("./composeResource");
class Secret extends composeResource_1.default {
constructor(name, body, context, composePath) {
super(name, 'secret', body, context, composePath);
this.identities = [];
}
async init() {
// getting secret
const filePath = path.join(this.composePath, this.body.file);
if (this.body.file)
this.payload = await fs_1.promises.readFile(filePath, 'utf-8');
}
addIdentity(identity) {
if (!this.identities.includes(identity))
this.identities.push(identity);
}
getUri() {
return `cpln://secret/${this.getName()}`;
}
toPolicy() {
return {
kind: 'policy',
name: `${this.getName()}-policy`,
description: `Policy for workloads to reveal ${this.getName()}`,
tags: {},
bindings: [
{
permissions: ['reveal'],
principalLinks: this.identities.map((i) => i.toLink()),
},
],
targetKind: 'secret',
targetLinks: [this.toSelfLink()],
};
}
toSecret() {
var _a;
return {
kind: 'secret',
name: this.getName(),
description: this.getName(),
tags: {},
type: 'opaque',
data: {
encoding: 'plain',
payload: (_a = this.payload) !== null && _a !== void 0 ? _a : '',
},
};
}
toResource() {
return [this.toPolicy(), this.toSecret()];
}
}
exports.default = Secret;
//# sourceMappingURL=secret.js.map
;