snyk-docker-plugin
Version:
Snyk CLI docker plugin
63 lines • 2.11 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBufferContent = exports.getElfFileContent = exports.getFileContent = exports.getContent = void 0;
function getContent(extractedLayers, searchedAction, contentTypeValidation) {
const foundAppFiles = {};
for (const filePath of Object.keys(extractedLayers)) {
for (const actionName of Object.keys(extractedLayers[filePath])) {
if (actionName !== searchedAction) {
continue;
}
if (!contentTypeValidation(extractedLayers[filePath][actionName])) {
throw new Error("unexpected content type");
}
foundAppFiles[filePath] = extractedLayers[filePath][actionName];
}
}
return foundAppFiles;
}
exports.getContent = getContent;
function isStringType(type) {
return typeof type === "string";
}
function getFileContent(extractedLayers, searchedAction) {
let foundAppFiles;
try {
foundAppFiles = getContent(extractedLayers, searchedAction, isStringType);
}
catch (_a) {
throw new Error("expected string");
}
return foundAppFiles;
}
exports.getFileContent = getFileContent;
function isElfType(type) {
const elf = type;
return !!(elf.body && elf.body.programs && elf.body.sections);
}
function getElfFileContent(extractedLayers, searchedAction) {
let foundAppFiles;
try {
foundAppFiles = getContent(extractedLayers, searchedAction, isElfType);
}
catch (_a) {
throw new Error("elf file expected to contain programs and sections");
}
return foundAppFiles;
}
exports.getElfFileContent = getElfFileContent;
function isTypeBuffer(type) {
return Buffer.isBuffer(type);
}
function getBufferContent(extractedLayers, searchedAction) {
let foundAppFiles;
try {
foundAppFiles = getContent(extractedLayers, searchedAction, isTypeBuffer);
}
catch (_a) {
throw new Error("expected Buffer");
}
return foundAppFiles;
}
exports.getBufferContent = getBufferContent;
//# sourceMappingURL=index.js.map
;