|
|
@ -19,6 +19,8 @@ package lifecycle |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"bytes" |
|
|
|
"encoding/xml" |
|
|
|
"encoding/xml" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/google/uuid" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Status represents lifecycle configuration status
|
|
|
|
// Status represents lifecycle configuration status
|
|
|
@ -44,16 +46,34 @@ type Rule struct { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
var ( |
|
|
|
errInvalidRuleID = Errorf("ID must be less than 255 characters") |
|
|
|
errInvalidRuleID = Errorf("ID length is limited to 255 characters") |
|
|
|
errEmptyRuleStatus = Errorf("Status should not be empty") |
|
|
|
errEmptyRuleStatus = Errorf("Status should not be empty") |
|
|
|
errInvalidRuleStatus = Errorf("Status must be set to either Enabled or Disabled") |
|
|
|
errInvalidRuleStatus = Errorf("Status must be set to either Enabled or Disabled") |
|
|
|
errMissingExpirationAction = Errorf("No expiration action found") |
|
|
|
errMissingExpirationAction = Errorf("No expiration action found") |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
// validateID - checks if ID is valid or not.
|
|
|
|
func (r Rule) validateID() error { |
|
|
|
func (r Rule) validateID() error { |
|
|
|
|
|
|
|
IDLen := len(string(r.ID)) |
|
|
|
|
|
|
|
// generate new ID when not provided
|
|
|
|
// cannot be longer than 255 characters
|
|
|
|
// cannot be longer than 255 characters
|
|
|
|
if len(string(r.ID)) > 255 { |
|
|
|
if IDLen == 0 { |
|
|
|
|
|
|
|
if newID, err := getNewUUID(); err == nil { |
|
|
|
|
|
|
|
r.ID = newID |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if IDLen > 255 { |
|
|
|
return errInvalidRuleID |
|
|
|
return errInvalidRuleID |
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
return nil |
|
|
|