Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(storage): refactor retention_period to retention_duration #7203

Merged
merged 1 commit into from Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions storage/bucket.go
Expand Up @@ -35,6 +35,7 @@ import (
raw "google.golang.org/api/storage/v1"
dpb "google.golang.org/genproto/googleapis/type/date"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/durationpb"
)

// BucketHandle provides operations on a Google Cloud Storage bucket.
Expand Down Expand Up @@ -1389,12 +1390,12 @@ func (rp *RetentionPolicy) toProtoRetentionPolicy() *storagepb.Bucket_RetentionP
}
// RetentionPeriod must be greater than 0, so if it is 0, the user left it
// unset, and so we should not send it in the request i.e. nil is sent.
var period *int64
var dur *durationpb.Duration
if rp.RetentionPeriod != 0 {
period = proto.Int64(int64(rp.RetentionPeriod / time.Second))
dur = durationpb.New(rp.RetentionPeriod)
}
return &storagepb.Bucket_RetentionPolicy{
RetentionPeriod: period,
RetentionDuration: dur,
}
}

Expand All @@ -1418,7 +1419,7 @@ func toRetentionPolicyFromProto(rp *storagepb.Bucket_RetentionPolicy) *Retention
return nil
}
return &RetentionPolicy{
RetentionPeriod: time.Duration(rp.GetRetentionPeriod()) * time.Second,
RetentionPeriod: rp.GetRetentionDuration().AsDuration(),
EffectiveTime: rp.GetEffectiveTime().AsTime(),
IsLocked: rp.GetIsLocked(),
}
Expand Down
7 changes: 4 additions & 3 deletions storage/bucket_test.go
Expand Up @@ -27,6 +27,7 @@ import (
"google.golang.org/api/googleapi"
raw "google.golang.org/api/storage/v1"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/durationpb"
)

func TestBucketAttrsToRawBucket(t *testing.T) {
Expand Down Expand Up @@ -725,8 +726,8 @@ func TestNewBucketFromProto(t *testing.T) {
LocationType: "region",
StorageClass: "class",
RetentionPolicy: &storagepb.Bucket_RetentionPolicy{
RetentionPeriod: proto.Int64(int64(3)),
EffectiveTime: toProtoTimestamp(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)),
RetentionDuration: durationpb.New(3 * time.Second),
EffectiveTime: toProtoTimestamp(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)),
},
IamConfig: &storagepb.Bucket_IamConfig{
UniformBucketLevelAccess: &storagepb.Bucket_IamConfig_UniformBucketLevelAccess{
Expand Down Expand Up @@ -866,7 +867,7 @@ func TestBucketAttrsToProtoBucket(t *testing.T) {
Location: "loc",
StorageClass: "class",
RetentionPolicy: &storagepb.Bucket_RetentionPolicy{
RetentionPeriod: proto.Int64(int64(3)),
RetentionDuration: durationpb.New(3 * time.Second),
},
IamConfig: &storagepb.Bucket_IamConfig{
UniformBucketLevelAccess: &storagepb.Bucket_IamConfig_UniformBucketLevelAccess{
Expand Down