From ed276f02c3c93c9edb5dd730e2d45c694e2fc64a Mon Sep 17 00:00:00 2001 From: Bradley Jones Date: Tue, 6 Aug 2024 13:49:19 +0100 Subject: [PATCH] feat: add option to disable RAW MIME type Signed-off-by: Bradley Jones --- pkg/adapter/anchore/adapter.go | 6 ++++++ pkg/adapter/anchore/config.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/pkg/adapter/anchore/adapter.go b/pkg/adapter/anchore/adapter.go index 0b8addd..1b64b6d 100644 --- a/pkg/adapter/anchore/adapter.go +++ b/pkg/adapter/anchore/adapter.go @@ -681,6 +681,12 @@ func nowISOFormat() string { func (s *HarborScannerAdapter) GetMetadata() (harbor.ScannerAdapterMetadata, error) { adapterMeta := adapter.AdapterMetadata + + // Disable RawReportMimeType if not enabled + if !s.Configuration.EnableRawMimeType { + adapterMeta.Capabilities[0].ProducesMIMETypes = []string{adapter.HarborVulnReportv1MimeType} + } + var err error var feedsUpdated time.Time diff --git a/pkg/adapter/anchore/config.go b/pkg/adapter/anchore/config.go index a48702d..b27a248 100644 --- a/pkg/adapter/anchore/config.go +++ b/pkg/adapter/anchore/config.go @@ -28,6 +28,7 @@ type AdapterConfig struct { AnchoreClientConfig client.Config // Credentials and client configuration CacheConfig CacheConfiguration UseAnchoreConfiguredCreds bool // If true, the adapter will ignore the dynamic credentials that are provided by harbor for each scan and will instead expect that the admin has configured Anchore with credentials out-of-band. Default is False. + EnableRawMimeType bool // If true, the scanner adapter will not attempt produce the Raw Mime type. Default is False. } const ( @@ -56,6 +57,8 @@ const ( DefaultDescriptionCacheEnabled = true DefaultDescriptionCacheTTL = 60 * 60 * 24 DefaultDescriptionCacheItemCount = 10000 + EnableRawMimeTypeEnvVarName = "SCANNER_ADAPTER_ENABLE_RAW_MIME_TYPE" + EnableRawMimeTypeDefault = true ReportCacheEnabledEnvVarName = "SCANNER_ADAPTER_REPORT_CACHE_ENABLED" ReportCacheItemCount = "SCANNER_ADAPTER_REPORT_CACHE_COUNT" ReportCacheTTL = "SCANNER_ADAPTER_REPORT_CACHE_TTL" @@ -299,5 +302,7 @@ func GetConfig() (AdapterConfig, error) { cfg.UseAnchoreConfiguredCreds, _ = GetEnvBoolean(UseAnchoreConfigCredsEnvVarName, UseAnchoreConfigCredsDefault) + cfg.EnableRawMimeType, _ = GetEnvBoolean(EnableRawMimeTypeEnvVarName, EnableRawMimeTypeDefault) + return cfg, nil }