Skip to content

Commit

Permalink
feat: Add prevent logic of PutObject with content type at JPN region
Browse files Browse the repository at this point in the history
  • Loading branch information
Geun-Oh committed Sep 23, 2024
1 parent c810ec2 commit 1b65cee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions internal/service/objectstorage/objectstorage_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ func (o *objectResource) Update(ctx context.Context, req resource.UpdateRequest,

reqParams.Body = file
} else {
// Prevent wasting of GetObject operation
if !plan.ContentType.Equal(state.ContentType) && o.config.RegionCode == "JPN" {
resp.Diagnostics.AddError("UPDATING ERROR", "updating object Content-Type is unavailable in this region")
return
}

getReqParams := &s3.GetObjectInput{
Bucket: state.Bucket.ValueStringPointer(),
Key: state.Key.ValueStringPointer(),
Expand Down
12 changes: 9 additions & 3 deletions internal/service/objectstorage/objectstorage_object_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ func (o *objectCopyResource) Update(ctx context.Context, req resource.UpdateRequ

if !plan.ContentType.Equal(state.ContentType) {

if o.config.RegionCode == "JPN" {
resp.Diagnostics.AddError("UPDATING ERROR", "updating object Content-Type is unavailable in this region")
return
}

getReqParams := &s3.GetObjectInput{
Bucket: state.Bucket.ValueStringPointer(),
Key: state.Key.ValueStringPointer(),
Expand All @@ -296,9 +301,10 @@ func (o *objectCopyResource) Update(ctx context.Context, req resource.UpdateRequ
tflog.Info(ctx, "GetObject at update operation response="+common.MarshalUncheckedString(getOutput))

reqParams := &s3.PutObjectInput{
Bucket: plan.Bucket.ValueStringPointer(),
Key: plan.Key.ValueStringPointer(),
Body: getOutput.Body,
Bucket: plan.Bucket.ValueStringPointer(),
Key: plan.Key.ValueStringPointer(),
Body: getOutput.Body,
// this option is only available in KR region
ContentType: plan.ContentType.ValueStringPointer(),
}

Expand Down

0 comments on commit 1b65cee

Please sign in to comment.