Skip to content

Commit ac9cd9f

Browse files
authored
Merge branch 'main' into aledbf/build-message
2 parents 80661bb + 0ca9de0 commit ac9cd9f

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/aws/aws-sdk-go-v2/config v1.29.6
88
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.59
99
github.com/aws/aws-sdk-go-v2/service/s3 v1.75.4
10+
github.com/aws/smithy-go v1.22.2
1011
github.com/creack/pty v1.1.23
1112
github.com/disiqueira/gotree v1.0.0
1213
github.com/dop251/goja v0.0.0-20241024094426-79f3a7efcdbd
@@ -47,7 +48,6 @@ require (
4748
github.com/aws/aws-sdk-go-v2/service/sso v1.24.15 // indirect
4849
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.14 // indirect
4950
github.com/aws/aws-sdk-go-v2/service/sts v1.33.14 // indirect
50-
github.com/aws/smithy-go v1.22.2 // indirect
5151
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
5252
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
5353
github.com/cyphar/filepath-securejoin v0.2.3 // indirect

pkg/leeway/cache/remote/s3.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
1717
"github.com/aws/aws-sdk-go-v2/service/s3"
1818
"github.com/aws/aws-sdk-go-v2/service/s3/types"
19+
"github.com/aws/smithy-go"
1920
log "github.com/sirupsen/logrus"
2021

2122
"github.com/gitpod-io/leeway/pkg/leeway/cache"
@@ -480,7 +481,6 @@ func (s *S3Storage) UploadObject(ctx context.Context, key string, src string) er
480481
u.PartSize = defaultS3PartSize
481482
})
482483

483-
// For multipart uploads, we use a different approach with checksums
484484
input := &s3.PutObjectInput{
485485
Bucket: aws.String(s.bucketName),
486486
Key: aws.String(key),
@@ -489,6 +489,11 @@ func (s *S3Storage) UploadObject(ctx context.Context, key string, src string) er
489489

490490
_, err = uploader.Upload(ctx, input)
491491
if err != nil {
492+
var apiErr smithy.APIError
493+
if errors.As(err, &apiErr) && apiErr.ErrorCode() == "Forbidden" {
494+
log.WithError(err).Warnf("permission denied while uploading object %s to S3 - continuing", key)
495+
return nil
496+
}
492497
return fmt.Errorf("failed to upload object: %w", err)
493498
}
494499

pkg/leeway/cache/remote/s3_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/aws/aws-sdk-go-v2/aws"
1616
"github.com/aws/aws-sdk-go-v2/service/s3"
1717
"github.com/aws/aws-sdk-go-v2/service/s3/types"
18+
"github.com/aws/smithy-go"
1819
"github.com/gitpod-io/leeway/pkg/leeway/cache"
1920
"github.com/google/go-cmp/cmp"
2021
)
@@ -377,6 +378,24 @@ func TestS3Cache_Upload(t *testing.T) {
377378
},
378379
expectError: true,
379380
},
381+
{
382+
name: "403 forbidden error should not fail",
383+
packages: []cache.Package{
384+
&mockPackage{version: "v1"},
385+
},
386+
mockPutObject: func(key string) error {
387+
return &smithy.GenericAPIError{
388+
Code: "Forbidden",
389+
Message: "Access Denied",
390+
}
391+
},
392+
localCache: &mockLocalCache{
393+
locations: map[string]string{
394+
"v1": filepath.Join(tmpDir, "pkg1.tar.gz"),
395+
},
396+
},
397+
expectError: false,
398+
},
380399
}
381400

382401
for _, tt := range tests {

pkg/leeway/reporter.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,20 @@ func (r *ConsoleReporter) PackageBuildFinished(pkg *Package, rep *PackageBuildRe
215215
delete(r.times, nme)
216216
r.mu.Unlock()
217217

218-
var coverage string
218+
var coverage string
219219
if rep.TestCoverageAvailable {
220220
coverage = color.Sprintf("<fg=yellow>test coverage: %d%%</> <gray>(%d of %d functions have tests)</>\n", rep.TestCoveragePercentage, rep.FunctionsWithTest, rep.FunctionsWithTest+rep.FunctionsWithoutTest)
221221
}
222222
msg := color.Sprintf("%s<green>package build succeeded</> <gray>(%.2fs)</>\n", coverage, dur.Seconds())
223-
if rep.Error != nil {
223+
224+
if rep.Error != nil {
224225
msg = color.Sprintf("<red>package build failed while %sing</>\n<white>Reason:</> %s\n", rep.LastPhase(), rep.Error)
226+
} else {
227+
var coverage string
228+
if rep.TestCoverageAvailable {
229+
coverage = color.Sprintf("<fg=yellow>test coverage: %d%%</> <gray>(%d of %d functions have tests)</>\n", rep.TestCoveragePercentage, rep.FunctionsWithTest, rep.FunctionsWithTest+rep.FunctionsWithoutTest)
230+
}
231+
msg = color.Sprintf("%s<green>package build succeded</> <gray>(%.2fs)</>\n", coverage, dur.Seconds())
225232
}
226233
//nolint:errcheck
227234
io.WriteString(out, msg)

0 commit comments

Comments
 (0)