mirror of
https://github.com/minio/minio.git
synced 2025-11-21 18:26:04 -05:00
lifecycle: Assign unique id to rules with empty id (#15731)
This commit is contained in:
committed by
GitHub
parent
6e84283c66
commit
6f56ba80b3
@@ -20,8 +20,6 @@ package lifecycle
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Status represents lifecycle configuration status
|
||||
@@ -53,28 +51,9 @@ var (
|
||||
errInvalidRuleStatus = Errorf("Status must be set to either Enabled or Disabled")
|
||||
)
|
||||
|
||||
// generates random UUID
|
||||
func getNewUUID() (string, error) {
|
||||
u, err := uuid.NewRandom()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
// validateID - checks if ID is valid or not.
|
||||
func (r Rule) validateID() error {
|
||||
IDLen := len(r.ID)
|
||||
// generate new ID when not provided
|
||||
// cannot be longer than 255 characters
|
||||
if IDLen == 0 {
|
||||
if newID, err := getNewUUID(); err == nil {
|
||||
r.ID = newID
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
} else if IDLen > 255 {
|
||||
if len(r.ID) > 255 {
|
||||
return errInvalidRuleID
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user