Skip to content
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.

Commit

Permalink
fix: reate lifecycle policies only when they don't exist already (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfinteligenz authored Nov 13, 2023
1 parent deae892 commit 507e39e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions go-sdk/sdk/persistent-storage/persistent_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (ps PersistentStorage) Save(key string, payload []byte, ttlDays ...int) (*O
reader := bytes.NewReader(payload)

opts := minio.PutObjectOptions{
UserTags: map[string]string{
UserMetadata: map[string]string{
"product": ps.metadata.GetProduct(),
"version": ps.metadata.GetVersion(),
"workflow": ps.metadata.GetWorkflow(),
Expand Down Expand Up @@ -318,17 +318,29 @@ func (ps PersistentStorage) addLifecycleDeletionRule(key string, ttlDays []int,
lc = lifecycle.NewConfiguration()
}

lc.Rules = append(lc.Rules, lifecycle.Rule{
rule := lifecycle.Rule{
ID: fmt.Sprintf("ttl-%s", key),
Status: minio.Enabled,
//Prefix: key,
RuleFilter: lifecycle.Filter{
Prefix: key,
},
Expiration: lifecycle.Expiration{
Days: lifecycle.ExpirationDays(ttlDays[0]),
},
})
}

found := false

for _, r := range lc.Rules {
if r.ID == rule.ID {
found = true
break
}
}

if !found {
lc.Rules = append(lc.Rules, rule)
}

err = ps.persistentStorage.SetBucketLifecycle(ctx, ps.persistentStorageBucket, lc)
if err != nil {
Expand Down

0 comments on commit 507e39e

Please sign in to comment.