From fe98e44c5683bbdbcfb0312ccd5dd0232a51fd24 Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Fri, 29 Sep 2023 21:50:30 +0000 Subject: [PATCH] fix: replace with faster JSON encoding Signed-off-by: Ramkumar Chinchani --- cmd/zb/helper.go | 4 +++- go.mod | 2 ++ go.sum | 4 ++-- golangcilint.yaml | 3 ++- pkg/api/config/config.go | 4 +++- pkg/api/routes.go | 3 ++- pkg/cli/client/client.go | 4 +++- pkg/cli/server/extensions_test.go | 2 +- pkg/cli/server/root.go | 7 ++++--- pkg/common/common.go | 5 ++++- pkg/common/http_client.go | 1 - pkg/extensions/extension_mgmt.go | 4 +++- pkg/extensions/lint/lint.go | 4 +++- pkg/extensions/monitoring/minimal_client.go | 5 ++++- pkg/extensions/search/convert/metadb.go | 4 +++- pkg/extensions/search/cve/cve.go | 4 +++- pkg/extensions/search/cve/trivy/scanner.go | 13 ++++++++++++- pkg/extensions/search/resolver.go | 4 +++- pkg/extensions/sync/local.go | 4 +++- pkg/extensions/sync/references/oci.go | 4 +++- pkg/extensions/sync/utils.go | 1 - pkg/meta/boltdb/boltdb.go | 4 +++- pkg/meta/common/common.go | 4 +++- pkg/meta/dynamodb/dynamodb.go | 5 +++-- pkg/meta/parse.go | 4 +++- pkg/storage/common/common.go | 4 +++- pkg/storage/imagestore/imagestore.go | 4 +++- pkg/storage/scrub.go | 1 - pkg/storage/storage.go | 4 +++- 29 files changed, 84 insertions(+), 32 deletions(-) diff --git a/cmd/zb/helper.go b/cmd/zb/helper.go index d091b8248..1ab60b243 100644 --- a/cmd/zb/helper.go +++ b/cmd/zb/helper.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "encoding/json" "fmt" "io" "log" @@ -15,6 +14,7 @@ import ( "time" "github.com/google/uuid" + jsoniter "github.com/json-iterator/go" godigest "github.com/opencontainers/go-digest" imeta "github.com/opencontainers/image-spec/specs-go" ispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -24,6 +24,8 @@ import ( "zotregistry.io/zot/pkg/common" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + func makeHTTPGetRequest(url string, resultPtr interface{}, client *resty.Client) error { resp, err := client.R().Get(url) if err != nil { diff --git a/go.mod b/go.mod index 402d15312..630c51a75 100644 --- a/go.mod +++ b/go.mod @@ -514,3 +514,5 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) + +replace github.com/aquasecurity/trivy v0.45.1 => github.com/project-zot/trivy v0.45.1-disable-analyzers diff --git a/go.sum b/go.sum index 62d5bd4ed..d11d9d209 100644 --- a/go.sum +++ b/go.sum @@ -396,8 +396,6 @@ github.com/aquasecurity/table v1.8.0/go.mod h1:eqOmvjjB7AhXFgFqpJUEE/ietg7RrMSJZ github.com/aquasecurity/testdocker v0.0.0-20230111101738-e741bda259da h1:pj/adfN0Wbzc0H8YkI1nX5K92wOU5/1/1TRuuc0y5Nw= github.com/aquasecurity/tml v0.6.1 h1:y2ZlGSfrhnn7t4ZJ/0rotuH+v5Jgv6BDDO5jB6A9gwo= github.com/aquasecurity/tml v0.6.1/go.mod h1:OnYMWY5lvI9ejU7yH9LCberWaaTBW7hBFsITiIMY2yY= -github.com/aquasecurity/trivy v0.45.1 h1:JjkrawgNpVUV6mxtFX635I3MhzDqmGkze46SnygkYN0= -github.com/aquasecurity/trivy v0.45.1/go.mod h1:3cawI6q9o32pPGXhuGEIWWwUCSMAzRk/FhsEdA4eW1k= github.com/aquasecurity/trivy-db v0.0.0-20230831170347-f732860d4917 h1:MQd7h7yUyA8UlUzhjNMzpUX0NpD7jfxmRfSKwp/Ji3E= github.com/aquasecurity/trivy-db v0.0.0-20230831170347-f732860d4917/go.mod h1:WJ5Qnk5ZNGWvks07GOZe2IOsuXrPfSC5c8hYGOGfrsU= github.com/aquasecurity/trivy-java-db v0.0.0-20230209231723-7cddb1406728 h1:0eS+V7SXHgqoT99tV1mtMW6HL4HdoB9qGLMCb1fZp8A= @@ -1438,6 +1436,8 @@ github.com/proglottis/gpgme v0.1.3 h1:Crxx0oz4LKB3QXc5Ea0J19K/3ICfy3ftr5exgUK1AU github.com/proglottis/gpgme v0.1.3/go.mod h1:fPbW/EZ0LvwQtH8Hy7eixhp1eF3G39dtx7GUN+0Gmy0= github.com/project-zot/mockoidc v0.0.0-20230307111146-f607b4b5fb97 h1:V6z9y0Yx2sQs4WSKx79mgkKJWwjbu/lHQg1yza5bmQE= github.com/project-zot/mockoidc v0.0.0-20230307111146-f607b4b5fb97/go.mod h1:46X30UrCsiwicZcg5L098Pyilaj94AO39mvS5PEyPn8= +github.com/project-zot/trivy v0.45.1-disable-analyzers h1:mrCqhX8rbYdM8WUXW6xledo5kZ0kVHiUnGkAMeniYcQ= +github.com/project-zot/trivy v0.45.1-disable-analyzers/go.mod h1:3cawI6q9o32pPGXhuGEIWWwUCSMAzRk/FhsEdA4eW1k= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= diff --git a/golangcilint.yaml b/golangcilint.yaml index 862c63185..37b44f9b0 100644 --- a/golangcilint.yaml +++ b/golangcilint.yaml @@ -50,7 +50,8 @@ linters-settings: checks: argument,case,condition,operation,return,assign ignored-numbers: 10,64 gomoddirectives: - replace-allow-list: [] + replace-allow-list: + - github.com/aquasecurity/trivy issues: exclude-rules: - path: pkg/extensions/search/schema.resolvers.go diff --git a/pkg/api/config/config.go b/pkg/api/config/config.go index 8ab156e32..1b3d5e994 100644 --- a/pkg/api/config/config.go +++ b/pkg/api/config/config.go @@ -1,16 +1,18 @@ package config import ( - "encoding/json" "os" "time" + jsoniter "github.com/json-iterator/go" distspec "github.com/opencontainers/distribution-spec/specs-go" extconf "zotregistry.io/zot/pkg/extensions/config" storageConstants "zotregistry.io/zot/pkg/storage/constants" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + var ( Commit string //nolint: gochecknoglobals ReleaseTag string //nolint: gochecknoglobals diff --git a/pkg/api/routes.go b/pkg/api/routes.go index 1db9a8044..6caba5d58 100644 --- a/pkg/api/routes.go +++ b/pkg/api/routes.go @@ -9,7 +9,6 @@ package api import ( "context" - "encoding/json" "errors" "fmt" "io" @@ -53,6 +52,8 @@ import ( "zotregistry.io/zot/pkg/test/inject" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + type RouteHandler struct { c *Controller } diff --git a/pkg/cli/client/client.go b/pkg/cli/client/client.go index fc74d77c0..3c690fc32 100644 --- a/pkg/cli/client/client.go +++ b/pkg/cli/client/client.go @@ -6,7 +6,6 @@ package client import ( "bytes" "context" - "encoding/json" "fmt" "io" "net/http" @@ -16,6 +15,7 @@ import ( "sync" "time" + jsoniter "github.com/json-iterator/go" ispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/sigstore/cosign/v2/pkg/oci/remote" @@ -23,6 +23,8 @@ import ( "zotregistry.io/zot/pkg/common" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + var ( httpClientsMap = make(map[string]*http.Client) //nolint: gochecknoglobals httpClientLock sync.Mutex //nolint: gochecknoglobals diff --git a/pkg/cli/server/extensions_test.go b/pkg/cli/server/extensions_test.go index bf2c6a61d..4f8e7c3c2 100644 --- a/pkg/cli/server/extensions_test.go +++ b/pkg/cli/server/extensions_test.go @@ -1031,7 +1031,7 @@ func TestServeSearchEnabledCVE(t *testing.T) { // The default config handling logic will convert the 1h interval to a 2h interval substring := "\"Search\":{\"Enable\":true,\"CVE\":{\"UpdateInterval\":7200000000000,\"Trivy\":" + - "{\"DBRepository\":\"ghcr.io/aquasecurity/trivy-db\",\"JavaDBRepository\":\"ghcr.io/aquasecurity/trivy-java-db\"}}}" + "{\"DBRepository\":\"ghcr.io/aquasecurity/trivy-db\",\"JavaDBRepository\":\"\"}}}" found, err := ReadLogFileAndSearchString(logPath, substring, readLogFileTimeout) diff --git a/pkg/cli/server/root.go b/pkg/cli/server/root.go index c4088fa80..dd8ba485f 100644 --- a/pkg/cli/server/root.go +++ b/pkg/cli/server/root.go @@ -551,9 +551,10 @@ func applyDefaultValues(config *config.Config, viperInstance *viper.Viper, log z if config.Extensions.Search.CVE.Trivy.JavaDBRepository == "" { defaultJavaDBDownloadURL := "ghcr.io/aquasecurity/trivy-java-db" - log.Info().Str("trivyJavaDownloadURL", defaultJavaDBDownloadURL). - Msg("Config: using default Trivy Java DB download URL.") - config.Extensions.Search.CVE.Trivy.JavaDBRepository = defaultJavaDBDownloadURL + log.Info().Str("trivyJavaDownloadURL", ""). + Str("suggestedTrivyJavaDownloadURL", defaultJavaDBDownloadURL). + Msg("Config: Trivy DB javaDBRepository configuration key was not provided, " + + "will skip scanning java packages") } } } diff --git a/pkg/common/common.go b/pkg/common/common.go index 1aa354a44..5f77ff33e 100644 --- a/pkg/common/common.go +++ b/pkg/common/common.go @@ -1,7 +1,6 @@ package common import ( - "encoding/json" "errors" "fmt" "io/fs" @@ -10,8 +9,12 @@ import ( "syscall" "time" "unicode/utf8" + + jsoniter "github.com/json-iterator/go" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + const ( httpTimeout = 5 * time.Minute certsPath = "/etc/containers/certs.d" diff --git a/pkg/common/http_client.go b/pkg/common/http_client.go index 7bf1b1d57..3b15ee681 100644 --- a/pkg/common/http_client.go +++ b/pkg/common/http_client.go @@ -4,7 +4,6 @@ import ( "context" "crypto/tls" "crypto/x509" - "encoding/json" "errors" "io" "net/http" diff --git a/pkg/extensions/extension_mgmt.go b/pkg/extensions/extension_mgmt.go index 0e41e4296..faf75ada7 100644 --- a/pkg/extensions/extension_mgmt.go +++ b/pkg/extensions/extension_mgmt.go @@ -4,10 +4,10 @@ package extensions import ( - "encoding/json" "net/http" "github.com/gorilla/mux" + jsoniter "github.com/json-iterator/go" "zotregistry.io/zot/pkg/api/config" "zotregistry.io/zot/pkg/api/constants" @@ -15,6 +15,8 @@ import ( "zotregistry.io/zot/pkg/log" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + type HTPasswd struct { Path string `json:"path,omitempty"` } diff --git a/pkg/extensions/lint/lint.go b/pkg/extensions/lint/lint.go index 9150fa2bb..d7713d262 100644 --- a/pkg/extensions/lint/lint.go +++ b/pkg/extensions/lint/lint.go @@ -4,9 +4,9 @@ package lint import ( - "encoding/json" "fmt" + jsoniter "github.com/json-iterator/go" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -16,6 +16,8 @@ import ( storageTypes "zotregistry.io/zot/pkg/storage/types" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + type Linter struct { config *config.LintConfig log log.Logger diff --git a/pkg/extensions/monitoring/minimal_client.go b/pkg/extensions/monitoring/minimal_client.go index 1f4a4e723..f71f7c38e 100644 --- a/pkg/extensions/monitoring/minimal_client.go +++ b/pkg/extensions/monitoring/minimal_client.go @@ -6,14 +6,17 @@ package monitoring import ( "context" "crypto/tls" - "encoding/json" "fmt" "net/http" "time" + jsoniter "github.com/json-iterator/go" + "zotregistry.io/zot/pkg/log" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + const ( httpTimeout = 1 * time.Minute ) diff --git a/pkg/extensions/search/convert/metadb.go b/pkg/extensions/search/convert/metadb.go index 5ff8f0329..4d08b28f3 100644 --- a/pkg/extensions/search/convert/metadb.go +++ b/pkg/extensions/search/convert/metadb.go @@ -2,7 +2,6 @@ package convert import ( "context" - "encoding/json" "fmt" "sort" "strconv" @@ -10,6 +9,7 @@ import ( "time" "github.com/99designs/gqlgen/graphql" + jsoniter "github.com/json-iterator/go" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/vektah/gqlparser/v2/gqlerror" @@ -24,6 +24,8 @@ import ( mTypes "zotregistry.io/zot/pkg/meta/types" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + type SkipQGLField struct { Vulnerabilities bool } diff --git a/pkg/extensions/search/cve/cve.go b/pkg/extensions/search/cve/cve.go index f4747cff7..8fb976f73 100644 --- a/pkg/extensions/search/cve/cve.go +++ b/pkg/extensions/search/cve/cve.go @@ -1,11 +1,11 @@ package cveinfo import ( - "encoding/json" "sort" "strings" "time" + jsoniter "github.com/json-iterator/go" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -17,6 +17,8 @@ import ( "zotregistry.io/zot/pkg/storage" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + type CveInfo interface { GetImageListForCVE(repo, cveID string) ([]cvemodel.TagInfo, error) GetImageListWithCVEFixed(repo, cveID string) ([]cvemodel.TagInfo, error) diff --git a/pkg/extensions/search/cve/trivy/scanner.go b/pkg/extensions/search/cve/trivy/scanner.go index 86e0a2f17..49bf02e34 100644 --- a/pkg/extensions/search/cve/trivy/scanner.go +++ b/pkg/extensions/search/cve/trivy/scanner.go @@ -2,7 +2,6 @@ package trivy import ( "context" - "encoding/json" "fmt" "os" "path" @@ -12,11 +11,13 @@ import ( dbTypes "github.com/aquasecurity/trivy-db/pkg/types" "github.com/aquasecurity/trivy/pkg/commands/artifact" "github.com/aquasecurity/trivy/pkg/commands/operation" + "github.com/aquasecurity/trivy/pkg/fanal/analyzer" fanalTypes "github.com/aquasecurity/trivy/pkg/fanal/types" "github.com/aquasecurity/trivy/pkg/flag" "github.com/aquasecurity/trivy/pkg/javadb" "github.com/aquasecurity/trivy/pkg/types" regTypes "github.com/google/go-containerregistry/pkg/v1/types" + jsoniter "github.com/json-iterator/go" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" _ "modernc.org/sqlite" @@ -31,15 +32,25 @@ import ( "zotregistry.io/zot/pkg/storage" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + const cacheSize = 1000000 // getNewScanOptions sets trivy configuration values for our scans and returns them as // a trivy Options structure. func getNewScanOptions(dir, dbRepository, javaDBRepository string) *flag.Options { + disabledAnalizers := []analyzer.Type{} + if javaDBRepository == "" { + disabledAnalizers = append(disabledAnalizers, analyzer.TypeJar) + disabledAnalizers = append(disabledAnalizers, analyzer.TypePom) + disabledAnalizers = append(disabledAnalizers, analyzer.TypeGradleLock) + } + scanOptions := flag.Options{ GlobalOptions: flag.GlobalOptions{ CacheDir: dir, }, + DisabledAnalyzers: disabledAnalizers, ScanOptions: flag.ScanOptions{ Scanners: types.Scanners{types.VulnerabilityScanner}, OfflineScan: true, diff --git a/pkg/extensions/search/resolver.go b/pkg/extensions/search/resolver.go index 5bbd0daab..555345bdc 100644 --- a/pkg/extensions/search/resolver.go +++ b/pkg/extensions/search/resolver.go @@ -6,13 +6,13 @@ package search import ( "context" - "encoding/json" "errors" "fmt" "sort" "strings" "github.com/99designs/gqlgen/graphql" + jsoniter "github.com/json-iterator/go" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/vektah/gqlparser/v2/gqlerror" @@ -30,6 +30,8 @@ import ( "zotregistry.io/zot/pkg/storage" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + // THIS CODE IS A STARTING POINT ONLY. IT WILL NOT BE UPDATED WITH SCHEMA CHANGES. const ( diff --git a/pkg/extensions/sync/local.go b/pkg/extensions/sync/local.go index 9bf171790..a6e64e60b 100644 --- a/pkg/extensions/sync/local.go +++ b/pkg/extensions/sync/local.go @@ -4,7 +4,6 @@ package sync import ( - "encoding/json" "errors" "fmt" "os" @@ -13,6 +12,7 @@ import ( "time" "github.com/containers/image/v5/types" + jsoniter "github.com/json-iterator/go" "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -28,6 +28,8 @@ import ( storageTypes "zotregistry.io/zot/pkg/storage/types" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + type LocalRegistry struct { storeController storage.StoreController tempStorage OciLayoutStorage diff --git a/pkg/extensions/sync/references/oci.go b/pkg/extensions/sync/references/oci.go index 4a98a33e6..0368da309 100644 --- a/pkg/extensions/sync/references/oci.go +++ b/pkg/extensions/sync/references/oci.go @@ -5,11 +5,11 @@ package references import ( "context" - "encoding/json" "errors" "fmt" "net/http" + jsoniter "github.com/json-iterator/go" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -24,6 +24,8 @@ import ( storageTypes "zotregistry.io/zot/pkg/storage/types" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + type OciReferences struct { client *client.Client storeController storage.StoreController diff --git a/pkg/extensions/sync/utils.go b/pkg/extensions/sync/utils.go index 7513cb562..c501d9116 100644 --- a/pkg/extensions/sync/utils.go +++ b/pkg/extensions/sync/utils.go @@ -6,7 +6,6 @@ package sync import ( "bytes" "context" - "encoding/json" "fmt" "io" "os" diff --git a/pkg/meta/boltdb/boltdb.go b/pkg/meta/boltdb/boltdb.go index ca14e456d..9c5f5774a 100644 --- a/pkg/meta/boltdb/boltdb.go +++ b/pkg/meta/boltdb/boltdb.go @@ -2,12 +2,12 @@ package boltdb import ( "context" - "encoding/json" "errors" "fmt" "strings" "time" + jsoniter "github.com/json-iterator/go" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" "go.etcd.io/bbolt" @@ -22,6 +22,8 @@ import ( reqCtx "zotregistry.io/zot/pkg/requestcontext" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + type BoltDB struct { DB *bbolt.DB Patches []func(DB *bbolt.DB) error diff --git a/pkg/meta/common/common.go b/pkg/meta/common/common.go index f97dfa010..d40a01a6a 100644 --- a/pkg/meta/common/common.go +++ b/pkg/meta/common/common.go @@ -1,11 +1,11 @@ package common import ( - "encoding/json" "fmt" "strings" "time" + jsoniter "github.com/json-iterator/go" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -13,6 +13,8 @@ import ( mTypes "zotregistry.io/zot/pkg/meta/types" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + func UpdateManifestMeta(repoMeta mTypes.RepoMetadata, manifestDigest godigest.Digest, manifestMeta mTypes.ManifestMetadata, ) mTypes.RepoMetadata { diff --git a/pkg/meta/dynamodb/dynamodb.go b/pkg/meta/dynamodb/dynamodb.go index d96c2b1df..718200b63 100644 --- a/pkg/meta/dynamodb/dynamodb.go +++ b/pkg/meta/dynamodb/dynamodb.go @@ -2,7 +2,6 @@ package dynamodb import ( "context" - "encoding/json" "errors" "fmt" "strings" @@ -12,9 +11,9 @@ import ( "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" "github.com/aws/aws-sdk-go-v2/service/dynamodb" "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" + jsoniter "github.com/json-iterator/go" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" - zerr "zotregistry.io/zot/errors" "zotregistry.io/zot/pkg/api/constants" zcommon "zotregistry.io/zot/pkg/common" @@ -25,6 +24,8 @@ import ( reqCtx "zotregistry.io/zot/pkg/requestcontext" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + var errMetaDB = errors.New("metadb: error while constructing manifest meta") type DynamoDB struct { diff --git a/pkg/meta/parse.go b/pkg/meta/parse.go index d9317f65c..f8e8537a4 100644 --- a/pkg/meta/parse.go +++ b/pkg/meta/parse.go @@ -1,11 +1,11 @@ package meta import ( - "encoding/json" "errors" "fmt" "time" + jsoniter "github.com/json-iterator/go" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -17,6 +17,8 @@ import ( storageTypes "zotregistry.io/zot/pkg/storage/types" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + // ParseStorage will sync all repos found in the rootdirectory of the oci layout that zot was deployed on with the // ParseStorage database. func ParseStorage(metaDB mTypes.MetaDB, storeController storage.StoreController, log log.Logger) error { diff --git a/pkg/storage/common/common.go b/pkg/storage/common/common.go index 533c078f5..40a6f6349 100644 --- a/pkg/storage/common/common.go +++ b/pkg/storage/common/common.go @@ -3,13 +3,13 @@ package storage import ( "bytes" "context" - "encoding/json" "errors" "fmt" "path" "strings" "github.com/docker/distribution/registry/storage/driver" + jsoniter "github.com/json-iterator/go" godigest "github.com/opencontainers/go-digest" "github.com/opencontainers/image-spec/schema" imeta "github.com/opencontainers/image-spec/specs-go" @@ -24,6 +24,8 @@ import ( storageTypes "zotregistry.io/zot/pkg/storage/types" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + const ( manifestWithEmptyLayersErrMsg = "layers: Array must have at least 1 items" cosignSignatureTagSuffix = "sig" diff --git a/pkg/storage/imagestore/imagestore.go b/pkg/storage/imagestore/imagestore.go index a65762c10..3f37e6935 100644 --- a/pkg/storage/imagestore/imagestore.go +++ b/pkg/storage/imagestore/imagestore.go @@ -3,7 +3,6 @@ package imagestore import ( "bytes" "crypto/sha256" - "encoding/json" "errors" "fmt" "io" @@ -16,6 +15,7 @@ import ( "github.com/docker/distribution/registry/storage/driver" guuid "github.com/gofrs/uuid" + jsoniter "github.com/json-iterator/go" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" artifactspec "github.com/oras-project/artifacts-spec/specs-go/v1" @@ -34,6 +34,8 @@ import ( "zotregistry.io/zot/pkg/test/inject" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + const ( cosignSignatureTagSuffix = "sig" SBOMTagSuffix = "sbom" diff --git a/pkg/storage/scrub.go b/pkg/storage/scrub.go index 3c4f31c62..ba214fcc0 100644 --- a/pkg/storage/scrub.go +++ b/pkg/storage/scrub.go @@ -2,7 +2,6 @@ package storage import ( "context" - "encoding/json" "fmt" "io" "strings" diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 56da20b74..f6d55b933 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -1,12 +1,12 @@ package storage import ( - "encoding/json" "fmt" "regexp" "strings" "github.com/docker/distribution/registry/storage/driver/factory" + jsoniter "github.com/json-iterator/go" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -22,6 +22,8 @@ import ( storageTypes "zotregistry.io/zot/pkg/storage/types" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary //nolint: gochecknoglobals // to replace standard lib + func New(config *config.Config, linter common.Lint, metrics monitoring.MetricServer, log log.Logger, ) (StoreController, error) {