Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // AerakiMetaprotocolV1Alpha1Applicationprotocols describes the collection // aeraki/metaprotocol/v1alpha1/applicationprotocols AerakiMetaprotocolV1Alpha1Applicationprotocols = resource.Builder{ Identifier: "ApplicationProtocol", Group: "metaprotocol.aeraki.io", Kind: "ApplicationProtocol", Plural: "applicationprotocols", Version: "v1alpha1", VersionAliases: []string{ "v1", }, Proto: "aeraki.io.v1alpha1.ApplicationProtocol", ReflectType: reflect.TypeOf(&metaprotocolv1alpha1.ApplicationProtocol{}).Elem(), ProtoPackage: "github.com/aeraki-mesh/api/metaprotocol/v1alpha1", ClusterScoped: false, Synthetic: false, Builtin: false, ValidateProto: ValidateApplicationProtocol, }.MustBuild() // AerakiMetaprotocolV1Alpha1Metarouters describes the collection // aeraki/metaprotocol/v1alpha1/metarouters AerakiMetaprotocolV1Alpha1Metarouters = resource.Builder{ Identifier: "MetaRouter", Group: "metaprotocol.aeraki.io", Kind: "MetaRouter", Plural: "metarouters", Version: "v1alpha1", VersionAliases: []string{ "v1", }, Proto: "aeraki.io.v1alpha1.MetaRouter", ReflectType: reflect.TypeOf(&metaprotocolv1alpha1.MetaRouter{}).Elem(), ProtoPackage: "github.com/aeraki-mesh/api/metaprotocol/v1alpha1", ClusterScoped: false, Synthetic: false, Builtin: false, ValidateProto: ValidateMetaRouter, }.MustBuild() // Aeraki contains Aeraki collections in the system. Aeraki = collection.NewSchemasBuilder(). MustAdd(AerakiMetaprotocolV1Alpha1Applicationprotocols). MustAdd(AerakiMetaprotocolV1Alpha1Metarouters). Build() )
var ValidateApplicationProtocol = func(cfg config.Config) (validation.Warning, error) { protocol, ok := cfg.Spec.(*metaprotocol.ApplicationProtocol) if !ok { return nil, errors.New("cannot cast to application protocol") } errs := Validation{} if protocol.Protocol == "" { errs = appendValidation(errs, fmt.Errorf("application protocol must have protocol")) } if protocol.Codec == "" { errs = appendValidation(errs, fmt.Errorf("application protocol must have codec")) } return errs.Unwrap() }
ValidateApplicationProtocol checks that a v1alpha1 application protocol is well-formed.
var ValidateMetaRouter = func(cfg config.Config) (validation.Warning, error) { metaRouter, ok := cfg.Spec.(*metaprotocol.MetaRouter) if !ok { return nil, errors.New("cannot cast to meta router") } errs := Validation{} if len(metaRouter.Hosts) == 0 { errs = appendValidation(errs, fmt.Errorf("meta router must have one host")) } if len(metaRouter.Hosts) > 1 { errs = appendValidation(errs, fmt.Errorf("meta router can only have one host")) } if len(metaRouter.Hosts) == 1 { if err := ValidateFQDN(metaRouter.Hosts[0]); err != nil { errs = appendValidation(errs, err) } } if len(metaRouter.Routes) == 0 && metaRouter.GlobalRateLimit == nil && metaRouter.LocalRateLimit == nil { errs = appendValidation(errs, errors.New("meta router must at least have one of routes, globalRateLimit,"+ " or LocalRateLimit")) } for _, route := range metaRouter.Routes { if route == nil { errs = appendValidation(errs, errors.New("meta route may not be null")) continue } errs = appendValidation(errs, validateMetaRoute(route)) } errs = appendValidation(errs, validateExportTo(cfg.Namespace, metaRouter.ExportTo)) warnUnused := func(ruleno, reason string) { errs = appendValidation(errs, WrapWarning(&AnalysisAwareError{ Type: "MetaRouterUnreachableRule", Msg: fmt.Sprintf("MetaRouter rule %v not used (%s)", ruleno, reason), Parameters: []interface{}{ruleno, reason}, })) } warnIneffective := func(ruleno, matchno, dupno string) { errs = appendValidation(errs, WrapWarning(&AnalysisAwareError{ Type: "MetaRouterIneffectiveMatch", Msg: fmt.Sprintf("MetaRouter rule %v match %v is not used (duplicate/overlapping match in rule %v)", ruleno, matchno, dupno), Parameters: []interface{}{ruleno, matchno, dupno}, })) } analyzeUnreachableMetaRules(metaRouter.Routes, warnUnused, warnIneffective) errs = appendValidation(errs, validateGlobalRateLimit(metaRouter.GlobalRateLimit)) errs = appendValidation(errs, validateLocalRateLimit(metaRouter.LocalRateLimit)) return errs.Unwrap() }
ValidateMetaRouter checks that a v1alpha1 route rule is well-formed.
Functions ¶
func ValidateFQDN ¶
ValidateFQDN checks a fully-qualified domain name
func ValidateMetaAttributeName ¶
ValidateMetaAttributeName validates a header name
func ValidatePercent ¶
ValidatePercent checks that percent is in range
func ValidatePort ¶
ValidatePort checks that the network port is in range
func ValidatePortName ¶
ValidatePortName validates a port name to DNS-1123
func ValidateProtocol ¶
ValidateProtocol validates a portocol name is known
Types ¶
type AnalysisAwareError ¶
AnalysisAwareError wraps analysis error
func (*AnalysisAwareError) Error ¶
func (aae *AnalysisAwareError) Error() string
Error return the error string
type Validation ¶
type Validation struct { Err error Warning validation.Warning }
Validation holds errors and warnings. They can be joined with additional errors by called appendValidation
func Warningf ¶
func Warningf(format string, a ...interface{}) Validation
Warningf formats according to a format specifier and returns the string as a value that satisfies error. Like Errorf, but for warnings.
func WrapWarning ¶
func WrapWarning(e error) Validation
WrapWarning turns an error into a Validation as a warning
func (Validation) Unwrap ¶
func (v Validation) Unwrap() (validation.Warning, error)
Unwrap a validation