Validate normalize retry diagnostics
This commit is contained in:
34
internal/framework/pipeline/normalize_retry.go
Normal file
34
internal/framework/pipeline/normalize_retry.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user