Skip to content

Commit e55692f

Browse files
committed
add log statement for PutObjectAcl
cr https://cr.amazon.com/r/6653749/
1 parent 1f299ae commit e55692f

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

agent/plugins/pluginutil/pluginutil.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type UploadOutputToS3BucketExecuter func(log log.T, pluginID string, orchestrati
5151

5252
// S3Uploader is an interface for objects that can upload data to s3.
5353
type S3Uploader interface {
54-
S3Upload(bucketName string, bucketKey string, filePath string) error
54+
S3Upload(log log.T, bucketName string, bucketKey string, filePath string) error
5555
UploadS3TestFile(log log.T, bucketName, key string) error
5656
IsS3ErrorRelatedToAccessDenied(errMsg string) bool
5757
IsS3ErrorRelatedToWrongBucketRegion(errMsg string) bool
@@ -238,7 +238,7 @@ func (p *DefaultPlugin) UploadOutputToS3Bucket(log log.T, pluginID string, orche
238238

239239
s3Key := fileutil.BuildS3Path(outputS3KeyPrefix, pluginID, p.StdoutFileName)
240240
log.Debugf("Uploading %v to s3://%v/%v", localPath, outputS3BucketName, s3Key)
241-
err := p.Uploader.S3Upload(outputS3BucketName, s3Key, localPath)
241+
err := p.Uploader.S3Upload(log, outputS3BucketName, s3Key, localPath)
242242
if err != nil {
243243

244244
log.Errorf("failed uploading %v to s3://%v/%v err:%v", localPath, outputS3BucketName, s3Key, err)
@@ -254,7 +254,7 @@ func (p *DefaultPlugin) UploadOutputToS3Bucket(log log.T, pluginID string, orche
254254

255255
s3Key := fileutil.BuildS3Path(outputS3KeyPrefix, pluginID, p.StderrFileName)
256256
log.Debugf("Uploading %v to s3://%v/%v", localPath, outputS3BucketName, s3Key)
257-
err := p.Uploader.S3Upload(outputS3BucketName, s3Key, localPath)
257+
err := p.Uploader.S3Upload(log, outputS3BucketName, s3Key, localPath)
258258
if err != nil {
259259
log.Errorf("failed uploading %v to s3://%v/%v err:%v", localPath, outputS3BucketName, s3Key, err)
260260
if p.UploadToS3Sync {

agent/s3util/s3util.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ func (m *Manager) SetS3ClientRegion(region string) {
5555
}
5656

5757
// S3Upload uploads a file to s3.
58-
func (m *Manager) S3Upload(bucketName string, objectKey string, filePath string) (err error) {
58+
func (m *Manager) S3Upload(log log.T, bucketName string, objectKey string, filePath string) (err error) {
5959
file, err := os.Open(filePath)
6060
if err != nil {
6161
return
6262
}
63-
return m.S3UploadFromReader(bucketName, objectKey, file)
63+
return m.S3UploadFromReader(log, bucketName, objectKey, file)
6464
}
6565

6666
// S3UploadFromReader uploads data to s3 from an io.ReadSeeker.
67-
func (m *Manager) S3UploadFromReader(bucketName string, objectKey string, content io.ReadSeeker) (err error) {
67+
func (m *Manager) S3UploadFromReader(log log.T, bucketName string, objectKey string, content io.ReadSeeker) (err error) {
6868
params := &s3.PutObjectInput{
6969
Bucket: aws.String(bucketName),
7070
Key: aws.String(objectKey),
@@ -78,9 +78,11 @@ func (m *Manager) S3UploadFromReader(bucketName string, objectKey string, conten
7878
ACL: aws.String("bucket-owner-full-control"),
7979
}
8080
// gracefully ignore the error, since the S3 putAcl policy may not be set
81-
m.S3.PutObjectAcl(aclParams)
81+
if _, aclErr := m.S3.PutObjectAcl(aclParams); aclErr != nil {
82+
log.Infof("PutAcl: bucket-owner-full-control failed, error: %v", aclErr)
83+
}
8284
}
83-
85+
8486
return
8587
}
8688

agent/s3util/test_s3util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type MockS3Uploader struct {
2929
var logger = log.NewMockLog()
3030

3131
// S3Upload mocks the method with the same name.
32-
func (uploader *MockS3Uploader) S3Upload(bucketName string, bucketKey string, contentPath string) error {
32+
func (uploader *MockS3Uploader) S3Upload(log log.T, bucketName string, bucketKey string, contentPath string) error {
3333
args := uploader.Called(bucketName, bucketKey, contentPath)
3434
logger.Debugf("===========MockS3Upload Uploading %v to s3://%v/%v returns %v", contentPath, bucketName, bucketKey, args.Error(0))
3535

agent/update/processor/context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func (c *contextManager) uploadOutput(log log.T, context *UpdateContext) (err er
239239
stdoutPath := updateutil.UpdateStdOutPath(context.Current.UpdateRoot, context.Current.StdoutFileName)
240240
s3Key := path.Join(context.Current.OutputS3KeyPrefix, context.Current.StdoutFileName)
241241
log.Debugf("Uploading %v to s3://%v/%v", stdoutPath, context.Current.OutputS3BucketName, s3Key)
242-
err = uploader.S3Upload(context.Current.OutputS3BucketName, s3Key, stdoutPath)
242+
err = uploader.S3Upload(log, context.Current.OutputS3BucketName, s3Key, stdoutPath)
243243
if err != nil {
244244
log.Errorf("failed uploading %v to s3://%v/%v \n err:%v",
245245
stdoutPath,
@@ -252,7 +252,7 @@ func (c *contextManager) uploadOutput(log log.T, context *UpdateContext) (err er
252252
stderrPath := updateutil.UpdateStdOutPath(context.Current.UpdateRoot, context.Current.StderrFileName)
253253
s3Key = path.Join(context.Current.OutputS3KeyPrefix, context.Current.StderrFileName)
254254
log.Debugf("Uploading %v to s3://%v/%v", stderrPath, context.Current.OutputS3BucketName, s3Key)
255-
err = uploader.S3Upload(context.Current.OutputS3BucketName, s3Key, stderrPath)
255+
err = uploader.S3Upload(log, context.Current.OutputS3BucketName, s3Key, stderrPath)
256256
if err != nil {
257257
log.Errorf("failed uploading %v to s3://%v/%v \n err:%v", stderrPath, context.Current.StderrFileName, s3Key, err)
258258
}

0 commit comments

Comments
 (0)