diff --git a/hauler-manifest.yaml b/hauler-manifest.yaml index 511b2e2d..585a0c4e 100644 --- a/hauler-manifest.yaml +++ b/hauler-manifest.yaml @@ -57,4 +57,4 @@ metadata: spec: files: - name: validatorctl - path: https://github.com/validator-labs/validatorctl/releases/download/v0.1.1/validator-linux-ARCH \ No newline at end of file + path: https://github.com/validator-labs/validatorctl/releases/download/v0.1.2/validator-linux-ARCH \ No newline at end of file diff --git a/pkg/validationresult/validation_result.go b/pkg/validationresult/validation_result.go index da4d4fb5..eee4c7b2 100644 --- a/pkg/validationresult/validation_result.go +++ b/pkg/validationresult/validation_result.go @@ -26,16 +26,16 @@ type Patcher interface { Patch(ctx context.Context, obj client.Object, opts ...patch.Option) error } -// ValidationRule is an interface for validation rules. -type ValidationRule interface { +// Validator is an interface for building ValidationResults. +type Validator interface { client.Object GetKind() string PluginCode() string ResultCount() int } -// Build creates a new ValidationResult for a specific ValidationRule. -func Build(r ValidationRule) *v1alpha1.ValidationResult { +// Build creates a new ValidationResult for a specific Validator. +func Build(r Validator) *v1alpha1.ValidationResult { return &v1alpha1.ValidationResult{ TypeMeta: metav1.TypeMeta{ APIVersion: v1alpha1.APIVersion, @@ -61,8 +61,8 @@ func Build(r ValidationRule) *v1alpha1.ValidationResult { } } -// Name returns the name of a ValidationResult for a specific ValidationRule. -func Name(r ValidationRule) string { +// Name returns the name of a ValidationResult for a specific Validator. +func Name(r Validator) string { name := fmt.Sprintf("validator-plugin-%s-%s", r.PluginCode(), r.GetName()) return util.Sanitize(name) } diff --git a/pkg/validationrule/validation_rule.go b/pkg/validationrule/validation_rule.go new file mode 100644 index 00000000..1cc19749 --- /dev/null +++ b/pkg/validationrule/validation_rule.go @@ -0,0 +1,38 @@ +// Package validationrule describes validation rules. +package validationrule + +// Interface defines validation rule behavior. +type Interface interface { + // Name returns the name of the rule. + Name() string + // SetName sets the name of the rule if it is a rule that requires manually specifying its name. + // This should be a no-op for rules that automatically generate their name. + SetName(string) + // RequiresName returns whether the validation rule requires its name to be manually specified. + // This should return false for rules that automatically generate their name. + RequiresName() bool +} + +// ManuallyNamed can be embedded into a rule struct to indicate that the rule requires its name to +// be manually specified. +type ManuallyNamed struct{} + +// RequiresName returns true. +func (ManuallyNamed) RequiresName() bool { + return true +} + +// AutomaticallyNamed can be embedded into a rule struct to indicate that the rule does not require +// its name to be manually specified because it is automatically generated from other data in the +// rule. +type AutomaticallyNamed struct{} + +// RequiresName returns false. +func (AutomaticallyNamed) RequiresName() bool { + return false +} + +// SetName is a no-op because the rule does not support manually specifying its name. +func (AutomaticallyNamed) SetName(string) { + // no-op +}