Skip to content

Commit

Permalink
fix: various lint issues
Browse files Browse the repository at this point in the history
Originally found by @jkroepke in: https://github.com/project-zot/zot/actions/runs/10056774230/job/27796324933?pr=2556
And #2556 in general

This commit covers:
- (canonicalheader) capitalization of Docker-Content-Digest header
- (protogetter) the proto getters were not used, they check for nil pointers, we should switch to using them
- (zerologlint) fix the false positive

Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
  • Loading branch information
andaaron committed Jul 24, 2024
1 parent a7ab16b commit bc8333a
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 159 deletions.
2 changes: 1 addition & 1 deletion pkg/api/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func SessionLogger(ctlr *Controller) mux.MiddlewareFunc {
clientIP := request.RemoteAddr
method := request.Method
headers := map[string][]string{}
log := logger.Info()
log := logger.Info() //nolint: zerologlint // false positive, the Msg call is below
for key, value := range request.Header {
if key == "Authorization" { // anonymize from logs
s := strings.SplitN(value[0], " ", 2) //nolint:gomnd
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func fetchImageIndexStruct(ctx context.Context, job *httpJob) (*imageStruct, err
return nil, err
}

indexDigest := header.Get("docker-content-digest")
indexDigest := header.Get("Docker-Content-Digest")

indexSize, err := strconv.ParseInt(header.Get("Content-Length"), 10, 64)
if err != nil {
Expand Down Expand Up @@ -398,7 +398,7 @@ func fetchManifestStruct(ctx context.Context, repo, manifestReference string, se
return common.ManifestSummary{}, err
}

manifestDigest := header.Get("docker-content-digest")
manifestDigest := header.Get("Docker-Content-Digest")
configDigest := manifestResp.Config.Digest.String()

configContent, err := fetchConfig(ctx, repo, configDigest, searchConf, username, password)
Expand Down
8 changes: 4 additions & 4 deletions pkg/cli/client/utils_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func TestDoHTTPRequest(t *testing.T) {
vars := mux.Vars(req)

if vars["reference"] == "indexRef" {
writer.Header().Add("docker-content-digest", godigest.FromString("t").String())
writer.Header().Add("Docker-Content-Digest", godigest.FromString("t").String())
_, err := writer.Write([]byte(`
{
"manifests": [
Expand Down Expand Up @@ -594,7 +594,7 @@ func TestDoJobErrors(t *testing.T) {
Route: "/v2/{name}/manifests/{reference}",
HandlerFunc: func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", ispec.MediaTypeImageIndex)
w.Header().Add("docker-content-digest", godigest.FromString("t").String())
w.Header().Add("Docker-Content-Digest", godigest.FromString("t").String())

_, err := w.Write([]byte(""))
if err != nil {
Expand All @@ -609,7 +609,7 @@ func TestDoJobErrors(t *testing.T) {
vars := mux.Vars(req)

if vars["reference"] == "indexRef" {
writer.Header().Add("docker-content-digest", godigest.FromString("t").String())
writer.Header().Add("Docker-Content-Digest", godigest.FromString("t").String())

_, err := writer.Write([]byte(`{"manifests": [{"digest": "manifestRef"}]}`))
if err != nil {
Expand All @@ -618,7 +618,7 @@ func TestDoJobErrors(t *testing.T) {
}

if vars["reference"] == "manifestRef" {
writer.Header().Add("docker-content-digest", godigest.FromString("t").String())
writer.Header().Add("Docker-Content-Digest", godigest.FromString("t").String())

_, err := writer.Write([]byte(`{"config": {"digest": "confDigest"}}`))
if err != nil {
Expand Down
Loading

0 comments on commit bc8333a

Please sign in to comment.