scheme

package
v0.0.0-...-2c1c132 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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()
)
View Source
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.

View Source
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

func ValidateFQDN(fqdn string) error

ValidateFQDN checks a fully-qualified domain name

func ValidateMetaAttributeName

func ValidateMetaAttributeName(name string) error

ValidateMetaAttributeName validates a header name

func ValidatePercent

func ValidatePercent(val uint32) error

ValidatePercent checks that percent is in range

func ValidatePort

func ValidatePort(port int) error

ValidatePort checks that the network port is in range

func ValidatePortName

func ValidatePortName(name string) error

ValidatePortName validates a port name to DNS-1123

func ValidateProtocol

func ValidateProtocol(protocolStr string) error

ValidateProtocol validates a portocol name is known

Types

type AnalysisAwareError

type AnalysisAwareError struct {
	Type       string
	Msg        string
	Parameters []interface{}
}

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 WrapError

func WrapError(e error) Validation

WrapError turns an error into a Validation

func WrapWarning

func WrapWarning(e error) Validation

WrapWarning turns an error into a Validation as a warning

func (Validation) Error

func (v Validation) Error() string

Error return the error string

func (Validation) Unwrap

func (v Validation) Unwrap() (validation.Warning, error)

Unwrap a validation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL