-
Notifications
You must be signed in to change notification settings - Fork 38
fix(cas): return 404 error if artifact does not exist #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
VERSION=$(shell git describe --tags --always) | ||
|
||
.PHONY: init | ||
# init env | ||
init: | ||
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30.0 | ||
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0 | ||
go install github.com/envoyproxy/protoc-gen-validate@v1.0.1 | ||
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest | ||
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest | ||
go install github.com/google/wire/cmd/wire@latest | ||
go install github.com/vektra/mockery/v2@v2.20.0 | ||
go install ariga.io/atlas/cmd/atlas@v0.12.0 | ||
go install github.com/bufbuild/buf/cmd/buf@v1.10.0 | ||
|
||
# show help | ||
help: | ||
@echo '' | ||
@echo 'Usage:' | ||
@echo ' make [target]' | ||
@echo '' | ||
@echo 'Targets:' | ||
@awk '/^[a-zA-Z\-_0-9]+:/ { \ | ||
helpMessage = match(lastLine, /^# (.*)/); \ | ||
if (helpMessage) { \ | ||
helpCommand = substr($$1, 0, index($$1, ":")-1); \ | ||
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \ | ||
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \ | ||
} \ | ||
} \ | ||
{ lastLine = $$0 }' $(MAKEFILE_LIST) | ||
|
||
.DEFAULT_GOAL := help | ||
|
||
.PHONY: check-goreleaser-tool | ||
check-atlas-tool: | ||
@if ! command -v atlas >/dev/null 2>&1; then \ | ||
echo "altas is not installed. Please run \"make init\" or install the tool manually."; \ | ||
exit 1; \ | ||
fi | ||
|
||
.PHONY: check-wire-tool | ||
check-wire-tool: | ||
@if ! command -v wire >/dev/null 2>&1; then \ | ||
echo "wire is not installed. Please run \"make init\" or install the tool manually."; \ | ||
exit 1; \ | ||
fi | ||
|
||
.PHONY: check-golangci-lint-tool | ||
check-golangci-lint-tool: | ||
@if ! command -v golangci-lint >/dev/null 2>&1; then \ | ||
echo "golangci-lint is not installed. Please run \"make init\" or install the tool manually."; \ | ||
exit 1; \ | ||
fi | ||
|
||
.PHONY: check-buf-tool | ||
check-buf-tool: | ||
@if ! command -v buf >/dev/null 2>&1; then \ | ||
echo "buf is not installed. Please run \"make init\" or install the tool manually."; \ | ||
exit 1; \ | ||
fi | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// Copyright 2023 The Chainloop Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package backend | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
type ErrNotFound struct { | ||
entity string | ||
} | ||
|
||
func NewErrNotFound(entity string) ErrNotFound { | ||
return ErrNotFound{entity} | ||
} | ||
|
||
func (e ErrNotFound) Error() string { | ||
return fmt.Sprintf("%s not found", e.entity) | ||
} | ||
|
||
func IsNotFound(err error) bool { | ||
return errors.As(err, &ErrNotFound{}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,12 +29,14 @@ import ( | |
"github.com/google/go-containerregistry/pkg/v1/empty" | ||
"github.com/google/go-containerregistry/pkg/v1/mutate" | ||
"github.com/google/go-containerregistry/pkg/v1/remote" | ||
"github.com/google/go-containerregistry/pkg/v1/remote/transport" | ||
"github.com/google/go-containerregistry/pkg/v1/static" | ||
"github.com/google/go-containerregistry/pkg/v1/types" | ||
|
||
ocispec "github.com/opencontainers/image-spec/specs-go/v1" | ||
|
||
pb "github.com/chainloop-dev/chainloop/app/artifact-cas/api/cas/v1" | ||
backend "github.com/chainloop-dev/chainloop/internal/blobmanager" | ||
) | ||
|
||
type Backend struct { | ||
|
@@ -185,6 +187,11 @@ func (b *Backend) Describe(_ context.Context, digest string) (*pb.CASResource, e | |
|
||
img, err := remote.Image(ref, remote.WithAuthFromKeychain(b.keychain)) | ||
if err != nil { | ||
var e *transport.Error | ||
if errors.As(err, &e) && e.StatusCode == http.StatusNotFound { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the way we bubble up the not found error |
||
return nil, backend.NewErrNotFound("image") | ||
} | ||
|
||
return nil, fmt.Errorf("getting image: %w", err) | ||
} | ||
|
||
|
@@ -197,7 +204,7 @@ func (b *Backend) Describe(_ context.Context, digest string) (*pb.CASResource, e | |
return nil, fmt.Errorf("extracting manifest: %w", err) | ||
} | ||
|
||
// Valirate image already checked that the manifest has exactly one layer | ||
// Validate image already checked that the manifest has exactly one layer | ||
size := manifest.Layers[0].Size | ||
|
||
filename, ok := manifest.Annotations[ocispec.AnnotationTitle] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we now check if the error is not found