snyk-docker-plugin
Version:
Snyk CLI docker plugin
53 lines • 1.91 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMatchingFiles = exports.generateExtractAction = void 0;
const minimatch = require("minimatch");
const path = require("path");
const stream_utils_1 = require("../../stream-utils");
function generatePathMatcher(globsInclude, globsExclude) {
return (filePath) => {
let exclude = false;
for (const g of globsExclude) {
if (!exclude && minimatch(filePath, g)) {
exclude = true;
}
}
if (!exclude) {
for (const g of globsInclude) {
if (minimatch(filePath, g)) {
return true;
}
}
}
return false;
};
}
function generateExtractAction(globsInclude, globsExclude) {
return {
actionName: "find-files-by-pattern",
filePathMatches: generatePathMatcher(globsInclude, globsExclude),
callback: (dataStream, streamSize) => (0, stream_utils_1.streamToString)(dataStream, streamSize, "base64"),
};
}
exports.generateExtractAction = generateExtractAction;
function getMatchingFiles(extractedLayers) {
const manifestFiles = [];
for (const filePath of Object.keys(extractedLayers)) {
for (const actionName of Object.keys(extractedLayers[filePath])) {
if (actionName !== "find-files-by-pattern") {
continue;
}
if (typeof extractedLayers[filePath][actionName] !== "string") {
throw new Error("expected a string");
}
manifestFiles.push({
name: path.basename(filePath),
path: path.dirname(filePath),
contents: extractedLayers[filePath][actionName],
});
}
}
return manifestFiles;
}
exports.getMatchingFiles = getMatchingFiles;
//# sourceMappingURL=static.js.map
;