UNPKG

snyk-docker-plugin

Version:
151 lines (150 loc) 4.61 kB
/// <reference types="node" /> /// <reference types="node" /> /// <reference types="node" /> import { Readable } from "stream"; import { Elf } from "../go-parser/types"; import { AutoDetectedUserInstructions, PluginOptions } from "../types"; export type ExtractCallback = (dataStream: Readable, streamSize?: number) => Promise<string | Buffer>; export type FileContent = string | Buffer | Elf; export type FileNameAndContent = Record<string, FileContent>; export interface Extractor { extractArchive(fileSystemPath: string, extractActions: ExtractAction[], options: Partial<PluginOptions>): ExtractedLayersAndManifest; getImageIdFromManifest(manifest: DockerArchiveManifest | OciArchiveManifest): string; getManifestLayers(manifest: DockerArchiveManifest | OciArchiveManifest): string[]; } export type SymlinkMap = Record<string, string>; export interface ExtractionResult { imageId: string; manifestLayers: string[]; extractedLayers: ExtractedLayers; /** * Per-layer extracted file contents in FROM->top order, aligned 1:1 with * `rootFsLayers` (index `i` is the same rootfs layer in both). Unlike * `extractedLayers` (a single "latest wins" merge across all layers), this * preserves the per-layer view the layer-attribution algorithm diffs. * Populated only when the `layer-attribution` option is enabled. */ orderedLayers?: ExtractedLayers[]; symlinks?: SymlinkMap; rootFsLayers?: string[]; autoDetectedUserInstructions?: AutoDetectedUserInstructions; platform?: string; imageLabels?: { [key: string]: string; }; imageCreationTime?: string; containerConfig?: ContainerConfig | null; history?: HistoryEntry[] | null; attestations?: ResolvedAttestationManifest[]; } export interface ExtractedLayers { [layerName: string]: FileNameAndContent; } export interface TarArchiveManifest { Config: string; RepoTags: string[]; Layers: string[]; } export interface DockerArchiveManifest extends TarArchiveManifest { } export interface KanikoArchiveManifest extends TarArchiveManifest { } export interface ExtractedLayersAndManifest { layers: ExtractedLayers[]; symlinkLayers?: SymlinkMap[]; manifest: TarArchiveManifest | OciArchiveManifest; imageConfig: ImageConfig; attestations?: ResolvedAttestationManifest[]; } export interface ContainerConfig { User?: string | null; ExposedPorts?: { [port: string]: object; } | null; Env?: string[] | null; Entrypoint?: string[] | null; Cmd?: string[] | null; Volumes?: { [path: string]: object; } | null; WorkingDir?: string | null; Labels?: { [key: string]: string; }; StopSignal?: string | null; ArgsEscaped?: boolean | null; } export interface HistoryEntry { created?: string | null; author?: string | null; created_by?: string | null; comment?: string | null; empty_layer?: boolean | null; } export interface ImageConfig { architecture: string; os: string; rootfs: { diff_ids: string[]; }; config: ContainerConfig | null; created: string; history?: HistoryEntry[] | null; } export interface OciArchiveLayer { digest: string; mediaType?: string; size?: number; annotations?: Record<string, string>; } export interface OciArchiveManifest { schemaVersion: string; mediaType?: string; config: { digest: string; mediaType?: string; }; layers: OciArchiveLayer[]; annotations?: Record<string, string>; } export interface OciManifestInfo { digest: string; mediaType: string; size?: number; platform?: OciPlatformInfo; annotations?: Record<string, string>; } export interface OciPlatformInfo { os?: string; architecture?: string; variant?: string; } export interface OciImageIndex { mediaType?: string; manifests: OciManifestInfo[]; } export interface InTotoSubject { name?: string; digest?: Record<string, string>; } export interface InTotoStatement { _type?: string; subject?: InTotoSubject[]; predicateType?: string; predicate?: Record<string, unknown>; } export interface ResolvedAttestationManifest { manifestDigest: string; attestedManifestDigest?: string; manifest: OciArchiveManifest; inTotoStatements: Record<string, InTotoStatement>; } export interface ExtractAction { actionName: string; filePathMatches: (filePath: string) => boolean; callback?: ExtractCallback; } export interface DetectedImageLayers { packages: any; layers: any; }