mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 04:48:26 +08:00
lint: upgrade golangci-lint
Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
This commit is contained in:
committed by
Ravi Chamarthy
parent
5f04092e71
commit
ac3801ea2d
@@ -56,8 +56,8 @@ func GetRootDir(image string, storeController storage.StoreController) string {
|
||||
|
||||
func GetRepo(image string) string {
|
||||
if strings.Contains(image, ":") {
|
||||
splitString := strings.SplitN(image, ":", 2)
|
||||
if len(splitString) != 2 { //nolint: gomnd
|
||||
splitString := strings.SplitN(image, ":", 2) //nolint:gomnd
|
||||
if len(splitString) != 2 { //nolint:gomnd
|
||||
return image
|
||||
}
|
||||
|
||||
@@ -100,9 +100,9 @@ func GetLatestTag(allTags []TagInfo) TagInfo {
|
||||
}
|
||||
|
||||
func GetRoutePrefix(name string) string {
|
||||
names := strings.SplitN(name, "/", 2)
|
||||
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 "/"
|
||||
|
||||
@@ -36,6 +36,7 @@ type ImgResponsWithLatestTag struct {
|
||||
Errors []ErrorGQL `json:"errors"`
|
||||
}
|
||||
|
||||
//nolint:tagliatelle // graphQL schema
|
||||
type ImgListWithLatestTag struct {
|
||||
Images []ImageInfo `json:"ImageListWithLatestTag"`
|
||||
}
|
||||
@@ -87,18 +88,26 @@ func testSetup() error {
|
||||
func getTags() ([]common.TagInfo, []common.TagInfo) {
|
||||
tags := make([]common.TagInfo, 0)
|
||||
|
||||
firstTag := common.TagInfo{Name: "1.0.0",
|
||||
firstTag := common.TagInfo{
|
||||
Name: "1.0.0",
|
||||
Digest: "sha256:eca04f027f414362596f2632746d8a178362170b9ac9af772011fedcc3877ebb",
|
||||
Timestamp: time.Now()}
|
||||
secondTag := common.TagInfo{Name: "1.0.1",
|
||||
Timestamp: time.Now(),
|
||||
}
|
||||
secondTag := common.TagInfo{
|
||||
Name: "1.0.1",
|
||||
Digest: "sha256:eca04f027f414362596f2632746d8a179362170b9ac9af772011fedcc3877ebb",
|
||||
Timestamp: time.Now()}
|
||||
thirdTag := common.TagInfo{Name: "1.0.2",
|
||||
Timestamp: time.Now(),
|
||||
}
|
||||
thirdTag := common.TagInfo{
|
||||
Name: "1.0.2",
|
||||
Digest: "sha256:eca04f027f414362596f2632746d8a170362170b9ac9af772011fedcc3877ebb",
|
||||
Timestamp: time.Now()}
|
||||
fourthTag := common.TagInfo{Name: "1.0.3",
|
||||
Timestamp: time.Now(),
|
||||
}
|
||||
fourthTag := common.TagInfo{
|
||||
Name: "1.0.3",
|
||||
Digest: "sha256:eca04f027f414362596f2632746d8a171362170b9ac9af772011fedcc3877ebb",
|
||||
Timestamp: time.Now()}
|
||||
Timestamp: time.Now(),
|
||||
}
|
||||
|
||||
tags = append(tags, firstTag, secondTag, thirdTag, fourthTag)
|
||||
|
||||
@@ -183,11 +192,11 @@ func TestLatestTagSearchHTTP(t *testing.T) {
|
||||
|
||||
conf.Extensions.Search.CVE = nil
|
||||
|
||||
c := api.NewController(conf)
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
go func() {
|
||||
// this blocks
|
||||
if err := c.Run(); err != nil {
|
||||
if err := ctlr.Run(); err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
@@ -204,7 +213,7 @@ func TestLatestTagSearchHTTP(t *testing.T) {
|
||||
// shut down server
|
||||
defer func() {
|
||||
ctx := context.Background()
|
||||
_ = c.Server.Shutdown(ctx)
|
||||
_ = ctlr.Server.Shutdown(ctx)
|
||||
}()
|
||||
|
||||
resp, err := resty.R().Get(baseURL + "/v2/")
|
||||
@@ -234,7 +243,7 @@ func TestLatestTagSearchHTTP(t *testing.T) {
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = os.Chmod(rootDir, 0000)
|
||||
err = os.Chmod(rootDir, 0o000)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -248,7 +257,7 @@ func TestLatestTagSearchHTTP(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(len(responseStruct.ImgListWithLatestTag.Images), ShouldEqual, 0)
|
||||
|
||||
err = os.Chmod(rootDir, 0755)
|
||||
err = os.Chmod(rootDir, 0o755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -3,12 +3,11 @@ package common
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
goerrors "errors"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
goerrors "errors"
|
||||
|
||||
v1 "github.com/google/go-containerregistry/pkg/v1"
|
||||
"github.com/google/go-containerregistry/pkg/v1/types"
|
||||
godigest "github.com/opencontainers/go-digest"
|
||||
@@ -32,8 +31,8 @@ func NewOciLayoutUtils(storeController storage.StoreController, log log.Logger)
|
||||
// Below method will return image path including root dir, root dir is determined by splitting.
|
||||
func (olu OciLayoutUtils) GetImageManifests(image string) ([]ispec.Descriptor, error) {
|
||||
imageStore := olu.StoreController.GetImageStore(image)
|
||||
buf, err := imageStore.GetIndexContent(image)
|
||||
|
||||
buf, err := imageStore.GetIndexContent(image)
|
||||
if err != nil {
|
||||
if goerrors.Is(errors.ErrRepoNotFound, err) {
|
||||
olu.Log.Error().Err(err).Msg("index.json doesn't exist")
|
||||
@@ -50,6 +49,7 @@ func (olu OciLayoutUtils) GetImageManifests(image string) ([]ispec.Descriptor, e
|
||||
|
||||
if err := json.Unmarshal(buf, &index); err != nil {
|
||||
olu.Log.Error().Err(err).Str("dir", path.Join(imageStore.RootDir(), image)).Msg("invalid JSON")
|
||||
|
||||
return nil, errors.ErrRepoNotFound
|
||||
}
|
||||
|
||||
@@ -108,14 +108,14 @@ func (olu OciLayoutUtils) IsValidImageFormat(image string) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, m := range manifests {
|
||||
tag, ok := m.Annotations[ispec.AnnotationRefName]
|
||||
for _, manifest := range manifests {
|
||||
tag, ok := manifest.Annotations[ispec.AnnotationRefName]
|
||||
|
||||
if ok && inputTag != "" && tag != inputTag {
|
||||
continue
|
||||
}
|
||||
|
||||
blobManifest, err := olu.GetImageBlobManifest(imageDir, m.Digest)
|
||||
blobManifest, err := olu.GetImageBlobManifest(imageDir, manifest.Digest)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -129,6 +129,7 @@ func (olu OciLayoutUtils) IsValidImageFormat(image string) (bool, error) {
|
||||
|
||||
default:
|
||||
olu.Log.Debug().Msg("image media type not supported for scanning")
|
||||
|
||||
return false, errors.ErrScanNotSupported
|
||||
}
|
||||
}
|
||||
@@ -151,7 +152,7 @@ func (olu OciLayoutUtils) GetImageTagsWithTimestamp(repo string) ([]TagInfo, err
|
||||
for _, manifest := range manifests {
|
||||
digest := manifest.Digest
|
||||
|
||||
v, ok := manifest.Annotations[ispec.AnnotationRefName]
|
||||
val, ok := manifest.Annotations[ispec.AnnotationRefName]
|
||||
if ok {
|
||||
imageBlobManifest, err := olu.GetImageBlobManifest(repo, digest)
|
||||
if err != nil {
|
||||
@@ -175,7 +176,7 @@ func (olu OciLayoutUtils) GetImageTagsWithTimestamp(repo string) ([]TagInfo, err
|
||||
timeStamp = time.Time{}
|
||||
}
|
||||
|
||||
tagsInfo = append(tagsInfo, TagInfo{Name: v, Timestamp: timeStamp, Digest: digest.String()})
|
||||
tagsInfo = append(tagsInfo, TagInfo{Name: val, Timestamp: timeStamp, Digest: digest.String()})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func getRoutePrefix(name string) string {
|
||||
names := strings.SplitN(name, "/", 2)
|
||||
names := strings.SplitN(name, "/", 2) //nolint:gomnd
|
||||
|
||||
if len(names) != 2 { // nolint: gomnd
|
||||
// it means route is of global storage e.g "centos:latest"
|
||||
@@ -104,8 +104,10 @@ func GetCVEInfo(storeController storage.StoreController, log log.Logger) (*CveIn
|
||||
|
||||
cveController.SubCveConfig = subCveConfig
|
||||
|
||||
return &CveInfo{Log: log, CveTrivyController: cveController, StoreController: storeController,
|
||||
LayoutUtils: layoutUtils}, nil
|
||||
return &CveInfo{
|
||||
Log: log, CveTrivyController: cveController, StoreController: storeController,
|
||||
LayoutUtils: layoutUtils,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (cveinfo CveInfo) GetTrivyContext(image string) *TrivyCtx {
|
||||
@@ -137,7 +139,7 @@ func (cveinfo CveInfo) GetTrivyContext(image string) *TrivyCtx {
|
||||
return trivyCtx
|
||||
}
|
||||
|
||||
func (cveinfo CveInfo) GetImageListForCVE(repo string, id string, imgStore storage.ImageStore,
|
||||
func (cveinfo CveInfo) GetImageListForCVE(repo string, cvid string, imgStore storage.ImageStore,
|
||||
trivyCtx *TrivyCtx) ([]*string, error) {
|
||||
tags := make([]*string, 0)
|
||||
|
||||
@@ -173,7 +175,7 @@ func (cveinfo CveInfo) GetImageListForCVE(repo string, id string, imgStore stora
|
||||
|
||||
for _, result := range report.Results {
|
||||
for _, vulnerability := range result.Vulnerabilities {
|
||||
if vulnerability.VulnerabilityID == id {
|
||||
if vulnerability.VulnerabilityID == cvid {
|
||||
copyImgTag := tag
|
||||
tags = append(tags, ©ImgTag)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//go:build extended
|
||||
// +build extended
|
||||
|
||||
// nolint: lll
|
||||
// nolint:lll,gosimple
|
||||
package cveinfo_test
|
||||
|
||||
import (
|
||||
@@ -48,10 +48,12 @@ type ImgWithFixedCVE struct {
|
||||
ImgResults ImgResults `json:"data"`
|
||||
}
|
||||
|
||||
//nolint:tagliatelle // graphQL schema
|
||||
type ImgResults struct {
|
||||
ImgResultForFixedCVE ImgResultForFixedCVE `json:"ImgResultForFixedCVE"`
|
||||
}
|
||||
|
||||
//nolint:tagliatelle // graphQL schema
|
||||
type ImgResultForFixedCVE struct {
|
||||
Tags []TagInfo `json:"Tags"`
|
||||
}
|
||||
@@ -61,15 +63,18 @@ type TagInfo struct {
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
//nolint:tagliatelle // graphQL schema
|
||||
type ImgList struct {
|
||||
CVEResultForImage CVEResultForImage `json:"CVEListForImage"`
|
||||
}
|
||||
|
||||
//nolint:tagliatelle // graphQL schema
|
||||
type CVEResultForImage struct {
|
||||
Tag string `json:"Tag"`
|
||||
CVEList []CVE `json:"CVEList"`
|
||||
}
|
||||
|
||||
//nolint:tagliatelle // graphQL schema
|
||||
type CVE struct {
|
||||
ID string `json:"Id"`
|
||||
Description string `json:"Description"`
|
||||
@@ -108,12 +113,12 @@ func testSetup() error {
|
||||
|
||||
func generateTestData() error { // nolint: gocyclo
|
||||
// Image dir with no files
|
||||
err := os.Mkdir(path.Join(dbDir, "zot-noindex-test"), 0755)
|
||||
err := os.Mkdir(path.Join(dbDir, "zot-noindex-test"), 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.Mkdir(path.Join(dbDir, "zot-nonreadable-test"), 0755)
|
||||
err = os.Mkdir(path.Join(dbDir, "zot-nonreadable-test"), 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -126,17 +131,17 @@ func generateTestData() error { // nolint: gocyclo
|
||||
return err
|
||||
}
|
||||
|
||||
if err = ioutil.WriteFile(path.Join(dbDir, "zot-nonreadable-test", "index.json"), buf, 0111); err != nil {
|
||||
if err = ioutil.WriteFile(path.Join(dbDir, "zot-nonreadable-test", "index.json"), buf, 0o111); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Image dir with invalid index.json
|
||||
err = os.Mkdir(path.Join(dbDir, "zot-squashfs-invalid-index"), 0755)
|
||||
err = os.Mkdir(path.Join(dbDir, "zot-squashfs-invalid-index"), 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
content := fmt.Sprintf(`{"schemaVersion": 2,"manifests"[{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:2a9b097b4e4c613dd8185eba55163201a221909f3d430f8df87cd3639afc5929","size": 1240,"annotations": {"org.opencontainers.image.ref.name": "commit-aaa7c6e7-squashfs"},"platform": {"architecture": "amd64","os": "linux"}}]}`)
|
||||
content := `{"schemaVersion": 2,"manifests"[{"mediaType": "application/vnd.oci.image.manifest.v1+json","digest": "sha256:2a9b097b4e4c613dd8185eba55163201a221909f3d430f8df87cd3639afc5929","size": 1240,"annotations": {"org.opencontainers.image.ref.name": "commit-aaa7c6e7-squashfs"},"platform": {"architecture": "amd64","os": "linux"}}]}`
|
||||
|
||||
err = makeTestFile(path.Join(dbDir, "zot-squashfs-invalid-index", "index.json"), content)
|
||||
if err != nil {
|
||||
@@ -144,13 +149,12 @@ func generateTestData() error { // nolint: gocyclo
|
||||
}
|
||||
|
||||
// Image dir with no blobs
|
||||
err = os.Mkdir(path.Join(dbDir, "zot-squashfs-noblobs"), 0755)
|
||||
err = os.Mkdir(path.Join(dbDir, "zot-squashfs-noblobs"), 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
content = fmt.Sprintf(`{"schemaVersion":2,"manifests":[{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:2a9b097b4e4c613dd8185eba55163201a221909f3d430f8df87cd3639afc5929","size":1240,"annotations":{"org.opencontainers.image.ref.name":"commit-aaa7c6e7-squashfs"},"platform":{"architecture":"amd64","os":"linux"}}]}
|
||||
`)
|
||||
content = `{"schemaVersion":2,"manifests":[{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:2a9b097b4e4c613dd8185eba55163201a221909f3d430f8df87cd3639afc5929","size":1240,"annotations":{"org.opencontainers.image.ref.name":"commit-aaa7c6e7-squashfs"},"platform":{"architecture":"amd64","os":"linux"}}]}`
|
||||
|
||||
err = makeTestFile(path.Join(dbDir, "zot-squashfs-noblobs", "index.json"), content)
|
||||
if err != nil {
|
||||
@@ -158,7 +162,7 @@ func generateTestData() error { // nolint: gocyclo
|
||||
}
|
||||
|
||||
// Image dir with invalid blob
|
||||
err = os.MkdirAll(path.Join(dbDir, "zot-squashfs-invalid-blob", "blobs/sha256"), 0755)
|
||||
err = os.MkdirAll(path.Join(dbDir, "zot-squashfs-invalid-blob", "blobs/sha256"), 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -181,7 +185,7 @@ func generateTestData() error { // nolint: gocyclo
|
||||
|
||||
// Create a squashfs image
|
||||
|
||||
err = os.MkdirAll(path.Join(dbDir, "zot-squashfs-test", "blobs/sha256"), 0755)
|
||||
err = os.MkdirAll(path.Join(dbDir, "zot-squashfs-test", "blobs/sha256"), 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -193,11 +197,11 @@ func generateTestData() error { // nolint: gocyclo
|
||||
return err
|
||||
}
|
||||
|
||||
if err = ioutil.WriteFile(path.Join(dbDir, "zot-squashfs-test", "oci-layout"), buf, 0644); err != nil { //nolint: gosec
|
||||
if err = ioutil.WriteFile(path.Join(dbDir, "zot-squashfs-test", "oci-layout"), buf, 0o644); err != nil { //nolint: gosec
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.Mkdir(path.Join(dbDir, "zot-squashfs-test", ".uploads"), 0755)
|
||||
err = os.Mkdir(path.Join(dbDir, "zot-squashfs-test", ".uploads"), 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -253,7 +257,7 @@ func generateTestData() error { // nolint: gocyclo
|
||||
|
||||
// Create a image with invalid layer blob
|
||||
|
||||
err = os.MkdirAll(path.Join(dbDir, "zot-invalid-layer", "blobs/sha256"), 0755)
|
||||
err = os.MkdirAll(path.Join(dbDir, "zot-invalid-layer", "blobs/sha256"), 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -281,7 +285,7 @@ func generateTestData() error { // nolint: gocyclo
|
||||
|
||||
// Create a image with no layer blob
|
||||
|
||||
err = os.MkdirAll(path.Join(dbDir, "zot-no-layer", "blobs/sha256"), 0755)
|
||||
err = os.MkdirAll(path.Join(dbDir, "zot-no-layer", "blobs/sha256"), 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -311,7 +315,7 @@ func generateTestData() error { // nolint: gocyclo
|
||||
}
|
||||
|
||||
func makeTestFile(fileName string, content string) error {
|
||||
if err := ioutil.WriteFile(fileName, []byte(content), 0600); err != nil {
|
||||
if err := ioutil.WriteFile(fileName, []byte(content), 0o600); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -390,8 +394,9 @@ func TestCVESearch(t *testing.T) {
|
||||
Path: htpasswdPath,
|
||||
},
|
||||
}
|
||||
c := api.NewController(conf)
|
||||
c.Config.Storage.RootDirectory = dbDir
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Config.Storage.RootDirectory = dbDir
|
||||
cveConfig := &extconf.CVEConfig{
|
||||
UpdateInterval: updateDuration,
|
||||
}
|
||||
@@ -399,12 +404,12 @@ func TestCVESearch(t *testing.T) {
|
||||
CVE: cveConfig,
|
||||
Enable: true,
|
||||
}
|
||||
c.Config.Extensions = &extconf.ExtensionConfig{
|
||||
ctlr.Config.Extensions = &extconf.ExtensionConfig{
|
||||
Search: searchConfig,
|
||||
}
|
||||
go func() {
|
||||
// this blocks
|
||||
if err := c.Run(); err != nil {
|
||||
if err := ctlr.Run(); err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
@@ -423,7 +428,7 @@ func TestCVESearch(t *testing.T) {
|
||||
|
||||
defer func() {
|
||||
ctx := context.Background()
|
||||
_ = c.Server.Shutdown(ctx)
|
||||
_ = ctlr.Server.Shutdown(ctx)
|
||||
}()
|
||||
|
||||
// without creds, should get access error
|
||||
@@ -464,9 +469,9 @@ func TestCVESearch(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(len(cveResult.ImgList.CVEResultForImage.CVEList), ShouldNotBeZeroValue)
|
||||
|
||||
id := cveResult.ImgList.CVEResultForImage.CVEList[0].ID
|
||||
cvid := cveResult.ImgList.CVEResultForImage.CVEList[0].ID
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + id + "\",image:\"zot-test\"){Tags{Name%20Timestamp}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + cvid + "\",image:\"zot-test\"){Tags{Name%20Timestamp}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
@@ -475,7 +480,7 @@ func TestCVESearch(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(len(imgFixedCVEResult.ImgResults.ImgResultForFixedCVE.Tags), ShouldEqual, 0)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + id + "\",image:\"zot-cve-test\"){Tags{Name%20Timestamp}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + cvid + "\",image:\"zot-cve-test\"){Tags{Name%20Timestamp}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
@@ -483,7 +488,7 @@ func TestCVESearch(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(len(imgFixedCVEResult.ImgResults.ImgResultForFixedCVE.Tags), ShouldEqual, 0)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + id + "\",image:\"zot-test\"){Tags{Name%20Timestamp}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + cvid + "\",image:\"zot-test\"){Tags{Name%20Timestamp}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
@@ -500,7 +505,7 @@ func TestCVESearch(t *testing.T) {
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + id + "\",image:\"zot-squashfs-noindex\"){Tags{Name%20Timestamp}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + cvid + "\",image:\"zot-squashfs-noindex\"){Tags{Name%20Timestamp}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
@@ -508,7 +513,7 @@ func TestCVESearch(t *testing.T) {
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + id + "\",image:\"zot-squashfs-invalid-index\"){Tags{Name%20Timestamp}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + cvid + "\",image:\"zot-squashfs-invalid-index\"){Tags{Name%20Timestamp}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
@@ -516,11 +521,11 @@ func TestCVESearch(t *testing.T) {
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + id + "\",image:\"zot-squashfs-noblob\"){Tags{Name%20Timestamp}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + cvid + "\",image:\"zot-squashfs-noblob\"){Tags{Name%20Timestamp}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + id + "\",image:\"zot-squashfs-test\"){Tags{Name%20Timestamp}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + cvid + "\",image:\"zot-squashfs-test\"){Tags{Name%20Timestamp}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
@@ -528,7 +533,7 @@ func TestCVESearch(t *testing.T) {
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + id + "\",image:\"zot-squashfs-invalid-blob\"){Tags{Name%20Timestamp}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListWithCVEFixed(id:\"" + cvid + "\",image:\"zot-squashfs-invalid-blob\"){Tags{Name%20Timestamp}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
@@ -597,7 +602,7 @@ func TestCVESearch(t *testing.T) {
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 422)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListForCVE(id:\"" + id + "\"){Name%20Tags}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/query?query={ImageListForCVE(id:\"" + cvid + "\"){Name%20Tags}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
})
|
||||
@@ -617,7 +622,9 @@ func TestCVEConfig(t *testing.T) {
|
||||
Path: htpasswdPath,
|
||||
},
|
||||
}
|
||||
c := api.NewController(conf)
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
firstDir, err := ioutil.TempDir("", "oci-repo-test")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -635,16 +642,17 @@ func TestCVEConfig(t *testing.T) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
c.Config.Storage.RootDirectory = firstDir
|
||||
ctlr.Config.Storage.RootDirectory = firstDir
|
||||
subPaths := make(map[string]config.StorageConfig)
|
||||
subPaths["/a"] = config.StorageConfig{
|
||||
RootDirectory: secondDir,
|
||||
}
|
||||
c.Config.Storage.SubPaths = subPaths
|
||||
|
||||
ctlr.Config.Storage.SubPaths = subPaths
|
||||
|
||||
go func() {
|
||||
// this blocks
|
||||
if err := c.Run(); err != nil {
|
||||
if err := ctlr.Run(); err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
@@ -676,7 +684,7 @@ func TestCVEConfig(t *testing.T) {
|
||||
|
||||
defer func() {
|
||||
ctx := context.Background()
|
||||
_ = c.Server.Shutdown(ctx)
|
||||
_ = ctlr.Server.Shutdown(ctx)
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ type CveTrivyController struct {
|
||||
DefaultCveConfig *TrivyCtx
|
||||
SubCveConfig map[string]*TrivyCtx
|
||||
}
|
||||
|
||||
type TrivyCtx struct {
|
||||
Input string
|
||||
Ctx *cli.Context
|
||||
|
||||
@@ -27,21 +27,21 @@ func (digestinfo DigestInfo) GetImageTagsByDigest(repo string, digest string) ([
|
||||
uniqueTags := []*string{}
|
||||
|
||||
manifests, err := digestinfo.LayoutUtils.GetImageManifests(repo)
|
||||
|
||||
if err != nil {
|
||||
digestinfo.Log.Error().Err(err).Msg("unable to read image manifests")
|
||||
|
||||
return uniqueTags, err
|
||||
}
|
||||
|
||||
for _, manifest := range manifests {
|
||||
imageDigest := manifest.Digest
|
||||
|
||||
v, ok := manifest.Annotations[ispec.AnnotationRefName]
|
||||
val, ok := manifest.Annotations[ispec.AnnotationRefName]
|
||||
if ok {
|
||||
imageBlobManifest, err := digestinfo.LayoutUtils.GetImageBlobManifest(repo, imageDigest)
|
||||
|
||||
if err != nil {
|
||||
digestinfo.Log.Error().Err(err).Msg("unable to read image blob manifest")
|
||||
|
||||
return uniqueTags, err
|
||||
}
|
||||
|
||||
@@ -50,20 +50,20 @@ func (digestinfo DigestInfo) GetImageTagsByDigest(repo string, digest string) ([
|
||||
// Check the image manigest in index.json matches the search digest
|
||||
// This is a blob with mediaType application/vnd.oci.image.manifest.v1+json
|
||||
if strings.Contains(manifest.Digest.String(), digest) {
|
||||
tags = append(tags, &v)
|
||||
tags = append(tags, &val)
|
||||
}
|
||||
|
||||
// Check the image config matches the search digest
|
||||
// This is a blob with mediaType application/vnd.oci.image.config.v1+json
|
||||
if strings.Contains(imageBlobManifest.Config.Digest.Algorithm+":"+imageBlobManifest.Config.Digest.Hex, digest) {
|
||||
tags = append(tags, &v)
|
||||
tags = append(tags, &val)
|
||||
}
|
||||
|
||||
// Check to see if the individual layers in the oci image manifest match the digest
|
||||
// These are blobs with mediaType application/vnd.oci.image.layer.v1.tar+gzip
|
||||
for _, layer := range imageBlobManifest.Layers {
|
||||
if strings.Contains(layer.Digest.Algorithm+":"+layer.Digest.Hex, digest) {
|
||||
tags = append(tags, &v)
|
||||
tags = append(tags, &val)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,12 @@ type ImgResponseForDigest struct {
|
||||
Errors []ErrorGQL `json:"errors"`
|
||||
}
|
||||
|
||||
//nolint:tagliatelle // graphQL schema
|
||||
type ImgListForDigest struct {
|
||||
Images []ImgInfo `json:"ImageListForDigest"`
|
||||
}
|
||||
|
||||
//nolint:tagliatelle // graphQL schema
|
||||
type ImgInfo struct {
|
||||
Name string `json:"Name"`
|
||||
Tags []string `json:"Tags"`
|
||||
@@ -51,8 +53,7 @@ type ErrorGQL struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
err := testSetup()
|
||||
if err != nil {
|
||||
if err := testSetup(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -79,7 +80,7 @@ func testSetup() error {
|
||||
// zot-cve-test 0.0.1 63a795ca 8dd57e17 75MB
|
||||
// 7a0437f0 75MB
|
||||
|
||||
err = os.Mkdir(subDir+"/a", 0700)
|
||||
err = os.Mkdir(subDir+"/a", 0o700)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -146,11 +147,11 @@ func TestDigestSearchHTTP(t *testing.T) {
|
||||
Search: &extconf.SearchConfig{Enable: true},
|
||||
}
|
||||
|
||||
c := api.NewController(conf)
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
go func() {
|
||||
// this blocks
|
||||
if err := c.Run(); err != nil {
|
||||
if err := ctlr.Run(); err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
@@ -167,7 +168,7 @@ func TestDigestSearchHTTP(t *testing.T) {
|
||||
// shut down server
|
||||
defer func() {
|
||||
ctx := context.Background()
|
||||
_ = c.Server.Shutdown(ctx)
|
||||
_ = ctlr.Server.Shutdown(ctx)
|
||||
}()
|
||||
|
||||
resp, err := resty.R().Get(baseURL + "/v2/")
|
||||
@@ -273,7 +274,7 @@ func TestDigestSearchHTTPSubPaths(t *testing.T) {
|
||||
Search: &extconf.SearchConfig{Enable: true},
|
||||
}
|
||||
|
||||
c := api.NewController(conf)
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
globalDir, err := ioutil.TempDir("", "digest_test")
|
||||
if err != nil {
|
||||
@@ -281,17 +282,17 @@ func TestDigestSearchHTTPSubPaths(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(globalDir)
|
||||
|
||||
c.Config.Storage.RootDirectory = globalDir
|
||||
ctlr.Config.Storage.RootDirectory = globalDir
|
||||
|
||||
subPathMap := make(map[string]config.StorageConfig)
|
||||
|
||||
subPathMap["/a"] = config.StorageConfig{RootDirectory: subRootDir}
|
||||
|
||||
c.Config.Storage.SubPaths = subPathMap
|
||||
ctlr.Config.Storage.SubPaths = subPathMap
|
||||
|
||||
go func() {
|
||||
// this blocks
|
||||
if err := c.Run(); err != nil {
|
||||
if err := ctlr.Run(); err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
@@ -308,7 +309,7 @@ func TestDigestSearchHTTPSubPaths(t *testing.T) {
|
||||
// shut down server
|
||||
defer func() {
|
||||
ctx := context.Background()
|
||||
_ = c.Server.Shutdown(ctx)
|
||||
_ = ctlr.Server.Shutdown(ctx)
|
||||
}()
|
||||
|
||||
resp, err := resty.R().Get(baseURL + "/v2/")
|
||||
@@ -347,11 +348,11 @@ func TestDigestSearchDisabled(t *testing.T) {
|
||||
Search: &extconf.SearchConfig{Enable: false},
|
||||
}
|
||||
|
||||
c := api.NewController(conf)
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
go func() {
|
||||
// this blocks
|
||||
if err := c.Run(); err != nil {
|
||||
if err := ctlr.Run(); err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
@@ -368,7 +369,7 @@ func TestDigestSearchDisabled(t *testing.T) {
|
||||
// shut down server
|
||||
defer func() {
|
||||
ctx := context.Background()
|
||||
_ = c.Server.Shutdown(ctx)
|
||||
_ = ctlr.Server.Shutdown(ctx)
|
||||
}()
|
||||
|
||||
resp, err := resty.R().Get(baseURL + "/v2/")
|
||||
|
||||
@@ -148,7 +148,7 @@ func (r *queryResolver) CVEListForImage(ctx context.Context, image string) (*CVE
|
||||
return &CVEResultForImage{Tag: ©ImgTag, CVEList: cveids}, nil
|
||||
}
|
||||
|
||||
func (r *queryResolver) ImageListForCve(ctx context.Context, id string) ([]*ImgResultForCve, error) {
|
||||
func (r *queryResolver) ImageListForCve(ctx context.Context, cvid string) ([]*ImgResultForCve, error) {
|
||||
finalCveResult := []*ImgResultForCve{}
|
||||
|
||||
r.log.Info().Msg("extracting repositories")
|
||||
@@ -166,7 +166,7 @@ func (r *queryResolver) ImageListForCve(ctx context.Context, id string) ([]*ImgR
|
||||
|
||||
r.cveInfo.Log.Info().Msg("scanning each global repository")
|
||||
|
||||
cveResult, err := r.getImageListForCVE(repoList, id, defaultStore, defaultTrivyCtx)
|
||||
cveResult, err := r.getImageListForCVE(repoList, cvid, defaultStore, defaultTrivyCtx)
|
||||
if err != nil {
|
||||
r.log.Error().Err(err).Msg("error getting cve list for global repositories")
|
||||
|
||||
@@ -187,7 +187,7 @@ func (r *queryResolver) ImageListForCve(ctx context.Context, id string) ([]*ImgR
|
||||
|
||||
subTrivyCtx := r.cveInfo.CveTrivyController.SubCveConfig[route]
|
||||
|
||||
subCveResult, err := r.getImageListForCVE(subRepoList, id, store, subTrivyCtx)
|
||||
subCveResult, err := r.getImageListForCVE(subRepoList, cvid, store, subTrivyCtx)
|
||||
if err != nil {
|
||||
r.log.Error().Err(err).Msg("unable to get cve result for sub repositories")
|
||||
|
||||
@@ -200,7 +200,7 @@ func (r *queryResolver) ImageListForCve(ctx context.Context, id string) ([]*ImgR
|
||||
return finalCveResult, nil
|
||||
}
|
||||
|
||||
func (r *queryResolver) getImageListForCVE(repoList []string, id string, imgStore storage.ImageStore,
|
||||
func (r *queryResolver) getImageListForCVE(repoList []string, cvid string, imgStore storage.ImageStore,
|
||||
trivyCtx *cveinfo.TrivyCtx) ([]*ImgResultForCve, error) {
|
||||
cveResult := []*ImgResultForCve{}
|
||||
|
||||
@@ -209,7 +209,7 @@ func (r *queryResolver) getImageListForCVE(repoList []string, id string, imgStor
|
||||
|
||||
name := repo
|
||||
|
||||
tags, err := r.cveInfo.GetImageListForCVE(repo, id, imgStore, trivyCtx)
|
||||
tags, err := r.cveInfo.GetImageListForCVE(repo, cvid, imgStore, trivyCtx)
|
||||
if err != nil {
|
||||
r.log.Error().Err(err).Msg("error getting tag")
|
||||
|
||||
@@ -224,7 +224,7 @@ func (r *queryResolver) getImageListForCVE(repoList []string, id string, imgStor
|
||||
return cveResult, nil
|
||||
}
|
||||
|
||||
func (r *queryResolver) ImageListWithCVEFixed(ctx context.Context, id string, image string) (*ImgResultForFixedCve, error) { // nolint: lll
|
||||
func (r *queryResolver) ImageListWithCVEFixed(ctx context.Context, cvid string, image string) (*ImgResultForFixedCve, error) { // nolint: lll
|
||||
imgResultForFixedCVE := &ImgResultForFixedCve{}
|
||||
|
||||
r.log.Info().Str("image", image).Msg("extracting list of tags available in image")
|
||||
@@ -270,7 +270,7 @@ func (r *queryResolver) ImageListWithCVEFixed(ctx context.Context, id string, im
|
||||
|
||||
for _, result := range report.Results {
|
||||
for _, vulnerability := range result.Vulnerabilities {
|
||||
if vulnerability.VulnerabilityID == id {
|
||||
if vulnerability.VulnerabilityID == cvid {
|
||||
hasCVE = true
|
||||
|
||||
break
|
||||
@@ -292,7 +292,7 @@ func (r *queryResolver) ImageListWithCVEFixed(ctx context.Context, id string, im
|
||||
|
||||
finalTagList = getGraphqlCompatibleTags(fixedTags)
|
||||
} else {
|
||||
r.log.Info().Str("image", image).Str("cve-id", id).Msg("image does not contain any tag that have given cve")
|
||||
r.log.Info().Str("image", image).Str("cve-id", cvid).Msg("image does not contain any tag that have given cve")
|
||||
|
||||
finalTagList = getGraphqlCompatibleTags(tagsInfo)
|
||||
}
|
||||
@@ -302,7 +302,7 @@ func (r *queryResolver) ImageListWithCVEFixed(ctx context.Context, id string, im
|
||||
return imgResultForFixedCVE, nil
|
||||
}
|
||||
|
||||
func (r *queryResolver) ImageListForDigest(ctx context.Context, id string) ([]*ImgResultForDigest, error) {
|
||||
func (r *queryResolver) ImageListForDigest(ctx context.Context, digestID string) ([]*ImgResultForDigest, error) {
|
||||
imgResultForDigest := []*ImgResultForDigest{}
|
||||
|
||||
r.log.Info().Msg("extracting repositories")
|
||||
@@ -318,7 +318,7 @@ func (r *queryResolver) ImageListForDigest(ctx context.Context, id string) ([]*I
|
||||
|
||||
r.log.Info().Msg("scanning each global repository")
|
||||
|
||||
partialImgResultForDigest, err := r.getImageListForDigest(repoList, id)
|
||||
partialImgResultForDigest, err := r.getImageListForDigest(repoList, digestID)
|
||||
if err != nil {
|
||||
r.log.Error().Err(err).Msg("unable to get image and tag list for global repositories")
|
||||
|
||||
@@ -336,7 +336,7 @@ func (r *queryResolver) ImageListForDigest(ctx context.Context, id string) ([]*I
|
||||
return imgResultForDigest, err
|
||||
}
|
||||
|
||||
partialImgResultForDigest, err = r.getImageListForDigest(subRepoList, id)
|
||||
partialImgResultForDigest, err = r.getImageListForDigest(subRepoList, digestID)
|
||||
if err != nil {
|
||||
r.log.Error().Err(err).Msg("unable to get image and tag list for sub-repositories")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user