(ctx context.Context, digest string)
| 177 | } |
| 178 | |
| 179 | func (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 | |
| 227 | func (b *Backend) Download(ctx context.Context, w io.Writer, digest string) error { |
| 228 | exists, err := b.Exists(ctx, digest) |
no test coverage detected