From 19eda875c7d03d937e8bc59d5d28e27d510e783e Mon Sep 17 00:00:00 2001 From: Jonathan Marcantonio Date: Tue, 3 Sep 2024 09:03:33 -0400 Subject: [PATCH] Rebase & update few protos Signed-off-by: Jonathan Marcantonio --- .../k8spolicy_ispropagatedto_k8scluster.proto | 8 +- .../relationships/metadata.pb.validate.go | 201 -------------- .../v1beta1/relationships/reporter_data.pb.go | 106 ++++---- .../reporter_data.pb.validate.go | 245 ------------------ .../v1beta1/relationships/reporter_data.proto | 8 +- ...ter_detail_nodes_inner.pb.validate_test.go | 118 --------- .../resources/k8s_policy.pb.validate_test.go | 58 ----- 7 files changed, 61 insertions(+), 683 deletions(-) delete mode 100644 api/kessel/inventory/v1beta1/relationships/metadata.pb.validate.go delete mode 100644 api/kessel/inventory/v1beta1/relationships/reporter_data.pb.validate.go delete mode 100644 api/kessel/inventory/v1beta1/resources/k8s_cluster_detail_nodes_inner.pb.validate_test.go delete mode 100644 api/kessel/inventory/v1beta1/resources/k8s_policy.pb.validate_test.go diff --git a/api/kessel/inventory/v1beta1/relationships/k8spolicy_ispropagatedto_k8scluster.proto b/api/kessel/inventory/v1beta1/relationships/k8spolicy_ispropagatedto_k8scluster.proto index f8af3a92..720d1435 100644 --- a/api/kessel/inventory/v1beta1/relationships/k8spolicy_ispropagatedto_k8scluster.proto +++ b/api/kessel/inventory/v1beta1/relationships/k8spolicy_ispropagatedto_k8scluster.proto @@ -5,7 +5,7 @@ package kessel.inventory.v1beta1.relationships; import "kessel/inventory/v1beta1/relationships/metadata.proto"; import "kessel/inventory/v1beta1/relationships/reporter_data.proto"; import "kessel/inventory/v1beta1/relationships/k8spolicy_ispropagatedto_k8scluster_detail.proto"; -import "validate/validate.proto"; +import "buf/validate/validate.proto"; option go_package = "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1/relationships"; option java_multiple_files = true; @@ -14,10 +14,10 @@ option java_package = "org.project_kessel.api.inventory.v1beta1.relationships"; message K8SPolicyIsPropagatedToK8SCluster { // Metadata about this resource - Metadata metadata = 1 [ (validate.rules).message = {required: false, skip: false} ]; + Metadata metadata = 1 [ (buf.validate.field) = {required: false, ignore: IGNORE_ALWAYS} ]; // Write only reporter specific data - ReporterData reporter_data = 245278793 [ (validate.rules).message.required = true ]; + ReporterData reporter_data = 245278793 [ (buf.validate.field).required = true ]; - K8SPolicyIsPropagatedToK8SClusterDetail relationship_data = 2122699 [ (validate.rules).message.required = true ]; + K8SPolicyIsPropagatedToK8SClusterDetail relationship_data = 2122699 [ (buf.validate.field).required = true ]; } diff --git a/api/kessel/inventory/v1beta1/relationships/metadata.pb.validate.go b/api/kessel/inventory/v1beta1/relationships/metadata.pb.validate.go deleted file mode 100644 index 1a36feb0..00000000 --- a/api/kessel/inventory/v1beta1/relationships/metadata.pb.validate.go +++ /dev/null @@ -1,201 +0,0 @@ -// Code generated by protoc-gen-validate. DO NOT EDIT. -// source: kessel/inventory/v1beta1/relationships/metadata.proto - -package relationships - -import ( - "bytes" - "errors" - "fmt" - "net" - "net/mail" - "net/url" - "regexp" - "sort" - "strings" - "time" - "unicode/utf8" - - "google.golang.org/protobuf/types/known/anypb" -) - -// ensure the imports are used -var ( - _ = bytes.MinRead - _ = errors.New("") - _ = fmt.Print - _ = utf8.UTFMax - _ = (*regexp.Regexp)(nil) - _ = (*strings.Reader)(nil) - _ = net.IPv4len - _ = time.Duration(0) - _ = (*url.URL)(nil) - _ = (*mail.Address)(nil) - _ = anypb.Any{} - _ = sort.Sort -) - -// Validate checks the field values on Metadata with the rules defined in the -// proto definition for this message. If any rules are violated, the first -// error encountered is returned, or nil if there are no violations. -func (m *Metadata) Validate() error { - return m.validate(false) -} - -// ValidateAll checks the field values on Metadata with the rules defined in -// the proto definition for this message. If any rules are violated, the -// result is a list of violation errors wrapped in MetadataMultiError, or nil -// if none found. -func (m *Metadata) ValidateAll() error { - return m.validate(true) -} - -func (m *Metadata) validate(all bool) error { - if m == nil { - return nil - } - - var errors []error - - // no validation rules for Id - - // no validation rules for RelationshipType - - if all { - switch v := interface{}(m.GetFirstReported()).(type) { - case interface{ ValidateAll() error }: - if err := v.ValidateAll(); err != nil { - errors = append(errors, MetadataValidationError{ - field: "FirstReported", - reason: "embedded message failed validation", - cause: err, - }) - } - case interface{ Validate() error }: - if err := v.Validate(); err != nil { - errors = append(errors, MetadataValidationError{ - field: "FirstReported", - reason: "embedded message failed validation", - cause: err, - }) - } - } - } else if v, ok := interface{}(m.GetFirstReported()).(interface{ Validate() error }); ok { - if err := v.Validate(); err != nil { - return MetadataValidationError{ - field: "FirstReported", - reason: "embedded message failed validation", - cause: err, - } - } - } - - if all { - switch v := interface{}(m.GetLastReported()).(type) { - case interface{ ValidateAll() error }: - if err := v.ValidateAll(); err != nil { - errors = append(errors, MetadataValidationError{ - field: "LastReported", - reason: "embedded message failed validation", - cause: err, - }) - } - case interface{ Validate() error }: - if err := v.Validate(); err != nil { - errors = append(errors, MetadataValidationError{ - field: "LastReported", - reason: "embedded message failed validation", - cause: err, - }) - } - } - } else if v, ok := interface{}(m.GetLastReported()).(interface{ Validate() error }); ok { - if err := v.Validate(); err != nil { - return MetadataValidationError{ - field: "LastReported", - reason: "embedded message failed validation", - cause: err, - } - } - } - - // no validation rules for FirstReportedBy - - // no validation rules for LastReportedBy - - if len(errors) > 0 { - return MetadataMultiError(errors) - } - - return nil -} - -// MetadataMultiError is an error wrapping multiple validation errors returned -// by Metadata.ValidateAll() if the designated constraints aren't met. -type MetadataMultiError []error - -// Error returns a concatenation of all the error messages it wraps. -func (m MetadataMultiError) Error() string { - var msgs []string - for _, err := range m { - msgs = append(msgs, err.Error()) - } - return strings.Join(msgs, "; ") -} - -// AllErrors returns a list of validation violation errors. -func (m MetadataMultiError) AllErrors() []error { return m } - -// MetadataValidationError is the validation error returned by -// Metadata.Validate if the designated constraints aren't met. -type MetadataValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e MetadataValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e MetadataValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e MetadataValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e MetadataValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e MetadataValidationError) ErrorName() string { return "MetadataValidationError" } - -// Error satisfies the builtin error interface -func (e MetadataValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sMetadata.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = MetadataValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = MetadataValidationError{} diff --git a/api/kessel/inventory/v1beta1/relationships/reporter_data.pb.go b/api/kessel/inventory/v1beta1/relationships/reporter_data.pb.go index 8d3ad0e7..ddfa5e28 100644 --- a/api/kessel/inventory/v1beta1/relationships/reporter_data.pb.go +++ b/api/kessel/inventory/v1beta1/relationships/reporter_data.pb.go @@ -7,7 +7,7 @@ package relationships import ( - _ "github.com/envoyproxy/protoc-gen-validate/validate" + _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" _ "google.golang.org/genproto/googleapis/api/annotations" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -198,59 +198,59 @@ var file_kessel_inventory_v1beta1_relationships_reporter_data_proto_rawDesc = [] 0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x62, 0x65, 0x68, 0x61, 0x76, 0x69, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, - 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, - 0x87, 0x05, 0x0a, 0x0c, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, - 0x12, 0x75, 0x0a, 0x0d, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x74, 0x79, 0x70, - 0x65, 0x18, 0xd9, 0x8f, 0x99, 0x75, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x41, 0x2e, 0x6b, 0x65, 0x73, - 0x73, 0x65, 0x6c, 0x2e, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x2e, 0x76, 0x31, - 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x68, - 0x69, 0x70, 0x73, 0x2e, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, - 0x2e, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x42, 0x0a, 0xfa, - 0x42, 0x07, 0x82, 0x01, 0x04, 0x10, 0x01, 0x20, 0x00, 0x52, 0x0c, 0x72, 0x65, 0x70, 0x6f, 0x72, - 0x74, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x38, 0x0a, 0x14, 0x72, 0x65, 0x70, 0x6f, 0x72, - 0x74, 0x65, 0x72, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, - 0xba, 0xd5, 0xfa, 0x72, 0x20, 0x01, 0x28, 0x09, 0x42, 0x03, 0xe0, 0x41, 0x03, 0x52, 0x12, 0x72, - 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, - 0x64, 0x12, 0x2d, 0x0a, 0x10, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x76, 0x65, - 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0xfb, 0xee, 0xc8, 0x80, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0f, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, - 0x12, 0x49, 0x0a, 0x0e, 0x66, 0x69, 0x72, 0x73, 0x74, 0x5f, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, - 0x65, 0x64, 0x18, 0x81, 0xed, 0xce, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, + 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x88, 0x05, 0x0a, 0x0c, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, + 0x44, 0x61, 0x74, 0x61, 0x12, 0x76, 0x0a, 0x0d, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, + 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0xd9, 0x8f, 0x99, 0x75, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x41, + 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, + 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x68, 0x69, 0x70, 0x73, 0x2e, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, + 0x44, 0x61, 0x74, 0x61, 0x2e, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x54, 0x79, 0x70, + 0x65, 0x42, 0x0b, 0xba, 0x48, 0x08, 0x82, 0x01, 0x05, 0x10, 0x01, 0x22, 0x01, 0x00, 0x52, 0x0c, + 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x38, 0x0a, 0x14, + 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, + 0x65, 0x5f, 0x69, 0x64, 0x18, 0xba, 0xd5, 0xfa, 0x72, 0x20, 0x01, 0x28, 0x09, 0x42, 0x03, 0xe0, + 0x41, 0x03, 0x52, 0x12, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x49, 0x6e, 0x73, 0x74, + 0x61, 0x6e, 0x63, 0x65, 0x49, 0x64, 0x12, 0x2d, 0x0a, 0x10, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, + 0x65, 0x72, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0xfb, 0xee, 0xc8, 0x80, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x56, 0x65, + 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x49, 0x0a, 0x0e, 0x66, 0x69, 0x72, 0x73, 0x74, 0x5f, 0x72, + 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x18, 0x81, 0xed, 0xce, 0x06, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x42, 0x03, 0xe0, 0x41, + 0x03, 0x52, 0x0d, 0x66, 0x69, 0x72, 0x73, 0x74, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, + 0x12, 0x48, 0x0a, 0x0d, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, + 0x64, 0x18, 0x8c, 0x9d, 0x90, 0xd0, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, - 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x42, 0x03, 0xe0, 0x41, 0x03, 0x52, 0x0d, 0x66, 0x69, - 0x72, 0x73, 0x74, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x12, 0x48, 0x0a, 0x0d, 0x6c, - 0x61, 0x73, 0x74, 0x5f, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x18, 0x8c, 0x9d, 0x90, - 0xd0, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, - 0x6d, 0x70, 0x42, 0x03, 0xe0, 0x41, 0x03, 0x52, 0x0c, 0x6c, 0x61, 0x73, 0x74, 0x52, 0x65, 0x70, - 0x6f, 0x72, 0x74, 0x65, 0x64, 0x12, 0x46, 0x0a, 0x19, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, - 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, - 0x69, 0x64, 0x18, 0xbe, 0xb8, 0xd9, 0xf2, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xfa, 0x42, - 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x16, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x6f, - 0x63, 0x61, 0x6c, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x12, 0x44, 0x0a, - 0x18, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x72, 0x65, - 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0xbf, 0xb8, 0xd9, 0xf2, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x15, 0x6f, 0x62, - 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, - 0x65, 0x49, 0x64, 0x22, 0x74, 0x0a, 0x0c, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x54, - 0x79, 0x70, 0x65, 0x12, 0x1d, 0x0a, 0x19, 0x52, 0x45, 0x50, 0x4f, 0x52, 0x54, 0x45, 0x52, 0x5f, - 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, - 0x10, 0x00, 0x12, 0x17, 0x0a, 0x13, 0x52, 0x45, 0x50, 0x4f, 0x52, 0x54, 0x45, 0x52, 0x5f, 0x54, - 0x59, 0x50, 0x45, 0x5f, 0x4f, 0x54, 0x48, 0x45, 0x52, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x41, - 0x43, 0x4d, 0x10, 0x02, 0x12, 0x07, 0x0a, 0x03, 0x48, 0x42, 0x49, 0x10, 0x03, 0x12, 0x07, 0x0a, - 0x03, 0x4f, 0x43, 0x4d, 0x10, 0x04, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x4f, 0x54, 0x49, 0x46, 0x49, - 0x43, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0x10, 0x05, 0x42, 0x8e, 0x01, 0x0a, 0x36, 0x6f, 0x72, - 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, - 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x2e, 0x76, - 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x68, 0x69, 0x70, 0x73, 0x50, 0x01, 0x5a, 0x52, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2d, 0x6b, 0x65, 0x73, 0x73, 0x65, - 0x6c, 0x2f, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x2d, 0x61, 0x70, 0x69, 0x2f, - 0x61, 0x70, 0x69, 0x2f, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2f, 0x69, 0x6e, 0x76, 0x65, 0x6e, - 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x72, 0x65, 0x6c, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x68, 0x69, 0x70, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x42, 0x03, 0xe0, 0x41, 0x03, 0x52, 0x0c, 0x6c, 0x61, + 0x73, 0x74, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x12, 0x46, 0x0a, 0x19, 0x73, 0x75, + 0x62, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x72, 0x65, 0x73, 0x6f, + 0x75, 0x72, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0xbe, 0xb8, 0xd9, 0xf2, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x16, 0x73, 0x75, 0x62, 0x6a, + 0x65, 0x63, 0x74, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, + 0x49, 0x64, 0x12, 0x44, 0x0a, 0x18, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x5f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0xbf, + 0xb8, 0xd9, 0xf2, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xba, 0x48, 0x04, 0x72, 0x02, 0x10, + 0x01, 0x52, 0x15, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x52, 0x65, + 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x22, 0x74, 0x0a, 0x0c, 0x52, 0x65, 0x70, 0x6f, + 0x72, 0x74, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1d, 0x0a, 0x19, 0x52, 0x45, 0x50, 0x4f, + 0x52, 0x54, 0x45, 0x52, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, + 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x17, 0x0a, 0x13, 0x52, 0x45, 0x50, 0x4f, 0x52, + 0x54, 0x45, 0x52, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x4f, 0x54, 0x48, 0x45, 0x52, 0x10, 0x01, + 0x12, 0x07, 0x0a, 0x03, 0x41, 0x43, 0x4d, 0x10, 0x02, 0x12, 0x07, 0x0a, 0x03, 0x48, 0x42, 0x49, + 0x10, 0x03, 0x12, 0x07, 0x0a, 0x03, 0x4f, 0x43, 0x4d, 0x10, 0x04, 0x12, 0x11, 0x0a, 0x0d, 0x4e, + 0x4f, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0x10, 0x05, 0x42, 0x8e, + 0x01, 0x0a, 0x36, 0x6f, 0x72, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x6b, + 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, + 0x6f, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x72, 0x65, 0x6c, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x68, 0x69, 0x70, 0x73, 0x50, 0x01, 0x5a, 0x52, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2d, + 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2f, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, + 0x2d, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2f, + 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, + 0x31, 0x2f, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x68, 0x69, 0x70, 0x73, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/kessel/inventory/v1beta1/relationships/reporter_data.pb.validate.go b/api/kessel/inventory/v1beta1/relationships/reporter_data.pb.validate.go deleted file mode 100644 index 62174aaa..00000000 --- a/api/kessel/inventory/v1beta1/relationships/reporter_data.pb.validate.go +++ /dev/null @@ -1,245 +0,0 @@ -// Code generated by protoc-gen-validate. DO NOT EDIT. -// source: kessel/inventory/v1beta1/relationships/reporter_data.proto - -package relationships - -import ( - "bytes" - "errors" - "fmt" - "net" - "net/mail" - "net/url" - "regexp" - "sort" - "strings" - "time" - "unicode/utf8" - - "google.golang.org/protobuf/types/known/anypb" -) - -// ensure the imports are used -var ( - _ = bytes.MinRead - _ = errors.New("") - _ = fmt.Print - _ = utf8.UTFMax - _ = (*regexp.Regexp)(nil) - _ = (*strings.Reader)(nil) - _ = net.IPv4len - _ = time.Duration(0) - _ = (*url.URL)(nil) - _ = (*mail.Address)(nil) - _ = anypb.Any{} - _ = sort.Sort -) - -// Validate checks the field values on ReporterData with the rules defined in -// the proto definition for this message. If any rules are violated, the first -// error encountered is returned, or nil if there are no violations. -func (m *ReporterData) Validate() error { - return m.validate(false) -} - -// ValidateAll checks the field values on ReporterData with the rules defined -// in the proto definition for this message. If any rules are violated, the -// result is a list of violation errors wrapped in ReporterDataMultiError, or -// nil if none found. -func (m *ReporterData) ValidateAll() error { - return m.validate(true) -} - -func (m *ReporterData) validate(all bool) error { - if m == nil { - return nil - } - - var errors []error - - if _, ok := _ReporterData_ReporterType_NotInLookup[m.GetReporterType()]; ok { - err := ReporterDataValidationError{ - field: "ReporterType", - reason: "value must not be in list [REPORTER_TYPE_UNSPECIFIED]", - } - if !all { - return err - } - errors = append(errors, err) - } - - if _, ok := ReporterData_ReporterType_name[int32(m.GetReporterType())]; !ok { - err := ReporterDataValidationError{ - field: "ReporterType", - reason: "value must be one of the defined enum values", - } - if !all { - return err - } - errors = append(errors, err) - } - - // no validation rules for ReporterInstanceId - - // no validation rules for ReporterVersion - - if all { - switch v := interface{}(m.GetFirstReported()).(type) { - case interface{ ValidateAll() error }: - if err := v.ValidateAll(); err != nil { - errors = append(errors, ReporterDataValidationError{ - field: "FirstReported", - reason: "embedded message failed validation", - cause: err, - }) - } - case interface{ Validate() error }: - if err := v.Validate(); err != nil { - errors = append(errors, ReporterDataValidationError{ - field: "FirstReported", - reason: "embedded message failed validation", - cause: err, - }) - } - } - } else if v, ok := interface{}(m.GetFirstReported()).(interface{ Validate() error }); ok { - if err := v.Validate(); err != nil { - return ReporterDataValidationError{ - field: "FirstReported", - reason: "embedded message failed validation", - cause: err, - } - } - } - - if all { - switch v := interface{}(m.GetLastReported()).(type) { - case interface{ ValidateAll() error }: - if err := v.ValidateAll(); err != nil { - errors = append(errors, ReporterDataValidationError{ - field: "LastReported", - reason: "embedded message failed validation", - cause: err, - }) - } - case interface{ Validate() error }: - if err := v.Validate(); err != nil { - errors = append(errors, ReporterDataValidationError{ - field: "LastReported", - reason: "embedded message failed validation", - cause: err, - }) - } - } - } else if v, ok := interface{}(m.GetLastReported()).(interface{ Validate() error }); ok { - if err := v.Validate(); err != nil { - return ReporterDataValidationError{ - field: "LastReported", - reason: "embedded message failed validation", - cause: err, - } - } - } - - if utf8.RuneCountInString(m.GetSubjectLocalResourceId()) < 1 { - err := ReporterDataValidationError{ - field: "SubjectLocalResourceId", - reason: "value length must be at least 1 runes", - } - if !all { - return err - } - errors = append(errors, err) - } - - if utf8.RuneCountInString(m.GetObjectLocalResourceId()) < 1 { - err := ReporterDataValidationError{ - field: "ObjectLocalResourceId", - reason: "value length must be at least 1 runes", - } - if !all { - return err - } - errors = append(errors, err) - } - - if len(errors) > 0 { - return ReporterDataMultiError(errors) - } - - return nil -} - -// ReporterDataMultiError is an error wrapping multiple validation errors -// returned by ReporterData.ValidateAll() if the designated constraints aren't met. -type ReporterDataMultiError []error - -// Error returns a concatenation of all the error messages it wraps. -func (m ReporterDataMultiError) Error() string { - var msgs []string - for _, err := range m { - msgs = append(msgs, err.Error()) - } - return strings.Join(msgs, "; ") -} - -// AllErrors returns a list of validation violation errors. -func (m ReporterDataMultiError) AllErrors() []error { return m } - -// ReporterDataValidationError is the validation error returned by -// ReporterData.Validate if the designated constraints aren't met. -type ReporterDataValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e ReporterDataValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e ReporterDataValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e ReporterDataValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e ReporterDataValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e ReporterDataValidationError) ErrorName() string { return "ReporterDataValidationError" } - -// Error satisfies the builtin error interface -func (e ReporterDataValidationError) Error() string { - cause := "" - if e.cause != nil { - cause = fmt.Sprintf(" | caused by: %v", e.cause) - } - - key := "" - if e.key { - key = "key for " - } - - return fmt.Sprintf( - "invalid %sReporterData.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = ReporterDataValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = ReporterDataValidationError{} - -var _ReporterData_ReporterType_NotInLookup = map[ReporterData_ReporterType]struct{}{ - 0: {}, -} diff --git a/api/kessel/inventory/v1beta1/relationships/reporter_data.proto b/api/kessel/inventory/v1beta1/relationships/reporter_data.proto index 9e3cdc8c..5b00cfac 100644 --- a/api/kessel/inventory/v1beta1/relationships/reporter_data.proto +++ b/api/kessel/inventory/v1beta1/relationships/reporter_data.proto @@ -4,7 +4,7 @@ package kessel.inventory.v1beta1.relationships; import "google/api/field_behavior.proto"; import "google/protobuf/timestamp.proto"; -import "validate/validate.proto"; +import "buf/validate/validate.proto"; option go_package = "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1/relationships"; option java_multiple_files = true; @@ -21,7 +21,7 @@ message ReporterData { NOTIFICATIONS = 5; } - ReporterType reporter_type = 245778393 [ (validate.rules).enum = {not_in: [0], defined_only: true} ]; + ReporterType reporter_type = 245778393 [ (buf.validate.field).enum = {not_in: [0], defined_only: true} ]; // The ID of the instance of the reporter. This is derived from the // authentication mechanism, i.e. authentication token. @@ -41,9 +41,9 @@ message ReporterData { // The ID assigned by the reporter to resource which is the subject of the relationship. For example // OCM cluster ID, HBI's host id, or ACM managed cluster name etc. - string subject_local_resource_id = 508976190 [ (validate.rules).string.min_len = 1 ]; + string subject_local_resource_id = 508976190 [ (buf.validate.field).string.min_len = 1 ]; // The ID assigned by the reporter to resource which is the object of the relationship. For example // OCM cluster ID, HBI's host id, or ACM managed cluster name etc. - string object_local_resource_id = 508976191 [ (validate.rules).string.min_len = 1 ]; + string object_local_resource_id = 508976191 [ (buf.validate.field).string.min_len = 1 ]; } diff --git a/api/kessel/inventory/v1beta1/resources/k8s_cluster_detail_nodes_inner.pb.validate_test.go b/api/kessel/inventory/v1beta1/resources/k8s_cluster_detail_nodes_inner.pb.validate_test.go deleted file mode 100644 index 4ec924aa..00000000 --- a/api/kessel/inventory/v1beta1/resources/k8s_cluster_detail_nodes_inner.pb.validate_test.go +++ /dev/null @@ -1,118 +0,0 @@ -package resources - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestK8SClusterDetailNodesInnerValidatesSuccessfullyWithValidData(t *testing.T) { - node := &K8SClusterDetailNodesInner{ - Name: "ip-10-0-0-1.ec2.internal", - Cpu: "7500m", - Memory: "30973224Ki", - Labels: []*ResourceLabel{ - { - Key: "node.openshift.io/os_id", - Value: "rhcos", - }, - }, - } - err := node.ValidateAll() - assert.NoError(t, err) -} - -func TestK8SClusterDetailNodesInnerValidationFailsWithEmptyName(t *testing.T) { - node := &K8SClusterDetailNodesInner{ - Name: "", - Cpu: "7500m", - Memory: "30973224Ki", - Labels: []*ResourceLabel{ - { - Key: "node.openshift.io/os_id", - Value: "rhcos", - }, - }, - } - err := node.ValidateAll() - assert.ErrorContains(t, err, "invalid K8SClusterDetailNodesInner.Name: value length must be at least 1 runes") -} - -func TestK8SClusterDetailNodesInnerValidationFailsWithEmptyCpu(t *testing.T) { - node := &K8SClusterDetailNodesInner{ - Name: "ip-10-0-0-1.ec2.internal", - Cpu: "", - Memory: "30973224Ki", - Labels: []*ResourceLabel{ - { - Key: "node.openshift.io/os_id", - Value: "rhcos", - }, - }, - } - err := node.ValidateAll() - assert.ErrorContains(t, err, "invalid K8SClusterDetailNodesInner.Cpu: value length must be at least 1 runes") -} - -func TestK8SClusterDetailNodesInnerValidationFailsWithEmptyMemory(t *testing.T) { - node := &K8SClusterDetailNodesInner{ - Name: "ip-10-0-0-1.ec2.internal", - Cpu: "7500m", - Memory: "", - Labels: []*ResourceLabel{ - { - Key: "node.openshift.io/os_id", - Value: "rhcos", - }, - }, - } - err := node.ValidateAll() - assert.ErrorContains(t, err, "invalid K8SClusterDetailNodesInner.Memory: value length must be at least 1 runes") -} - -func TestK8SClusterDetailNodesInnerValidationFailsWithNilLabel(t *testing.T) { - node := &K8SClusterDetailNodesInner{ - Name: "ip-10-0-0-1.ec2.internal", - Cpu: "7500m", - Memory: "30973224Ki", - Labels: []*ResourceLabel{ - nil, - }, - } - err := node.ValidateAll() - assert.ErrorContains(t, err, "invalid K8SClusterDetailNodesInner.Labels[0]: value is required") -} - -func TestK8SClusterDetailNodesInnerValidationFailsWithInvalidLabel(t *testing.T) { - node := &K8SClusterDetailNodesInner{ - Name: "ip-10-0-0-1.ec2.internal", - Cpu: "7500m", - Memory: "30973224Ki", - Labels: []*ResourceLabel{ - { - Key: "", - Value: "rhcos", - }, - }, - } - err := node.ValidateAll() - assert.ErrorContains(t, err, "invalid K8SClusterDetailNodesInner.Labels[0]: embedded message failed validation") -} - -var multipleErrorMessage = "invalid K8SClusterDetailNodesInner.Name: value length must be at least 1 runes; " + - "invalid K8SClusterDetailNodesInner.Cpu: value length must be at least 1 runes; " + - "invalid K8SClusterDetailNodesInner.Memory: value length must be at least 1 runes; " + - "invalid K8SClusterDetailNodesInner.Labels[0]: value is required" - -func TestK8SClusterDetailNodesInnerValidationWithMultipleErrors(t *testing.T) { - node := &K8SClusterDetailNodesInner{ - Name: "", - Cpu: "", - Memory: "", - Labels: []*ResourceLabel{nil}, - } - - err := node.ValidateAll() - assert.ErrorContains(t, err, multipleErrorMessage) - -} diff --git a/api/kessel/inventory/v1beta1/resources/k8s_policy.pb.validate_test.go b/api/kessel/inventory/v1beta1/resources/k8s_policy.pb.validate_test.go deleted file mode 100644 index 9b6295bb..00000000 --- a/api/kessel/inventory/v1beta1/resources/k8s_policy.pb.validate_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package resources - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestK8SPolicyValidatesSuccessfullyWithValidData(t *testing.T) { - policy := K8SPolicy{ - Metadata: &Metadata{}, - ReporterData: &ReporterData{ - ReporterInstanceId: "reporter-id", - ReporterType: 1, //ACM - ConsoleHref: "https://example.com/console", - ApiHref: "https://example.com/api", - LocalResourceId: "local-resource-id", - ReporterVersion: "2.12"}, - ResourceData: &K8SPolicyDetail{}, - } - err := policy.ValidateAll() - assert.NoError(t, err) -} - -func TestK8SPolicyValidationFailsWithMissingReporterData(t *testing.T) { - policy := K8SPolicy{ - Metadata: &Metadata{}, - - ResourceData: &K8SPolicyDetail{}, - } - err := policy.ValidateAll() - assert.ErrorContains(t, err, "Policy.ReporterData") -} - -func TestK8SPolicyValidationFailsWithMissingResourceData(t *testing.T) { - policy := K8SPolicy{ - Metadata: &Metadata{}, - ReporterData: &ReporterData{ - ReporterInstanceId: "reporter-id", - ReporterType: 1, //ACM - ConsoleHref: "https://example.com/console", - ApiHref: "https://example.com/api", - LocalResourceId: "local-resource-id", - ReporterVersion: "2.12", - }, - } - err := policy.ValidateAll() - assert.ErrorContains(t, err, "Policy.ResourceData") -} - -// Missing ReporterData and ResourceData, Policy MetaData is not required -func TestK8SPolicyValidationWithAllErrors(t *testing.T) { - policy := K8SPolicy{} - err := policy.ValidateAll() - assert.Error(t, err) - assert.Contains(t, err.Error(), "Policy.ReporterData") - assert.Contains(t, err.Error(), "Policy.ResourceData") -}