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

@@ -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