35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"unicode/utf8"
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
|
)
|
|
|
|
func validateNormalizeRetry(retry *contracts.NormalizeRetry) error {
|
|
if retry == nil {
|
|
return errors.New("normalize retry directive is missing")
|
|
}
|
|
if !utf8.ValidString(retry.ReasonCode) {
|
|
return errors.New("normalize retry directive reason code has invalid UTF-8")
|
|
}
|
|
if strings.TrimSpace(retry.ReasonCode) == "" {
|
|
return errors.New("normalize retry directive reason code is blank")
|
|
}
|
|
if len(retry.ReasonCode) > contracts.MaxNormalizeRetryReasonCodeBytes {
|
|
return errors.New("normalize retry directive reason code exceeds maximum length")
|
|
}
|
|
if !utf8.ValidString(retry.Message) {
|
|
return errors.New("normalize retry directive message has invalid UTF-8")
|
|
}
|
|
if strings.TrimSpace(retry.Message) == "" {
|
|
return errors.New("normalize retry directive message is blank")
|
|
}
|
|
if len(retry.Message) > contracts.MaxNormalizeRetryMessageBytes {
|
|
return errors.New("normalize retry directive message exceeds maximum length")
|
|
}
|
|
return nil
|
|
}
|