MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / Describe

Method Describe

pkg/blobmanager/s3/backend.go:179–225  ·  view source on GitHub ↗
(ctx context.Context, digest string)

Source from the content-addressed store, hash-verified

177}
178
179func (b *Backend) Describe(ctx context.Context, digest string) (*pb.CASResource, error) {
180 input := &s3.HeadObjectInput{
181 Bucket: aws.String(b.bucket),
182 Key: aws.String(resourceName(digest)),
183 }
184
185 if b.checksumVerificationEnabled() {
186 // Enable checksum verification
187 input.ChecksumMode = types.ChecksumModeEnabled
188 }
189
190 // and read the object back
191 resp, err := b.client.HeadObject(ctx, input)
192
193 // check error is aws error
194 if err != nil {
195 var apiErr smithy.APIError
196 if errors.As(err, &apiErr) && apiErr.ErrorCode() == "NotFound" {
197 return nil, backend.NewErrNotFound("artifact")
198 }
199
200 return nil, fmt.Errorf("failed to read from bucket: %w", err)
201 }
202
203 // Check integrity of the remote object
204 if resp.ChecksumSHA256 != nil && *resp.ChecksumSHA256 != hexSha256ToBinaryB64(digest) {
205 return nil, fmt.Errorf("failed to validate integrity of object, got=%s, want=%s", *resp.ChecksumSHA256, hexSha256ToBinaryB64(digest))
206 }
207
208 // Check asset author is Chainloop that way we can ignore files uploaded by other tools
209 // note: this is not a security mechanism, an additional check will be put in place for tamper check
210 author, ok := resp.Metadata[annotationNameAuthor]
211 if !ok || author != backend.AuthorAnnotation {
212 return nil, errors.New("asset not uploaded by Chainloop")
213 }
214
215 fileName, ok := resp.Metadata[annotationNameFilename]
216 if !ok {
217 return nil, fmt.Errorf("couldn't find file metadata")
218 }
219
220 return &pb.CASResource{
221 FileName: fileName,
222 Size: *resp.ContentLength,
223 Digest: digest,
224 }, nil
225}
226
227func (b *Backend) Download(ctx context.Context, w io.Writer, digest string) error {
228 exists, err := b.Exists(ctx, digest)

Callers 1

ExistsMethod · 0.95

Calls 4

resourceNameFunction · 0.70
hexSha256ToBinaryB64Function · 0.70
StringMethod · 0.65

Tested by

no test coverage detected