mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 12:58:02 +08:00
Update go version to 1.19 (#829)
* ci: Update go version to 1.19 Signed-off-by: Nicol Draghici <idraghic@cisco.com> * ci: Fix lint issues Signed-off-by: Nicol Draghici <idraghic@cisco.com> * ci: Added needprivileges to lint, made needprivileges pass lint Signed-off-by: Catalin Hofnar <catalin.hofnar@gmail.com> Signed-off-by: Nicol Draghici <idraghic@cisco.com> Signed-off-by: Nicol Draghici <idraghic@cisco.com> Signed-off-by: Catalin Hofnar <catalin.hofnar@gmail.com> Co-authored-by: Catalin Hofnar <catalin.hofnar@gmail.com>
This commit is contained in:
@@ -21,7 +21,7 @@ import (
|
||||
// We need this object to be a singleton as read/writes in the CVE DB may
|
||||
// occur at any time via DB downloads as well as during scanning.
|
||||
// The library doesn't seem to handle concurrency very well internally.
|
||||
var cveInfo cveinfo.CveInfo // nolint:gochecknoglobals
|
||||
var cveInfo cveinfo.CveInfo //nolint:gochecknoglobals
|
||||
|
||||
func EnableSearchExtension(config *config.Config, log log.Logger, storeController storage.StoreController) {
|
||||
if config.Extensions.Search != nil && *config.Extensions.Search.Enable && config.Extensions.Search.CVE != nil {
|
||||
|
||||
@@ -40,7 +40,7 @@ const (
|
||||
)
|
||||
|
||||
func TestVerifyMandatoryAnnotations(t *testing.T) {
|
||||
// nolint: dupl
|
||||
//nolint: dupl
|
||||
Convey("Mandatory annotations disabled", t, func() {
|
||||
port := test.GetFreePort()
|
||||
baseURL := test.GetBaseURL(port)
|
||||
@@ -87,7 +87,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
})
|
||||
|
||||
// nolint: dupl
|
||||
//nolint: dupl
|
||||
Convey("Mandatory annotations enabled, but no list in config", t, func() {
|
||||
port := test.GetFreePort()
|
||||
baseURL := test.GetBaseURL(port)
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
const metricsNamespace = "zot"
|
||||
|
||||
var (
|
||||
httpConnRequests = promauto.NewCounterVec( // nolint: gochecknoglobals
|
||||
httpConnRequests = promauto.NewCounterVec( //nolint: gochecknoglobals
|
||||
prometheus.CounterOpts{
|
||||
Namespace: metricsNamespace,
|
||||
Name: "http_requests_total",
|
||||
@@ -25,7 +25,7 @@ var (
|
||||
},
|
||||
[]string{"method", "code"},
|
||||
)
|
||||
httpRepoLatency = promauto.NewSummaryVec( // nolint: gochecknoglobals
|
||||
httpRepoLatency = promauto.NewSummaryVec( //nolint: gochecknoglobals
|
||||
prometheus.SummaryOpts{
|
||||
Namespace: metricsNamespace,
|
||||
Name: "http_repo_latency_seconds",
|
||||
@@ -33,7 +33,7 @@ var (
|
||||
},
|
||||
[]string{"repo"},
|
||||
)
|
||||
httpMethodLatency = promauto.NewHistogramVec( // nolint: gochecknoglobals
|
||||
httpMethodLatency = promauto.NewHistogramVec( //nolint: gochecknoglobals
|
||||
prometheus.HistogramOpts{
|
||||
Namespace: metricsNamespace,
|
||||
Name: "http_method_latency_seconds",
|
||||
@@ -42,7 +42,7 @@ var (
|
||||
},
|
||||
[]string{"method"},
|
||||
)
|
||||
repoStorageBytes = promauto.NewGaugeVec( // nolint: gochecknoglobals
|
||||
repoStorageBytes = promauto.NewGaugeVec( //nolint: gochecknoglobals
|
||||
prometheus.GaugeOpts{
|
||||
Namespace: metricsNamespace,
|
||||
Name: "repo_storage_bytes",
|
||||
@@ -50,7 +50,7 @@ var (
|
||||
},
|
||||
[]string{"repo"},
|
||||
)
|
||||
uploadCounter = promauto.NewCounterVec( // nolint: gochecknoglobals
|
||||
uploadCounter = promauto.NewCounterVec( //nolint: gochecknoglobals
|
||||
prometheus.CounterOpts{
|
||||
Namespace: metricsNamespace,
|
||||
Name: "repo_uploads_total",
|
||||
@@ -58,7 +58,7 @@ var (
|
||||
},
|
||||
[]string{"repo"},
|
||||
)
|
||||
downloadCounter = promauto.NewCounterVec( // nolint: gochecknoglobals
|
||||
downloadCounter = promauto.NewCounterVec( //nolint: gochecknoglobals
|
||||
prometheus.CounterOpts{
|
||||
Namespace: metricsNamespace,
|
||||
Name: "repo_downloads_total",
|
||||
@@ -66,7 +66,7 @@ var (
|
||||
},
|
||||
[]string{"repo"},
|
||||
)
|
||||
serverInfo = promauto.NewGaugeVec( // nolint: gochecknoglobals
|
||||
serverInfo = promauto.NewGaugeVec( //nolint: gochecknoglobals
|
||||
prometheus.GaugeOpts{
|
||||
Namespace: metricsNamespace,
|
||||
Name: "info",
|
||||
@@ -74,7 +74,7 @@ var (
|
||||
},
|
||||
[]string{"commit", "binaryType", "goVersion", "version"},
|
||||
)
|
||||
storageLockLatency = promauto.NewHistogramVec( // nolint: gochecknoglobals
|
||||
storageLockLatency = promauto.NewHistogramVec( //nolint: gochecknoglobals
|
||||
prometheus.HistogramOpts{
|
||||
Namespace: metricsNamespace,
|
||||
Name: "storage_lock_latency_seconds",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//go:build !metrics
|
||||
// +build !metrics
|
||||
|
||||
// nolint: varnamelen,forcetypeassert
|
||||
//nolint:varnamelen,forcetypeassert
|
||||
package monitoring
|
||||
|
||||
import (
|
||||
@@ -401,7 +401,7 @@ func (ms *metricServer) HistogramObserve(hv *HistogramValue) {
|
||||
}
|
||||
}
|
||||
|
||||
// nolint: goerr113
|
||||
//nolint:goerr113
|
||||
func sanityChecks(name string, knownLabels []string, found bool, labelNames, labelValues []string) error {
|
||||
if !found {
|
||||
return fmt.Errorf("metric %s: not found", name)
|
||||
|
||||
@@ -68,7 +68,7 @@ func (mc *MetricsClient) GetMetrics() (*MetricsInfo, error) {
|
||||
}
|
||||
|
||||
func (mc *MetricsClient) makeGETRequest(url string, resultsPtr interface{}) (http.Header, error) {
|
||||
req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("metric scraping: %w", err)
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ func GetLatestTag(allTags []TagInfo) TagInfo {
|
||||
func GetRoutePrefix(name string) string {
|
||||
names := strings.SplitN(name, "/", 2) //nolint:gomnd
|
||||
|
||||
if len(names) != 2 { // nolint:gomnd
|
||||
if len(names) != 2 { //nolint:gomnd
|
||||
// it means route is of global storage e.g "centos:latest"
|
||||
if len(names) == 1 {
|
||||
return "/"
|
||||
@@ -146,9 +146,12 @@ type ImageAnnotations struct {
|
||||
Vendor string
|
||||
}
|
||||
|
||||
/* OCI annotation/label with backwards compatibility
|
||||
/*
|
||||
OCI annotation/label with backwards compatibility
|
||||
|
||||
arg can be either lables or annotations
|
||||
https://github.com/opencontainers/image-spec/blob/main/annotations.md.*/
|
||||
https://github.com/opencontainers/image-spec/blob/main/annotations.md.
|
||||
*/
|
||||
func GetAnnotationValue(annotations map[string]string, annotationKey, labelKey string) string {
|
||||
value, ok := annotations[annotationKey]
|
||||
if !ok || value == "" {
|
||||
|
||||
@@ -50,7 +50,7 @@ var (
|
||||
ErrPutManifest = errors.New("can't put manifest")
|
||||
)
|
||||
|
||||
// nolint:gochecknoglobals
|
||||
//nolint:gochecknoglobals
|
||||
var (
|
||||
rootDir string
|
||||
subRootDir string
|
||||
@@ -111,7 +111,7 @@ type ImageSummaryResult struct {
|
||||
Errors []ErrorGQL `json:"errors"`
|
||||
}
|
||||
|
||||
func testSetup(t *testing.T, subpath string) error {
|
||||
func testSetup(t *testing.T, subpath string) error { //nolint:unparam
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
|
||||
@@ -738,7 +738,7 @@ func TestExpandedRepoInfo(t *testing.T) {
|
||||
err = os.WriteFile(indexPath, buf, 0o600)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
query := "{ExpandedRepoInfo(repo:\"test1\"){Summary%20{Name%20LastUpdated%20Size%20Platforms%20{Os%20Arch}%20Vendors%20Score}%20Images%20{Digest%20IsSigned%20Tag%20Layers%20{Size%20Digest}}}}" // nolint: lll
|
||||
query := "{ExpandedRepoInfo(repo:\"test1\"){Summary%20{Name%20LastUpdated%20Size%20Platforms%20{Os%20Arch}%20Vendors%20Score}%20Images%20{Digest%20IsSigned%20Tag%20Layers%20{Size%20Digest}}}}" //nolint: lll
|
||||
|
||||
resp, err := resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + query)
|
||||
So(resp, ShouldNotBeNil)
|
||||
@@ -808,7 +808,7 @@ func TestExpandedRepoInfo(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 422)
|
||||
|
||||
query := "{ExpandedRepoInfo(repo:\"zot-cve-test\"){Summary%20{Name%20LastUpdated%20Size%20Platforms%20{Os%20Arch}%20Vendors%20Score}}}" // nolint: lll
|
||||
query := "{ExpandedRepoInfo(repo:\"zot-cve-test\"){Summary%20{Name%20LastUpdated%20Size%20Platforms%20{Os%20Arch}%20Vendors%20Score}}}" //nolint: lll
|
||||
|
||||
resp, err = resty.R().Get(baseURL + graphqlQueryPrefix + "?query=" + query)
|
||||
So(resp, ShouldNotBeNil)
|
||||
@@ -1372,7 +1372,7 @@ func TestDerivedImageList(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// nolint:dupl
|
||||
//nolint:dupl
|
||||
func TestDerivedImageListNoRepos(t *testing.T) {
|
||||
Convey("No repositories found", t, func() {
|
||||
port := GetFreePort()
|
||||
@@ -1887,7 +1887,7 @@ func TestBaseImageList(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// nolint:dupl
|
||||
//nolint:dupl
|
||||
func TestBaseImageListNoRepos(t *testing.T) {
|
||||
Convey("No repositories found", t, func() {
|
||||
port := GetFreePort()
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
)
|
||||
|
||||
type OciLayoutUtils interface {
|
||||
type OciLayoutUtils interface { //nolint: interfacebloat
|
||||
GetImageManifest(repo string, reference string) (ispec.Manifest, string, error)
|
||||
GetImageManifests(image string) ([]ispec.Descriptor, error)
|
||||
GetImageBlobManifest(imageDir string, digest godigest.Digest) (v1.Manifest, error)
|
||||
@@ -117,7 +117,6 @@ func (olu BaseOciLayoutUtils) GetImageManifests(image string) ([]ispec.Descripto
|
||||
return index.Manifests, nil
|
||||
}
|
||||
|
||||
//nolint: interfacer
|
||||
func (olu BaseOciLayoutUtils) GetImageBlobManifest(imageDir string, digest godigest.Digest) (v1.Manifest, error) {
|
||||
var blobIndex v1.Manifest
|
||||
|
||||
@@ -139,7 +138,6 @@ func (olu BaseOciLayoutUtils) GetImageBlobManifest(imageDir string, digest godig
|
||||
return blobIndex, nil
|
||||
}
|
||||
|
||||
//nolint: interfacer
|
||||
func (olu BaseOciLayoutUtils) GetImageInfo(imageDir string, hash v1.Hash) (ispec.Image, error) {
|
||||
var imageInfo ispec.Image
|
||||
|
||||
@@ -230,7 +228,7 @@ func (olu BaseOciLayoutUtils) checkCosignSignature(name string, digest godigest.
|
||||
// new manifest is tagged as sha256-<manifest-digest>.sig.
|
||||
reference := fmt.Sprintf("sha256-%s.sig", digest.Encoded())
|
||||
|
||||
_, _, _, err := imageStore.GetImageManifest(name, reference) // nolint: dogsled
|
||||
_, _, _, err := imageStore.GetImageManifest(name, reference) //nolint: dogsled
|
||||
if err != nil {
|
||||
olu.Log.Info().Err(err).Str("repo", name).Str("digest",
|
||||
digest.String()).Msg("invalid cosign signature")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//go:build search
|
||||
// +build search
|
||||
|
||||
// nolint:lll,gosimple
|
||||
//nolint:lll,gosimple
|
||||
package cveinfo_test
|
||||
|
||||
import (
|
||||
@@ -37,7 +37,7 @@ import (
|
||||
"zotregistry.io/zot/pkg/test/mocks"
|
||||
)
|
||||
|
||||
// nolint:gochecknoglobals
|
||||
//nolint:gochecknoglobals
|
||||
var (
|
||||
cve cveinfo.CveInfo
|
||||
dbDir string
|
||||
@@ -109,7 +109,7 @@ func testSetup() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func generateTestData() error { // nolint: gocyclo
|
||||
func generateTestData() error { //nolint: gocyclo
|
||||
// Image dir with no files
|
||||
err := os.Mkdir(path.Join(dbDir, "zot-noindex-test"), 0o755)
|
||||
if err != nil {
|
||||
|
||||
@@ -192,7 +192,7 @@ func (scanner Scanner) ScanImage(image string) (map[string]cvemodel.CVE, error)
|
||||
report, err := artifact.TrivyImageRun(tCtx.Ctx)
|
||||
scanner.dbLock.Unlock()
|
||||
|
||||
if err != nil { // nolint: wsl
|
||||
if err != nil { //nolint: wsl
|
||||
scanner.log.Error().Err(err).Str("image", image).Msg("unable to scan image")
|
||||
|
||||
return cveidMap, err
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//go:build search
|
||||
// +build search
|
||||
|
||||
// nolint: gochecknoinits
|
||||
//nolint:gochecknoinits
|
||||
package digestinfo_test
|
||||
|
||||
import (
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
. "zotregistry.io/zot/pkg/test"
|
||||
)
|
||||
|
||||
// nolint:gochecknoglobals
|
||||
//nolint:gochecknoglobals
|
||||
var (
|
||||
digestInfo *digestinfo.DigestInfo
|
||||
rootDir string
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/99designs/gqlgen/graphql"
|
||||
glob "github.com/bmatcuk/doublestar/v4" // nolint:gci
|
||||
v1 "github.com/google/go-containerregistry/pkg/v1" // nolint:gci
|
||||
glob "github.com/bmatcuk/doublestar/v4" //nolint:gci
|
||||
v1 "github.com/google/go-containerregistry/pkg/v1" //nolint:gci
|
||||
godigest "github.com/opencontainers/go-digest"
|
||||
ispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/vektah/gqlparser/v2/gqlerror"
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
cveinfo "zotregistry.io/zot/pkg/extensions/search/cve"
|
||||
digestinfo "zotregistry.io/zot/pkg/extensions/search/digest"
|
||||
"zotregistry.io/zot/pkg/extensions/search/gql_generated"
|
||||
"zotregistry.io/zot/pkg/log" // nolint: gci
|
||||
"zotregistry.io/zot/pkg/log" //nolint: gci
|
||||
localCtx "zotregistry.io/zot/pkg/requestcontext"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
) // THIS CODE IS A STARTING POINT ONLY. IT WILL NOT BE UPDATED WITH SCHEMA CHANGES.
|
||||
@@ -88,7 +88,7 @@ func repoListWithNewestImage(
|
||||
olu common.OciLayoutUtils,
|
||||
cveInfo cveinfo.CveInfo,
|
||||
log log.Logger,
|
||||
) ([]*gql_generated.RepoSummary, error) {
|
||||
) ([]*gql_generated.RepoSummary, error) { //nolint:unparam
|
||||
reposSummary := []*gql_generated.RepoSummary{}
|
||||
|
||||
for _, repo := range repoList {
|
||||
@@ -473,8 +473,10 @@ func globalSearch(repoList []string, name, tag string, olu common.OciLayoutUtils
|
||||
// The distance represents the score of the match.
|
||||
//
|
||||
// Example:
|
||||
// query: image
|
||||
// repos: repo/test/myimage
|
||||
//
|
||||
// query: image
|
||||
// repos: repo/test/myimage
|
||||
//
|
||||
// Score will be 2.
|
||||
func calculateImageMatchingScore(artefactName string, index int, matchesTag bool) int {
|
||||
score := 0
|
||||
|
||||
@@ -64,7 +64,7 @@ func (r *queryResolver) ImageListForCve(ctx context.Context, id string) ([]*gql_
|
||||
|
||||
r.log.Info().Msg("extracting repositories")
|
||||
repoList, err := olu.GetRepositories()
|
||||
if err != nil { // nolint: wsl
|
||||
if err != nil { //nolint: wsl
|
||||
r.log.Error().Err(err).Msg("unable to search repositories")
|
||||
|
||||
return affectedImages, err
|
||||
|
||||
@@ -30,7 +30,7 @@ type syncContextUtils struct {
|
||||
copyOptions copy.Options
|
||||
}
|
||||
|
||||
// nolint: gochecknoglobals
|
||||
//nolint:gochecknoglobals
|
||||
var demandedImgs demandedImages
|
||||
|
||||
type demandedImages struct {
|
||||
|
||||
@@ -295,7 +295,7 @@ func getUpstreamContext(regCfg *RegistryConfig, credentials Credentials) *types.
|
||||
return upstreamCtx
|
||||
}
|
||||
|
||||
// nolint:gocyclo // offloading some of the functionalities from here would make the code harder to follow
|
||||
//nolint:gocyclo // offloading some of the functionalities from here would make the code harder to follow
|
||||
func syncRegistry(ctx context.Context, regCfg RegistryConfig,
|
||||
upstreamURL string,
|
||||
storeController storage.StoreController, localCtx *types.SystemContext,
|
||||
|
||||
@@ -249,7 +249,7 @@ func getHTTPClient(regCfg *RegistryConfig, upstreamURL string, credentials Crede
|
||||
client.SetCertificates(cert)
|
||||
}
|
||||
|
||||
// nolint: gosec
|
||||
//nolint: gosec
|
||||
if regCfg.TLSVerify != nil && !*regCfg.TLSVerify && registryURL.Scheme == "https" {
|
||||
client.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user