Skip to content

Commit

Permalink
Merge pull request #46 from ekristen/storage-bucket
Browse files Browse the repository at this point in the history
feat(storage-bucket): add setting for disabling deletion protection
  • Loading branch information
ekristen authored Aug 18, 2024
2 parents 9c2f2d5 + 4158ee4 commit 93d4f13
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions resources/storage-bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func init() {
},
Settings: []string{
"DeleteGoogleManagedBuckets",
"DisableDeletionProtection",
},
})
}
Expand Down Expand Up @@ -158,17 +159,23 @@ func (r *StorageBucket) Filter() error {
}

func (r *StorageBucket) Remove(ctx context.Context) error {
if _, err := r.svc.Bucket(*r.Name).Update(ctx, storage.BucketAttrsToUpdate{
RetentionPolicy: nil,
SoftDeletePolicy: &storage.SoftDeletePolicy{
EffectiveTime: time.Now(),
RetentionDuration: 0,
},
Lifecycle: &storage.Lifecycle{Rules: nil},
VersioningEnabled: false,
}); err != nil {
logrus.WithError(err).Error("encountered error while updating bucket attrs")
return err
if r.settings.GetBool("DisableDeletionProtection") {
if _, err := r.svc.Bucket(*r.Name).Update(ctx, storage.BucketAttrsToUpdate{
RetentionPolicy: &storage.RetentionPolicy{
RetentionPeriod: 0,
EffectiveTime: time.Now(),
IsLocked: false,
},
SoftDeletePolicy: &storage.SoftDeletePolicy{
EffectiveTime: time.Now(),
RetentionDuration: 0,
},
Lifecycle: &storage.Lifecycle{Rules: nil},
VersioningEnabled: false,
}); err != nil {
logrus.WithError(err).Error("encountered error while updating bucket attrs")
return err
}
}

if err := r.removeObjects(ctx); err != nil {
Expand Down

0 comments on commit 93d4f13

Please sign in to comment.