lifecycle: Assign unique id to rules with empty id (#15731)

This commit is contained in:
Krishnan Parthasarathi
2022-09-22 10:51:54 -07:00
committed by GitHub
parent 6e84283c66
commit 6f56ba80b3
4 changed files with 48 additions and 23 deletions

View File

@@ -25,6 +25,7 @@ import (
"strings"
"time"
"github.com/google/uuid"
xhttp "github.com/minio/minio/internal/http"
)
@@ -176,6 +177,22 @@ func (lc Lifecycle) HasActiveRules(prefix string, recursive bool) bool {
return false
}
// ParseLifecycleConfigWithID - parses for a Lifecycle config and assigns
// unique id to rules with empty ID.
func ParseLifecycleConfigWithID(r io.Reader) (*Lifecycle, error) {
var lc Lifecycle
if err := xml.NewDecoder(r).Decode(&lc); err != nil {
return nil, err
}
// assign a unique id for rules with empty ID
for i := range lc.Rules {
if lc.Rules[i].ID == "" {
lc.Rules[i].ID = uuid.New().String()
}
}
return &lc, nil
}
// ParseLifecycleConfig - parses data in given reader to Lifecycle.
func ParseLifecycleConfig(reader io.Reader) (*Lifecycle, error) {
var lc Lifecycle