@openzeppelin/defender-as-code
Version:
Configure your Defender environment via code
42 lines (41 loc) • 1.77 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = __importDefault(require("../utils/logger"));
const utils_1 = require("@openzeppelin/defender-sdk-action-client/lib/utils");
const utils_2 = require("../utils");
class DefenderLogs {
constructor(serverless, options, logging) {
this.serverless = serverless;
this.options = options;
this.logging = logging;
this.log = logger_1.default.getInstance();
this.hooks = {
'before:logs:logs': () => this.validateKeys(),
'logs:logs': this.logs.bind(this),
};
}
validateKeys() {
this.teamKey = (0, utils_2.getTeamAPIkeysOrThrow)(this.serverless);
}
async logs() {
try {
this.log.notice('========================================================');
this.log.progress('logs', `Running Defender Logs on stack function: ${this.options.function}`);
const client = (0, utils_2.getActionClient)(this.teamKey);
const list = (await client.list()).items;
const defenderAction = (0, utils_2.getEquivalentResourceByKey)(this.options.function, list);
if (defenderAction)
await (0, utils_1.tailLogsFor)(client, defenderAction.actionId);
else
this.log.error(`No action with stackResourceId: ${this.options.function} found.`);
this.log.notice('========================================================');
}
catch (e) {
this.log.tryLogDefenderError(e);
}
}
}
exports.default = DefenderLogs;