From e2bd18eebf729e8538b5080f54c9cc2cecac05bc Mon Sep 17 00:00:00 2001 From: Joshua Leuenberger Date: Tue, 28 Apr 2026 17:20:22 +0200 Subject: [PATCH] fix: bucket policy is both string and int from API Co-authored-by: Copilot --- examples/tenant/bucket-operations/main.go | 2 +- models/buckets.go | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/examples/tenant/bucket-operations/main.go b/examples/tenant/bucket-operations/main.go index dc30ec6..fcaa5cc 100644 --- a/examples/tenant/bucket-operations/main.go +++ b/examples/tenant/bucket-operations/main.go @@ -152,7 +152,7 @@ func createExampleBuckets(ctx context.Context, client *client.TenantClient) erro Enabled: &config.objectLock, DefaultRetentionSetting: &models.BucketS3ObjectLockDefaultRetentionSettings{ Mode: "COMPLIANCE", - Years: 1, + Years: "1", }, } } diff --git a/models/buckets.go b/models/buckets.go index 1db6787..29f1c4d 100644 --- a/models/buckets.go +++ b/models/buckets.go @@ -1,6 +1,9 @@ package models -import "time" +import ( + "encoding/json" + "time" +) type Bucket struct { // if true, object versioning will be enabled for the bucket. @@ -30,9 +33,16 @@ type BucketS3ObjectLockDefaultRetentionSettings struct { // The retention mode used for new objects added to this bucket. Must be compliance, which means that an object version cannot be overwritten or deleted by any user. Mode string `json:"mode"` // The length of the default retention period for new objects added to this bucket, in days. If provided, must be paired with retentionMode. Does not affect existing bucket objects or objects with their own retain-until-date settings. - Days int32 `json:"days,omitempty"` + // + // Typed as json.Number because the StorageGRID API returns this value + // as a JSON string (e.g. "30") even though it accepts an integer on + // write. json.Number tolerates both encodings on read and marshals + // back as a bare numeric literal on write. + Days json.Number `json:"days,omitempty"` // The length of the default retention period for new objects added to this bucket, in years. If provided, must be paired with retentionMode. Does not affect existing bucket objects or objects with their own retain-until-date settings. - Years int32 `json:"years,omitempty"` + // + // See Days for why this is typed as json.Number. + Years json.Number `json:"years,omitempty"` } type BucketComplianceSettings struct {