snyk-docker-plugin
Version:
Snyk CLI docker plugin
47 lines • 1.8 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");
/**
* Return false if any exclusion pattern matches,
* return true if any inclusion pattern matches
*/
function generatePathMatcher(globsInclude, globsExclude) {
return (filePath) => {
if (globsExclude.some((glob) => minimatch(filePath, glob))) {
return false;
}
return globsInclude.some((glob) => minimatch(filePath, glob));
};
}
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