UNPKG

snyk-docker-plugin

Version:
51 lines 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseAnalysisResults = exports.selectPrimaryPackageAnalysis = void 0; const types_1 = require("../analyzer/types"); /** * Selects the single OS-package analysis that represents the image, using * the "first non-empty result wins" rule. The OS dep graph is built from * exactly this one analysis (see `parseAnalysisResults`), so any other * producer that needs to agree with the dep graph on "which OS package * manager is this image?" — e.g. layer attribution — must select through * here rather than re-deriving its own answer, to avoid drift. * * Returns `undefined` for scratch / unknown-PM images (no non-empty result). */ function selectPrimaryPackageAnalysis(results) { return results.find((res) => res.Analysis && res.Analysis.length > 0); } exports.selectPrimaryPackageAnalysis = selectPrimaryPackageAnalysis; function parseAnalysisResults(targetImage, analysis) { let analysisResult = selectPrimaryPackageAnalysis(analysis.results); if (!analysisResult) { // Special case when we have no package management // on scratch images or images with unknown package manager analysisResult = { Image: targetImage, AnalyzeType: types_1.AnalysisType.Linux, Analysis: [], }; } let packageFormat; switch (analysisResult.AnalyzeType) { case types_1.AnalysisType.Apt: case types_1.AnalysisType.Chisel: { packageFormat = "deb"; break; } default: { packageFormat = analysisResult.AnalyzeType.toLowerCase(); } } return { imageId: analysis.imageId, platform: analysis.platform, targetOS: analysis.osRelease, packageFormat, depInfosList: analysisResult.Analysis, imageLayers: analysis.imageLayers, }; } exports.parseAnalysisResults = parseAnalysisResults; //# sourceMappingURL=index.js.map