diff --git a/api/kessel/inventory/v1beta1/k8s_cluster.pb.go b/api/kessel/inventory/v1beta1/k8s_cluster.pb.go index 64f179f5..73e0d80c 100644 --- a/api/kessel/inventory/v1beta1/k8s_cluster.pb.go +++ b/api/kessel/inventory/v1beta1/k8s_cluster.pb.go @@ -7,6 +7,7 @@ package v1beta1 import ( + _ "github.com/envoyproxy/protoc-gen-validate/validate" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -92,40 +93,42 @@ var file_kessel_inventory_v1beta1_k8s_cluster_proto_rawDesc = []byte{ 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x6b, 0x38, 0x73, 0x5f, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x18, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x2e, 0x76, - 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x1a, 0x31, 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, 0x6b, 0x38, 0x73, 0x5f, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x65, 0x74, - 0x61, 0x69, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x27, 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, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x1a, 0x2c, 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, 0x70, - 0x6f, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x22, 0xf0, 0x01, 0x0a, 0x0a, 0x4b, 0x38, 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x12, - 0x3e, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x22, 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, 0x4d, 0x65, 0x74, - 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, - 0x4e, 0x0a, 0x0d, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x61, 0x74, 0x61, - 0x18, 0xc8, 0xd0, 0xfa, 0x74, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 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, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, - 0x61, 0x52, 0x0c, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, - 0x52, 0x0a, 0x0d, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x64, 0x61, 0x74, 0x61, - 0x18, 0xca, 0xc7, 0x81, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2a, 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, 0x4b, 0x38, 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x44, - 0x65, 0x74, 0x61, 0x69, 0x6c, 0x52, 0x0c, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x44, - 0x61, 0x74, 0x61, 0x42, 0x83, 0x01, 0x0a, 0x28, 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, - 0x42, 0x0f, 0x4b, 0x38, 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x50, 0x72, 0x6f, 0x74, - 0x6f, 0x50, 0x01, 0x5a, 0x44, 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, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 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, 0x1a, + 0x31, 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, 0x6b, 0x38, 0x73, 0x5f, 0x63, 0x6c, + 0x75, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x1a, 0x27, 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, 0x6d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2c, 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, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x64, + 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x84, 0x02, 0x0a, 0x0a, 0x4b, 0x38, + 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x12, 0x3e, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, + 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 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, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x08, + 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x58, 0x0a, 0x0d, 0x72, 0x65, 0x70, 0x6f, + 0x72, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0xc8, 0xd0, 0xfa, 0x74, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x26, 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, 0x52, 0x65, + 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x8a, + 0x01, 0x02, 0x10, 0x01, 0x52, 0x0c, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, + 0x74, 0x61, 0x12, 0x5c, 0x0a, 0x0d, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x64, + 0x61, 0x74, 0x61, 0x18, 0xca, 0xc7, 0x81, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2a, 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, 0x4b, 0x38, 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, + 0x65, 0x72, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x8a, 0x01, 0x02, + 0x10, 0x01, 0x52, 0x0c, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x44, 0x61, 0x74, 0x61, + 0x42, 0x83, 0x01, 0x0a, 0x28, 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, 0x42, 0x0f, 0x4b, + 0x38, 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, + 0x5a, 0x44, 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, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/kessel/inventory/v1beta1/k8s_cluster.pb.validate.go b/api/kessel/inventory/v1beta1/k8s_cluster.pb.validate.go index 7dc51eee..deb92c6f 100644 --- a/api/kessel/inventory/v1beta1/k8s_cluster.pb.validate.go +++ b/api/kessel/inventory/v1beta1/k8s_cluster.pb.validate.go @@ -86,6 +86,17 @@ func (m *K8SCluster) validate(all bool) error { } } + if m.GetReporterData() == nil { + err := K8SClusterValidationError{ + field: "ReporterData", + reason: "value is required", + } + if !all { + return err + } + errors = append(errors, err) + } + if all { switch v := interface{}(m.GetReporterData()).(type) { case interface{ ValidateAll() error }: @@ -115,6 +126,17 @@ func (m *K8SCluster) validate(all bool) error { } } + if m.GetResourceData() == nil { + err := K8SClusterValidationError{ + field: "ResourceData", + reason: "value is required", + } + if !all { + return err + } + errors = append(errors, err) + } + if all { switch v := interface{}(m.GetResourceData()).(type) { case interface{ ValidateAll() error }: diff --git a/api/kessel/inventory/v1beta1/k8s_cluster.proto b/api/kessel/inventory/v1beta1/k8s_cluster.proto index 77b9865c..5a1ef359 100644 --- a/api/kessel/inventory/v1beta1/k8s_cluster.proto +++ b/api/kessel/inventory/v1beta1/k8s_cluster.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package kessel.inventory.v1beta1; +import "validate/validate.proto"; + import "kessel/inventory/v1beta1/k8s_cluster_detail.proto"; import "kessel/inventory/v1beta1/metadata.proto"; import "kessel/inventory/v1beta1/reporter_data.proto"; @@ -16,7 +18,7 @@ message K8sCluster { Metadata metadata = 1; // Write only reporter specific data - ReporterData reporter_data = 245278792; + ReporterData reporter_data = 245278792 [ (validate.rules).message.required = true ]; - K8sClusterDetail resource_data = 2122698; + K8sClusterDetail resource_data = 2122698 [ (validate.rules).message.required = true ]; } diff --git a/api/kessel/inventory/v1beta1/k8s_cluster_detail.pb.go b/api/kessel/inventory/v1beta1/k8s_cluster_detail.pb.go index bb7dbb9a..fd977e10 100644 --- a/api/kessel/inventory/v1beta1/k8s_cluster_detail.pb.go +++ b/api/kessel/inventory/v1beta1/k8s_cluster_detail.pb.go @@ -7,6 +7,7 @@ package v1beta1 import ( + _ "github.com/envoyproxy/protoc-gen-validate/validate" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -341,44 +342,50 @@ var file_kessel_inventory_v1beta1_k8s_cluster_detail_proto_rawDesc = []byte{ 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x6b, 0x38, 0x73, 0x5f, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x18, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x69, 0x6e, 0x76, 0x65, - 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x1a, 0x3d, 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, 0x6b, 0x38, 0x73, 0x5f, 0x63, 0x6c, 0x75, 0x73, - 0x74, 0x65, 0x72, 0x5f, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x73, - 0x5f, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xc3, 0x0b, 0x0a, - 0x10, 0x4b, 0x38, 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x74, 0x61, 0x69, - 0x6c, 0x12, 0x31, 0x0a, 0x13, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x5f, 0x63, 0x6c, - 0x75, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x8d, 0xcb, 0xd9, 0x68, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x11, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x43, 0x6c, 0x75, 0x73, 0x74, - 0x65, 0x72, 0x49, 0x64, 0x12, 0x63, 0x0a, 0x0e, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x5f, - 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0xd8, 0xdb, 0x8d, 0xee, 0x01, 0x20, 0x01, 0x28, 0x0e, - 0x32, 0x38, 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, 0x4b, 0x38, 0x73, 0x43, - 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x2e, 0x43, 0x6c, 0x75, - 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x0d, 0x63, 0x6c, 0x75, 0x73, - 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x25, 0x0a, 0x0c, 0x6b, 0x75, 0x62, - 0x65, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0xba, 0xa4, 0xe1, 0xbc, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x75, 0x62, 0x65, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, - 0x12, 0x59, 0x0a, 0x0b, 0x6b, 0x75, 0x62, 0x65, 0x5f, 0x76, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x18, - 0x9a, 0xfd, 0xfc, 0x7d, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x35, 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, 0x4b, 0x38, 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, - 0x74, 0x61, 0x69, 0x6c, 0x2e, 0x4b, 0x75, 0x62, 0x65, 0x56, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x52, - 0x0a, 0x6b, 0x75, 0x62, 0x65, 0x56, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x12, 0x28, 0x0a, 0x0e, 0x76, - 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0xe3, 0xc1, - 0xb6, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x76, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x56, 0x65, - 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x63, 0x0a, 0x0e, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x5f, 0x70, - 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0xbe, 0xce, 0xab, 0xe3, 0x01, 0x20, 0x01, 0x28, - 0x0e, 0x32, 0x38, 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, 0x4b, 0x38, 0x73, - 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x2e, 0x43, 0x6c, - 0x6f, 0x75, 0x64, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x52, 0x0d, 0x63, 0x6c, 0x6f, - 0x75, 0x64, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x4d, 0x0a, 0x05, 0x6e, 0x6f, - 0x64, 0x65, 0x73, 0x18, 0x91, 0xc5, 0xfc, 0x23, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x34, 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, 0x4b, 0x38, 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, - 0x65, 0x72, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x49, 0x6e, 0x6e, - 0x65, 0x72, 0x52, 0x05, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x22, 0x80, 0x01, 0x0a, 0x0d, 0x43, 0x6c, + 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 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, 0x1a, 0x3d, 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, 0x6b, 0x38, 0x73, 0x5f, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x65, 0x74, + 0x61, 0x69, 0x6c, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x5f, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x8a, 0x0c, 0x0a, 0x10, 0x4b, 0x38, 0x73, 0x43, 0x6c, 0x75, + 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x12, 0x3a, 0x0a, 0x13, 0x65, 0x78, + 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x5f, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x69, + 0x64, 0x18, 0x8d, 0xcb, 0xd9, 0x68, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, + 0x02, 0x10, 0x01, 0x52, 0x11, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x43, 0x6c, 0x75, + 0x73, 0x74, 0x65, 0x72, 0x49, 0x64, 0x12, 0x6f, 0x0a, 0x0e, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, + 0x72, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0xd8, 0xdb, 0x8d, 0xee, 0x01, 0x20, 0x01, + 0x28, 0x0e, 0x32, 0x38, 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, 0x4b, 0x38, + 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x2e, 0x43, + 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x0a, 0xfa, 0x42, + 0x07, 0x82, 0x01, 0x04, 0x10, 0x01, 0x20, 0x00, 0x52, 0x0d, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, + 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x25, 0x0a, 0x0c, 0x6b, 0x75, 0x62, 0x65, 0x5f, + 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0xba, 0xa4, 0xe1, 0xbc, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x6b, 0x75, 0x62, 0x65, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x65, + 0x0a, 0x0b, 0x6b, 0x75, 0x62, 0x65, 0x5f, 0x76, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x18, 0x9a, 0xfd, + 0xfc, 0x7d, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x35, 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, 0x4b, 0x38, 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x74, 0x61, + 0x69, 0x6c, 0x2e, 0x4b, 0x75, 0x62, 0x65, 0x56, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x42, 0x0a, 0xfa, + 0x42, 0x07, 0x82, 0x01, 0x04, 0x10, 0x01, 0x20, 0x00, 0x52, 0x0a, 0x6b, 0x75, 0x62, 0x65, 0x56, + 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x12, 0x31, 0x0a, 0x0e, 0x76, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x5f, + 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0xe3, 0xc1, 0xb6, 0x0b, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x0d, 0x76, 0x65, 0x6e, 0x64, 0x6f, + 0x72, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x6f, 0x0a, 0x0e, 0x63, 0x6c, 0x6f, 0x75, + 0x64, 0x5f, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0xbe, 0xce, 0xab, 0xe3, 0x01, + 0x20, 0x01, 0x28, 0x0e, 0x32, 0x38, 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, + 0x4b, 0x38, 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, + 0x2e, 0x43, 0x6c, 0x6f, 0x75, 0x64, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x42, 0x0a, + 0xfa, 0x42, 0x07, 0x82, 0x01, 0x04, 0x10, 0x01, 0x20, 0x00, 0x52, 0x0d, 0x63, 0x6c, 0x6f, 0x75, + 0x64, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x5e, 0x0a, 0x05, 0x6e, 0x6f, 0x64, + 0x65, 0x73, 0x18, 0x91, 0xc5, 0xfc, 0x23, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x34, 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, 0x4b, 0x38, 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, + 0x72, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x49, 0x6e, 0x6e, 0x65, + 0x72, 0x42, 0x0f, 0xfa, 0x42, 0x0c, 0x92, 0x01, 0x09, 0x08, 0x01, 0x22, 0x05, 0x8a, 0x01, 0x02, + 0x10, 0x01, 0x52, 0x05, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x22, 0x80, 0x01, 0x0a, 0x0d, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, 0x0a, 0x1a, 0x43, 0x4c, 0x55, 0x53, 0x54, 0x45, 0x52, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x18, 0x0a, 0x14, 0x43, diff --git a/api/kessel/inventory/v1beta1/k8s_cluster_detail.pb.validate.go b/api/kessel/inventory/v1beta1/k8s_cluster_detail.pb.validate.go index 02ff606c..80672a45 100644 --- a/api/kessel/inventory/v1beta1/k8s_cluster_detail.pb.validate.go +++ b/api/kessel/inventory/v1beta1/k8s_cluster_detail.pb.validate.go @@ -57,21 +57,121 @@ func (m *K8SClusterDetail) validate(all bool) error { var errors []error - // no validation rules for ExternalClusterId + if utf8.RuneCountInString(m.GetExternalClusterId()) < 1 { + err := K8SClusterDetailValidationError{ + field: "ExternalClusterId", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } - // no validation rules for ClusterStatus + if _, ok := _K8SClusterDetail_ClusterStatus_NotInLookup[m.GetClusterStatus()]; ok { + err := K8SClusterDetailValidationError{ + field: "ClusterStatus", + reason: "value must not be in list [CLUSTER_STATUS_UNSPECIFIED]", + } + if !all { + return err + } + errors = append(errors, err) + } + + if _, ok := K8SClusterDetail_ClusterStatus_name[int32(m.GetClusterStatus())]; !ok { + err := K8SClusterDetailValidationError{ + field: "ClusterStatus", + reason: "value must be one of the defined enum values", + } + if !all { + return err + } + errors = append(errors, err) + } // no validation rules for KubeVersion - // no validation rules for KubeVendor + if _, ok := _K8SClusterDetail_KubeVendor_NotInLookup[m.GetKubeVendor()]; ok { + err := K8SClusterDetailValidationError{ + field: "KubeVendor", + reason: "value must not be in list [KUBE_VENDOR_UNSPECIFIED]", + } + if !all { + return err + } + errors = append(errors, err) + } - // no validation rules for VendorVersion + if _, ok := K8SClusterDetail_KubeVendor_name[int32(m.GetKubeVendor())]; !ok { + err := K8SClusterDetailValidationError{ + field: "KubeVendor", + reason: "value must be one of the defined enum values", + } + if !all { + return err + } + errors = append(errors, err) + } - // no validation rules for CloudPlatform + if utf8.RuneCountInString(m.GetVendorVersion()) < 1 { + err := K8SClusterDetailValidationError{ + field: "VendorVersion", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } + + if _, ok := _K8SClusterDetail_CloudPlatform_NotInLookup[m.GetCloudPlatform()]; ok { + err := K8SClusterDetailValidationError{ + field: "CloudPlatform", + reason: "value must not be in list [CLOUD_PLATFORM_UNSPECIFIED]", + } + if !all { + return err + } + errors = append(errors, err) + } + + if _, ok := K8SClusterDetail_CloudPlatform_name[int32(m.GetCloudPlatform())]; !ok { + err := K8SClusterDetailValidationError{ + field: "CloudPlatform", + reason: "value must be one of the defined enum values", + } + if !all { + return err + } + errors = append(errors, err) + } + + if len(m.GetNodes()) < 1 { + err := K8SClusterDetailValidationError{ + field: "Nodes", + reason: "value must contain at least 1 item(s)", + } + if !all { + return err + } + errors = append(errors, err) + } for idx, item := range m.GetNodes() { _, _ = idx, item + if item == nil { + err := K8SClusterDetailValidationError{ + field: fmt.Sprintf("Nodes[%v]", idx), + reason: "value is required", + } + if !all { + return err + } + errors = append(errors, err) + } + if all { switch v := interface{}(item).(type) { case interface{ ValidateAll() error }: @@ -180,3 +280,15 @@ var _ interface { Cause() error ErrorName() string } = K8SClusterDetailValidationError{} + +var _K8SClusterDetail_ClusterStatus_NotInLookup = map[K8SClusterDetail_ClusterStatus]struct{}{ + 0: {}, +} + +var _K8SClusterDetail_KubeVendor_NotInLookup = map[K8SClusterDetail_KubeVendor]struct{}{ + 0: {}, +} + +var _K8SClusterDetail_CloudPlatform_NotInLookup = map[K8SClusterDetail_CloudPlatform]struct{}{ + 0: {}, +} diff --git a/api/kessel/inventory/v1beta1/k8s_cluster_detail.proto b/api/kessel/inventory/v1beta1/k8s_cluster_detail.proto index 785b12f3..3d7ff12f 100644 --- a/api/kessel/inventory/v1beta1/k8s_cluster_detail.proto +++ b/api/kessel/inventory/v1beta1/k8s_cluster_detail.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package kessel.inventory.v1beta1; +import "validate/validate.proto"; + import "kessel/inventory/v1beta1/k8s_cluster_detail_nodes_inner.proto"; option go_package = "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1"; @@ -55,19 +57,19 @@ message K8sClusterDetail { } // The OCP cluster ID or ARN etc for *KS - string external_cluster_id = 219571597; + string external_cluster_id = 219571597 [ (validate.rules).string.min_len = 1 ]; - ClusterStatus cluster_status = 499346904; + ClusterStatus cluster_status = 499346904 [ (validate.rules).enum = {not_in: [0], defined_only: true} ]; // The version of kubernetes string kube_version = 395858490; - KubeVendor kube_vendor = 264191642; + KubeVendor kube_vendor = 264191642 [ (validate.rules).enum = {not_in: [0], defined_only: true} ]; // The version of the productized kubernetes distribution - string vendor_version = 23961827; + string vendor_version = 23961827 [ (validate.rules).string.min_len = 1 ]; - CloudPlatform cloud_platform = 476768062; + CloudPlatform cloud_platform = 476768062 [ (validate.rules).enum = {not_in: [0], defined_only: true} ]; - repeated K8sClusterDetailNodesInner nodes = 75440785; + repeated K8sClusterDetailNodesInner nodes = 75440785 [ (validate.rules).repeated = {min_items: 1, items: { message: { required: true}}} ]; } diff --git a/api/kessel/inventory/v1beta1/k8s_cluster_detail_nodes_inner.pb.go b/api/kessel/inventory/v1beta1/k8s_cluster_detail_nodes_inner.pb.go index f2b145bf..cd1db1d6 100644 --- a/api/kessel/inventory/v1beta1/k8s_cluster_detail_nodes_inner.pb.go +++ b/api/kessel/inventory/v1beta1/k8s_cluster_detail_nodes_inner.pb.go @@ -7,6 +7,7 @@ package v1beta1 import ( + _ "github.com/envoyproxy/protoc-gen-validate/validate" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -33,6 +34,7 @@ type K8SClusterDetailNodesInner struct { Memory string `protobuf:"bytes,4014849,opt,name=memory,proto3" json:"memory,omitempty"` // Map of string keys and string values that can be used to organize and // categorize (scope and select) resources + // Todo: Do we require at least 1 label? Labels []*ResourceLabel `protobuf:"bytes,36675587,rep,name=labels,proto3" json:"labels,omitempty"` } @@ -104,30 +106,35 @@ var file_kessel_inventory_v1beta1_k8s_cluster_detail_nodes_inner_proto_rawDesc = 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x5f, 0x69, 0x6e, 0x6e, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x18, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, - 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x1a, 0x2d, 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, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x6c, 0x61, 0x62, - 0x65, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa6, 0x01, 0x0a, 0x1a, 0x4b, 0x38, 0x73, - 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x4e, 0x6f, 0x64, - 0x65, 0x73, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x15, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, - 0x8b, 0xf5, 0xcd, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, - 0x0a, 0x03, 0x63, 0x70, 0x75, 0x18, 0xa8, 0x83, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x63, - 0x70, 0x75, 0x12, 0x19, 0x0a, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x18, 0x81, 0x86, 0xf5, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x12, 0x42, 0x0a, - 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x18, 0x83, 0xc0, 0xbe, 0x11, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x27, 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, 0x52, 0x65, 0x73, 0x6f, - 0x75, 0x72, 0x63, 0x65, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x52, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, - 0x73, 0x42, 0x93, 0x01, 0x0a, 0x28, 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, 0x42, 0x1f, - 0x4b, 0x38, 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, - 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, - 0x01, 0x5a, 0x44, 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, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 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, 0x1a, 0x2d, 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, 0x73, + 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x22, 0xd0, 0x01, 0x0a, 0x1a, 0x4b, 0x38, 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, + 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x49, 0x6e, 0x6e, 0x65, 0x72, + 0x12, 0x1e, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x8b, 0xf5, 0xcd, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x12, 0x1b, 0x0a, 0x03, 0x63, 0x70, 0x75, 0x18, 0xa8, 0x83, 0x06, 0x20, 0x01, 0x28, 0x09, 0x42, + 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x03, 0x63, 0x70, 0x75, 0x12, 0x22, 0x0a, + 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x18, 0x81, 0x86, 0xf5, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, + 0x79, 0x12, 0x51, 0x0a, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x18, 0x83, 0xc0, 0xbe, 0x11, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 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, + 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x42, 0x0d, 0xfa, + 0x42, 0x0a, 0x92, 0x01, 0x07, 0x22, 0x05, 0x8a, 0x01, 0x02, 0x10, 0x01, 0x52, 0x06, 0x6c, 0x61, + 0x62, 0x65, 0x6c, 0x73, 0x42, 0x93, 0x01, 0x0a, 0x28, 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, 0x42, 0x1f, 0x4b, 0x38, 0x73, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x44, 0x65, 0x74, + 0x61, 0x69, 0x6c, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x49, 0x6e, 0x6e, 0x65, 0x72, 0x50, 0x72, 0x6f, + 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x44, 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, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( diff --git a/api/kessel/inventory/v1beta1/k8s_cluster_detail_nodes_inner.pb.validate.go b/api/kessel/inventory/v1beta1/k8s_cluster_detail_nodes_inner.pb.validate.go index 3a9ed0d1..c6222f7c 100644 --- a/api/kessel/inventory/v1beta1/k8s_cluster_detail_nodes_inner.pb.validate.go +++ b/api/kessel/inventory/v1beta1/k8s_cluster_detail_nodes_inner.pb.validate.go @@ -57,15 +57,53 @@ func (m *K8SClusterDetailNodesInner) validate(all bool) error { var errors []error - // no validation rules for Name + if utf8.RuneCountInString(m.GetName()) < 1 { + err := K8SClusterDetailNodesInnerValidationError{ + field: "Name", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } - // no validation rules for Cpu + if utf8.RuneCountInString(m.GetCpu()) < 1 { + err := K8SClusterDetailNodesInnerValidationError{ + field: "Cpu", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } - // no validation rules for Memory + if utf8.RuneCountInString(m.GetMemory()) < 1 { + err := K8SClusterDetailNodesInnerValidationError{ + field: "Memory", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } for idx, item := range m.GetLabels() { _, _ = idx, item + if item == nil { + err := K8SClusterDetailNodesInnerValidationError{ + field: fmt.Sprintf("Labels[%v]", idx), + reason: "value is required", + } + if !all { + return err + } + errors = append(errors, err) + } + if all { switch v := interface{}(item).(type) { case interface{ ValidateAll() error }: diff --git a/api/kessel/inventory/v1beta1/k8s_cluster_detail_nodes_inner.proto b/api/kessel/inventory/v1beta1/k8s_cluster_detail_nodes_inner.proto index e5087c9b..fe1b0077 100644 --- a/api/kessel/inventory/v1beta1/k8s_cluster_detail_nodes_inner.proto +++ b/api/kessel/inventory/v1beta1/k8s_cluster_detail_nodes_inner.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package kessel.inventory.v1beta1; +import "validate/validate.proto"; + import "kessel/inventory/v1beta1/resource_label.proto"; option go_package = "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1"; @@ -12,15 +14,16 @@ option java_outer_classname = "K8sClusterDetailNodesInnerProto"; message K8sClusterDetailNodesInner { // The name of the node (this can contain private info) - string name = 3373707; + string name = 3373707 [ (validate.rules).string.min_len = 1 ]; // CPU Capacity of the node defined in CPU units, e.g. \"0.5\" - string cpu = 98728; + string cpu = 98728 [ (validate.rules).string.min_len = 1 ]; // Memory Capacity of the node defined as MiB, e.g. \"50Mi\" - string memory = 4014849; + string memory = 4014849 [ (validate.rules).string.min_len = 1 ]; // Map of string keys and string values that can be used to organize and // categorize (scope and select) resources - repeated ResourceLabel labels = 36675587; + // Todo: Do we require at least 1 label? + repeated ResourceLabel labels = 36675587 [ (validate.rules).repeated.items.message.required = true ]; } diff --git a/api/kessel/inventory/v1beta1/metadata.pb.validate_test.go b/api/kessel/inventory/v1beta1/metadata.pb.validate_test.go new file mode 100644 index 00000000..bf3e3f43 --- /dev/null +++ b/api/kessel/inventory/v1beta1/metadata.pb.validate_test.go @@ -0,0 +1,33 @@ +package v1beta1 + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestMetadataValid(t *testing.T) { + meta := Metadata{} + err := meta.ValidateAll() + + assert.NoError(t, err) +} + +func TestMetadataEmptyLabels(t *testing.T) { + meta := Metadata{ + Labels: []*ResourceLabel{}, + } + + err := meta.ValidateAll() + assert.NoError(t, err) +} + +func TestMetadataInvalidLabels(t *testing.T) { + meta := Metadata{ + Labels: []*ResourceLabel{ + {}, + }, + } + + err := meta.ValidateAll() + assert.ErrorContains(t, err, "invalid Metadata.Labels[0]") +} diff --git a/api/kessel/inventory/v1beta1/notifications_integration.pb.go b/api/kessel/inventory/v1beta1/notifications_integration.pb.go index d053cb3f..fbbbbfc6 100644 --- a/api/kessel/inventory/v1beta1/notifications_integration.pb.go +++ b/api/kessel/inventory/v1beta1/notifications_integration.pb.go @@ -31,9 +31,6 @@ type NotificationsIntegration struct { Metadata *Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` // Write only reporter specific data ReporterData *ReporterData `protobuf:"bytes,245278792,opt,name=reporter_data,json=reporterData,proto3" json:"reporter_data,omitempty"` - // The entities that registered this item in the Kessel Asset Inventory. The - // same resource may be registered by multiple reporters. - Reporters []*ReporterData `protobuf:"bytes,353323086,rep,name=reporters,proto3" json:"reporters,omitempty"` } func (x *NotificationsIntegration) Reset() { @@ -82,13 +79,6 @@ func (x *NotificationsIntegration) GetReporterData() *ReporterData { return nil } -func (x *NotificationsIntegration) GetReporters() []*ReporterData { - if x != nil { - return x.Reporters - } - return nil -} - var File_kessel_inventory_v1beta1_notifications_integration_proto protoreflect.FileDescriptor var file_kessel_inventory_v1beta1_notifications_integration_proto_rawDesc = []byte{ @@ -106,7 +96,7 @@ var file_kessel_inventory_v1beta1_notifications_integration_proto_rawDesc = []by 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2c, 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, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x86, 0x02, 0x0a, 0x18, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x69, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb7, 0x01, 0x0a, 0x18, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x49, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x3e, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x69, 0x6e, @@ -116,21 +106,16 @@ var file_kessel_inventory_v1beta1_notifications_integration_proto_rawDesc = []by 0x61, 0x74, 0x61, 0x18, 0xc8, 0xd0, 0xfa, 0x74, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 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, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, - 0x44, 0x61, 0x74, 0x61, 0x42, 0x0b, 0xe0, 0x41, 0x04, 0xfa, 0x42, 0x05, 0xa2, 0x01, 0x02, 0x08, - 0x01, 0x52, 0x0c, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, - 0x4d, 0x0a, 0x09, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x73, 0x18, 0xce, 0x90, 0xbd, - 0xa8, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x26, 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, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x42, 0x03, - 0xe0, 0x41, 0x03, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x73, 0x42, 0x72, - 0x0a, 0x28, 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, 0x50, 0x01, 0x5a, 0x44, 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, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x44, 0x61, 0x74, 0x61, 0x42, 0x0b, 0xe0, 0x41, 0x04, 0xfa, 0x42, 0x05, 0x8a, 0x01, 0x02, 0x10, + 0x01, 0x52, 0x0c, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x42, + 0x72, 0x0a, 0x28, 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, 0x50, 0x01, 0x5a, 0x44, 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, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -154,12 +139,11 @@ var file_kessel_inventory_v1beta1_notifications_integration_proto_goTypes = []an var file_kessel_inventory_v1beta1_notifications_integration_proto_depIdxs = []int32{ 1, // 0: kessel.inventory.v1beta1.NotificationsIntegration.metadata:type_name -> kessel.inventory.v1beta1.Metadata 2, // 1: kessel.inventory.v1beta1.NotificationsIntegration.reporter_data:type_name -> kessel.inventory.v1beta1.ReporterData - 2, // 2: kessel.inventory.v1beta1.NotificationsIntegration.reporters:type_name -> kessel.inventory.v1beta1.ReporterData - 3, // [3:3] is the sub-list for method output_type - 3, // [3:3] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_kessel_inventory_v1beta1_notifications_integration_proto_init() } diff --git a/api/kessel/inventory/v1beta1/notifications_integration.pb.validate.go b/api/kessel/inventory/v1beta1/notifications_integration.pb.validate.go index b5f6c800..c3a6c21d 100644 --- a/api/kessel/inventory/v1beta1/notifications_integration.pb.validate.go +++ b/api/kessel/inventory/v1beta1/notifications_integration.pb.validate.go @@ -97,42 +97,33 @@ func (m *NotificationsIntegration) validate(all bool) error { errors = append(errors, err) } - if a := m.GetReporterData(); a != nil { - - } - - for idx, item := range m.GetReporters() { - _, _ = idx, item - - if all { - switch v := interface{}(item).(type) { - case interface{ ValidateAll() error }: - if err := v.ValidateAll(); err != nil { - errors = append(errors, NotificationsIntegrationValidationError{ - field: fmt.Sprintf("Reporters[%v]", idx), - reason: "embedded message failed validation", - cause: err, - }) - } - case interface{ Validate() error }: - if err := v.Validate(); err != nil { - errors = append(errors, NotificationsIntegrationValidationError{ - field: fmt.Sprintf("Reporters[%v]", idx), - reason: "embedded message failed validation", - cause: err, - }) - } + if all { + switch v := interface{}(m.GetReporterData()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, NotificationsIntegrationValidationError{ + field: "ReporterData", + reason: "embedded message failed validation", + cause: err, + }) } - } else if v, ok := interface{}(item).(interface{ Validate() error }); ok { + case interface{ Validate() error }: if err := v.Validate(); err != nil { - return NotificationsIntegrationValidationError{ - field: fmt.Sprintf("Reporters[%v]", idx), + errors = append(errors, NotificationsIntegrationValidationError{ + field: "ReporterData", reason: "embedded message failed validation", cause: err, - } + }) + } + } + } else if v, ok := interface{}(m.GetReporterData()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return NotificationsIntegrationValidationError{ + field: "ReporterData", + reason: "embedded message failed validation", + cause: err, } } - } if len(errors) > 0 { diff --git a/api/kessel/inventory/v1beta1/notifications_integration.pb.validate_test.go b/api/kessel/inventory/v1beta1/notifications_integration.pb.validate_test.go new file mode 100644 index 00000000..e73b36ca --- /dev/null +++ b/api/kessel/inventory/v1beta1/notifications_integration.pb.validate_test.go @@ -0,0 +1,43 @@ +package v1beta1 + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestNotificationIntegrationOptionalMetadata(t *testing.T) { + notifintegration := NotificationsIntegration{ + ReporterData: &ReporterData{ + ReporterType: ReporterData_REPORTER_TYPE_OCM, + LocalResourceId: "foo", + }, + } + err := notifintegration.ValidateAll() + + assert.NoError(t, err) +} + +func TestNotificationIntegrationMetadataIsValidatedIfFound(t *testing.T) { + notifintegration := NotificationsIntegration{ + ReporterData: &ReporterData{ + ReporterType: ReporterData_REPORTER_TYPE_OCM, + LocalResourceId: "foo", + }, + Metadata: &Metadata{ + Labels: []*ResourceLabel{ + {}, + }, + }, + } + err := notifintegration.ValidateAll() + + assert.ErrorContains(t, err, "Integration.Metadata") + assert.ErrorContains(t, err, "Metadata.Labels") +} + +func TestNotificationIntegrationDataIsValidated(t *testing.T) { + host := NotificationsIntegration{} + err := host.ValidateAll() + + assert.ErrorContains(t, err, "Integration.ReporterData") +} diff --git a/api/kessel/inventory/v1beta1/notifications_integration.proto b/api/kessel/inventory/v1beta1/notifications_integration.proto index 700acc97..a561e601 100644 --- a/api/kessel/inventory/v1beta1/notifications_integration.proto +++ b/api/kessel/inventory/v1beta1/notifications_integration.proto @@ -18,10 +18,5 @@ message NotificationsIntegration { // Write only reporter specific data ReporterData reporter_data = 245278792 - [ (google.api.field_behavior) = INPUT_ONLY, (validate.rules).any.required = true ]; - - // The entities that registered this item in the Kessel Asset Inventory. The - // same resource may be registered by multiple reporters. - repeated ReporterData reporters = 353323086 - [ (google.api.field_behavior) = OUTPUT_ONLY ]; + [ (google.api.field_behavior) = INPUT_ONLY, (validate.rules).message.required = true ]; } diff --git a/api/kessel/inventory/v1beta1/policy.pb.go b/api/kessel/inventory/v1beta1/policy.pb.go index 5e0b4517..06b7bc62 100644 --- a/api/kessel/inventory/v1beta1/policy.pb.go +++ b/api/kessel/inventory/v1beta1/policy.pb.go @@ -7,6 +7,7 @@ package v1beta1 import ( + _ "github.com/envoyproxy/protoc-gen-validate/validate" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -92,37 +93,40 @@ var file_kessel_inventory_v1beta1_policy_proto_rawDesc = []byte{ 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x18, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, - 0x31, 0x1a, 0x27, 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, 0x6d, 0x65, 0x74, 0x61, - 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2c, 0x6b, 0x65, 0x73, 0x73, + 0x31, 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, 0x1a, 0x27, 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, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x5f, 0x64, 0x65, 0x74, 0x61, - 0x69, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2c, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, + 0x65, 0x74, 0x61, 0x31, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x1a, 0x2c, 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, 0x70, 0x6f, + 0x6c, 0x69, 0x63, 0x79, 0x5f, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x1a, 0x2c, 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, 0x70, 0x6f, + 0x72, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0xfc, 0x01, 0x0a, 0x06, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x3e, 0x0a, 0x08, 0x6d, 0x65, + 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 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, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, + 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x58, 0x0a, 0x0d, 0x72, 0x65, + 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0xc8, 0xd0, 0xfa, 0x74, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 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, + 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x42, 0x08, 0xfa, 0x42, + 0x05, 0x8a, 0x01, 0x02, 0x10, 0x01, 0x52, 0x0c, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, + 0x44, 0x61, 0x74, 0x61, 0x12, 0x58, 0x0a, 0x0d, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, + 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0xca, 0xc7, 0x81, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, + 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, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, + 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x8a, 0x01, 0x02, 0x10, 0x01, + 0x52, 0x0c, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x44, 0x61, 0x74, 0x61, 0x42, 0x72, + 0x0a, 0x28, 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, 0x50, 0x01, 0x5a, 0x44, 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, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x61, 0x74, 0x61, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe8, 0x01, 0x0a, 0x06, 0x50, 0x6f, 0x6c, 0x69, 0x63, - 0x79, 0x12, 0x3e, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x22, 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, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, - 0x61, 0x12, 0x4e, 0x0a, 0x0d, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x18, 0xc8, 0xd0, 0xfa, 0x74, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 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, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, - 0x61, 0x74, 0x61, 0x52, 0x0c, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, - 0x61, 0x12, 0x4e, 0x0a, 0x0d, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x18, 0xca, 0xc7, 0x81, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 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, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x44, 0x65, 0x74, - 0x61, 0x69, 0x6c, 0x52, 0x0c, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x44, 0x61, 0x74, - 0x61, 0x42, 0x72, 0x0a, 0x28, 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, 0x50, 0x01, 0x5a, - 0x44, 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, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/kessel/inventory/v1beta1/policy.pb.validate.go b/api/kessel/inventory/v1beta1/policy.pb.validate.go index 4024ca5d..4a3f385a 100644 --- a/api/kessel/inventory/v1beta1/policy.pb.validate.go +++ b/api/kessel/inventory/v1beta1/policy.pb.validate.go @@ -85,6 +85,17 @@ func (m *Policy) validate(all bool) error { } } + if m.GetReporterData() == nil { + err := PolicyValidationError{ + field: "ReporterData", + reason: "value is required", + } + if !all { + return err + } + errors = append(errors, err) + } + if all { switch v := interface{}(m.GetReporterData()).(type) { case interface{ ValidateAll() error }: @@ -114,6 +125,17 @@ func (m *Policy) validate(all bool) error { } } + if m.GetResourceData() == nil { + err := PolicyValidationError{ + field: "ResourceData", + reason: "value is required", + } + if !all { + return err + } + errors = append(errors, err) + } + if all { switch v := interface{}(m.GetResourceData()).(type) { case interface{ ValidateAll() error }: diff --git a/api/kessel/inventory/v1beta1/policy.proto b/api/kessel/inventory/v1beta1/policy.proto index bcebf04c..80f02399 100644 --- a/api/kessel/inventory/v1beta1/policy.proto +++ b/api/kessel/inventory/v1beta1/policy.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package kessel.inventory.v1beta1; +import "validate/validate.proto"; + import "kessel/inventory/v1beta1/metadata.proto"; import "kessel/inventory/v1beta1/policy_detail.proto"; import "kessel/inventory/v1beta1/reporter_data.proto"; @@ -15,7 +17,7 @@ message Policy { Metadata metadata = 1; // Write only reporter specific data - ReporterData reporter_data = 245278792; + ReporterData reporter_data = 245278792 [ (validate.rules).message.required = true ]; - PolicyDetail resource_data = 2122698; + PolicyDetail resource_data = 2122698 [ (validate.rules).message.required = true ]; } diff --git a/api/kessel/inventory/v1beta1/policy_detail.pb.go b/api/kessel/inventory/v1beta1/policy_detail.pb.go index a98b77ed..363b6c64 100644 --- a/api/kessel/inventory/v1beta1/policy_detail.pb.go +++ b/api/kessel/inventory/v1beta1/policy_detail.pb.go @@ -7,6 +7,7 @@ package v1beta1 import ( + _ "github.com/envoyproxy/protoc-gen-validate/validate" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -142,32 +143,34 @@ var file_kessel_inventory_v1beta1_policy_detail_proto_rawDesc = []byte{ 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x5f, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x18, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, - 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x22, 0x8b, 0x02, 0x0a, 0x0c, 0x50, 0x6f, 0x6c, - 0x69, 0x63, 0x79, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x12, 0x1e, 0x0a, 0x08, 0x64, 0x69, 0x73, - 0x61, 0x62, 0x6c, 0x65, 0x64, 0x18, 0xfc, 0xf4, 0x98, 0x81, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, - 0x08, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x12, 0x4f, 0x0a, 0x08, 0x73, 0x65, 0x76, - 0x65, 0x72, 0x69, 0x74, 0x79, 0x18, 0xff, 0xa5, 0xf4, 0xc0, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, - 0x2f, 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, 0x50, 0x6f, 0x6c, 0x69, 0x63, - 0x79, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x2e, 0x53, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, - 0x52, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x22, 0x89, 0x01, 0x0a, 0x08, 0x53, - 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x12, 0x18, 0x0a, 0x14, 0x53, 0x45, 0x56, 0x45, 0x52, - 0x49, 0x54, 0x59, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, - 0x00, 0x12, 0x10, 0x0a, 0x0c, 0x53, 0x45, 0x56, 0x45, 0x52, 0x49, 0x54, 0x59, 0x5f, 0x4c, 0x4f, - 0x57, 0x10, 0x01, 0x12, 0x13, 0x0a, 0x0f, 0x53, 0x45, 0x56, 0x45, 0x52, 0x49, 0x54, 0x59, 0x5f, - 0x4d, 0x45, 0x44, 0x49, 0x55, 0x4d, 0x10, 0x02, 0x12, 0x11, 0x0a, 0x0d, 0x53, 0x45, 0x56, 0x45, - 0x52, 0x49, 0x54, 0x59, 0x5f, 0x48, 0x49, 0x47, 0x48, 0x10, 0x03, 0x12, 0x15, 0x0a, 0x11, 0x53, - 0x45, 0x56, 0x45, 0x52, 0x49, 0x54, 0x59, 0x5f, 0x43, 0x52, 0x49, 0x54, 0x49, 0x43, 0x41, 0x4c, - 0x10, 0x04, 0x12, 0x12, 0x0a, 0x0e, 0x53, 0x45, 0x56, 0x45, 0x52, 0x49, 0x54, 0x59, 0x5f, 0x4f, - 0x54, 0x48, 0x45, 0x52, 0x10, 0x05, 0x42, 0x72, 0x0a, 0x28, 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, 0x50, 0x01, 0x5a, 0x44, 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, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 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, 0x95, 0x02, 0x0a, 0x0c, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x44, 0x65, 0x74, 0x61, + 0x69, 0x6c, 0x12, 0x1e, 0x0a, 0x08, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x18, 0xfc, + 0xf4, 0x98, 0x81, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, + 0x65, 0x64, 0x12, 0x59, 0x0a, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x18, 0xff, + 0xa5, 0xf4, 0xc0, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x2f, 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, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, + 0x2e, 0x53, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x82, 0x01, + 0x02, 0x10, 0x01, 0x52, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x22, 0x89, 0x01, + 0x0a, 0x08, 0x53, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x12, 0x18, 0x0a, 0x14, 0x53, 0x45, + 0x56, 0x45, 0x52, 0x49, 0x54, 0x59, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, + 0x45, 0x44, 0x10, 0x00, 0x12, 0x10, 0x0a, 0x0c, 0x53, 0x45, 0x56, 0x45, 0x52, 0x49, 0x54, 0x59, + 0x5f, 0x4c, 0x4f, 0x57, 0x10, 0x01, 0x12, 0x13, 0x0a, 0x0f, 0x53, 0x45, 0x56, 0x45, 0x52, 0x49, + 0x54, 0x59, 0x5f, 0x4d, 0x45, 0x44, 0x49, 0x55, 0x4d, 0x10, 0x02, 0x12, 0x11, 0x0a, 0x0d, 0x53, + 0x45, 0x56, 0x45, 0x52, 0x49, 0x54, 0x59, 0x5f, 0x48, 0x49, 0x47, 0x48, 0x10, 0x03, 0x12, 0x15, + 0x0a, 0x11, 0x53, 0x45, 0x56, 0x45, 0x52, 0x49, 0x54, 0x59, 0x5f, 0x43, 0x52, 0x49, 0x54, 0x49, + 0x43, 0x41, 0x4c, 0x10, 0x04, 0x12, 0x12, 0x0a, 0x0e, 0x53, 0x45, 0x56, 0x45, 0x52, 0x49, 0x54, + 0x59, 0x5f, 0x4f, 0x54, 0x48, 0x45, 0x52, 0x10, 0x05, 0x42, 0x72, 0x0a, 0x28, 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, 0x50, 0x01, 0x5a, 0x44, 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, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/kessel/inventory/v1beta1/policy_detail.pb.validate.go b/api/kessel/inventory/v1beta1/policy_detail.pb.validate.go index 6c817fa9..08e644d8 100644 --- a/api/kessel/inventory/v1beta1/policy_detail.pb.validate.go +++ b/api/kessel/inventory/v1beta1/policy_detail.pb.validate.go @@ -59,7 +59,16 @@ func (m *PolicyDetail) validate(all bool) error { // no validation rules for Disabled - // no validation rules for Severity + if _, ok := PolicyDetail_Severity_name[int32(m.GetSeverity())]; !ok { + err := PolicyDetailValidationError{ + field: "Severity", + reason: "value must be one of the defined enum values", + } + if !all { + return err + } + errors = append(errors, err) + } if len(errors) > 0 { return PolicyDetailMultiError(errors) diff --git a/api/kessel/inventory/v1beta1/policy_detail.proto b/api/kessel/inventory/v1beta1/policy_detail.proto index 68acf596..9f4cae2e 100644 --- a/api/kessel/inventory/v1beta1/policy_detail.proto +++ b/api/kessel/inventory/v1beta1/policy_detail.proto @@ -2,12 +2,14 @@ syntax = "proto3"; package kessel.inventory.v1beta1; +import "validate/validate.proto"; + option go_package = "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1"; option java_multiple_files = true; option java_package = "org.project_kessel.api.inventory.v1beta1"; message PolicyDetail { - + // The kind of policy enum Severity { SEVERITY_UNSPECIFIED = 0; @@ -21,5 +23,5 @@ message PolicyDetail { // Defines if the policy is currently enabled or disabled across all targets bool disabled = 270940796; - Severity severity = 404558591; + Severity severity = 404558591 [ (validate.rules).enum.defined_only = true ]; } diff --git a/api/kessel/inventory/v1beta1/reporter_data.pb.go b/api/kessel/inventory/v1beta1/reporter_data.pb.go index e4f29789..a3cb30d3 100644 --- a/api/kessel/inventory/v1beta1/reporter_data.pb.go +++ b/api/kessel/inventory/v1beta1/reporter_data.pb.go @@ -7,6 +7,7 @@ package v1beta1 import ( + _ "github.com/envoyproxy/protoc-gen-validate/validate" _ "google.golang.org/genproto/googleapis/api/annotations" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -200,56 +201,59 @@ var file_kessel_inventory_v1beta1_reporter_data_proto_rawDesc = []byte{ 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 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, 0x22, 0xec, 0x04, 0x0a, 0x0c, 0x52, - 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x5b, 0x0a, 0x0d, 0x72, - 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0xd8, 0x8f, 0x99, - 0x75, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x33, 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, 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, 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, 0xb8, 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, 0x49, 0x0a, 0x0e, 0x66, 0x69, 0x72, 0x73, 0x74, 0x5f, 0x72, 0x65, 0x70, 0x6f, - 0x72, 0x74, 0x65, 0x64, 0x18, 0x80, 0xed, 0xce, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, + 0x69, 0x6f, 0x72, 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, 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, 0x22, 0x81, 0x05, 0x0a, 0x0c, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, + 0x44, 0x61, 0x74, 0x61, 0x12, 0x67, 0x0a, 0x0d, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, + 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0xd8, 0x8f, 0x99, 0x75, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x33, + 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, 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, 0xb8, 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, 0x49, 0x0a, 0x0e, 0x66, 0x69, 0x72, 0x73, 0x74, + 0x5f, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x18, 0x80, 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, 0x8b, 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, 0x8b, - 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, 0x24, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x73, 0x6f, - 0x6c, 0x65, 0x5f, 0x68, 0x72, 0x65, 0x66, 0x18, 0x94, 0xa2, 0xc6, 0x45, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x48, 0x72, 0x65, 0x66, 0x12, 0x1d, 0x0a, - 0x08, 0x61, 0x70, 0x69, 0x5f, 0x68, 0x72, 0x65, 0x66, 0x18, 0xb1, 0xfc, 0x91, 0xcd, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x70, 0x69, 0x48, 0x72, 0x65, 0x66, 0x12, 0x2e, 0x0a, 0x11, - 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x69, - 0x64, 0x18, 0xbd, 0xb8, 0xd9, 0xf2, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 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, 0xfa, 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, 0x22, 0x8b, 0x01, 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, 0x15, 0x0a, 0x11, 0x52, - 0x45, 0x50, 0x4f, 0x52, 0x54, 0x45, 0x52, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x41, 0x43, 0x4d, - 0x10, 0x01, 0x12, 0x15, 0x0a, 0x11, 0x52, 0x45, 0x50, 0x4f, 0x52, 0x54, 0x45, 0x52, 0x5f, 0x54, - 0x59, 0x50, 0x45, 0x5f, 0x48, 0x42, 0x49, 0x10, 0x02, 0x12, 0x15, 0x0a, 0x11, 0x52, 0x45, 0x50, - 0x4f, 0x52, 0x54, 0x45, 0x52, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x4f, 0x43, 0x4d, 0x10, 0x03, - 0x12, 0x17, 0x0a, 0x13, 0x52, 0x45, 0x50, 0x4f, 0x52, 0x54, 0x45, 0x52, 0x5f, 0x54, 0x59, 0x50, - 0x45, 0x5f, 0x4f, 0x54, 0x48, 0x45, 0x52, 0x10, 0x04, 0x42, 0x72, 0x0a, 0x28, 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, 0x50, 0x01, 0x5a, 0x44, 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, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 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, 0x24, 0x0a, 0x0c, + 0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x5f, 0x68, 0x72, 0x65, 0x66, 0x18, 0x94, 0xa2, 0xc6, + 0x45, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x48, 0x72, + 0x65, 0x66, 0x12, 0x1d, 0x0a, 0x08, 0x61, 0x70, 0x69, 0x5f, 0x68, 0x72, 0x65, 0x66, 0x18, 0xb1, + 0xfc, 0x91, 0xcd, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x70, 0x69, 0x48, 0x72, 0x65, + 0x66, 0x12, 0x37, 0x0a, 0x11, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x72, 0x65, 0x73, 0x6f, 0x75, + 0x72, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0xbd, 0xb8, 0xd9, 0xf2, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x0f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 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, 0xfa, + 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, 0x22, 0x8b, 0x01, 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, 0x15, 0x0a, 0x11, 0x52, 0x45, 0x50, + 0x4f, 0x52, 0x54, 0x45, 0x52, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x41, 0x43, 0x4d, 0x10, 0x01, + 0x12, 0x15, 0x0a, 0x11, 0x52, 0x45, 0x50, 0x4f, 0x52, 0x54, 0x45, 0x52, 0x5f, 0x54, 0x59, 0x50, + 0x45, 0x5f, 0x48, 0x42, 0x49, 0x10, 0x02, 0x12, 0x15, 0x0a, 0x11, 0x52, 0x45, 0x50, 0x4f, 0x52, + 0x54, 0x45, 0x52, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x4f, 0x43, 0x4d, 0x10, 0x03, 0x12, 0x17, + 0x0a, 0x13, 0x52, 0x45, 0x50, 0x4f, 0x52, 0x54, 0x45, 0x52, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, + 0x4f, 0x54, 0x48, 0x45, 0x52, 0x10, 0x04, 0x42, 0x72, 0x0a, 0x28, 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, 0x50, 0x01, 0x5a, 0x44, 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, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( diff --git a/api/kessel/inventory/v1beta1/reporter_data.pb.validate.go b/api/kessel/inventory/v1beta1/reporter_data.pb.validate.go index 3b5685b4..83146952 100644 --- a/api/kessel/inventory/v1beta1/reporter_data.pb.validate.go +++ b/api/kessel/inventory/v1beta1/reporter_data.pb.validate.go @@ -57,7 +57,27 @@ func (m *ReporterData) validate(all bool) error { var errors []error - // no validation rules for ReporterType + 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 @@ -123,7 +143,16 @@ func (m *ReporterData) validate(all bool) error { // no validation rules for ApiHref - // no validation rules for LocalResourceId + if utf8.RuneCountInString(m.GetLocalResourceId()) < 1 { + err := ReporterDataValidationError{ + field: "LocalResourceId", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } // no validation rules for ReporterVersion @@ -203,3 +232,7 @@ var _ interface { Cause() error ErrorName() string } = ReporterDataValidationError{} + +var _ReporterData_ReporterType_NotInLookup = map[ReporterData_ReporterType]struct{}{ + 0: {}, +} diff --git a/api/kessel/inventory/v1beta1/reporter_data.pb.validate_test.go b/api/kessel/inventory/v1beta1/reporter_data.pb.validate_test.go new file mode 100644 index 00000000..5f05447e --- /dev/null +++ b/api/kessel/inventory/v1beta1/reporter_data.pb.validate_test.go @@ -0,0 +1,47 @@ +package v1beta1 + +import ( + "github.com/stretchr/testify/assert" + "strconv" + "testing" +) + +func TestReporterDataValid(t *testing.T) { + reporter := ReporterData{ + ReporterType: ReporterData_REPORTER_TYPE_OCM, + LocalResourceId: "my-id", + } + + err := reporter.ValidateAll() + + assert.NoError(t, err) +} + +func TestReporterDataInvalidReporterTypes(t *testing.T) { + invalidReporterTypes := []int32{ + int32(ReporterData_REPORTER_TYPE_UNSPECIFIED), + 15, + 99, + } + + for _, reporterType := range invalidReporterTypes { + t.Run(strconv.Itoa(int(reporterType)), func(t *testing.T) { + reporter := ReporterData{ + ReporterType: ReporterData_ReporterType(reporterType), + LocalResourceId: "my-id", + } + + err := reporter.ValidateAll() + assert.ErrorContains(t, err, "ReporterData.ReporterType") + }) + } +} + +func TestReporterDataEmpty(t *testing.T) { + reporter := ReporterData{} + + err := reporter.ValidateAll() + + assert.ErrorContains(t, err, "ReporterData.ReporterType") + assert.ErrorContains(t, err, "ReporterData.LocalResourceId") +} diff --git a/api/kessel/inventory/v1beta1/reporter_data.proto b/api/kessel/inventory/v1beta1/reporter_data.proto index 013efb73..bdbb38fe 100644 --- a/api/kessel/inventory/v1beta1/reporter_data.proto +++ b/api/kessel/inventory/v1beta1/reporter_data.proto @@ -3,6 +3,7 @@ syntax = "proto3"; package kessel.inventory.v1beta1; import "google/api/field_behavior.proto"; +import "validate/validate.proto"; import "google/protobuf/timestamp.proto"; option go_package = "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1"; @@ -19,11 +20,11 @@ message ReporterData { REPORTER_TYPE_OTHER = 4; } - ReporterType reporter_type = 245778392; + ReporterType reporter_type = 245778392 [ (validate.rules).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. - string reporter_instance_id = 241085112 + string reporter_instance_id = 241085112 [ (google.api.field_behavior) = OUTPUT_ONLY ]; // Date and time when the inventory item was first reported by this reporter @@ -44,7 +45,7 @@ message ReporterData { // The ID assigned to this resource by the reporter, for example OCM cluster // ID, HBI's host id, or ACM managed cluster name etc. - string local_resource_id = 508976189; + string local_resource_id = 508976189 [ (validate.rules).string.min_len = 1 ]; // version of the reporter string reporter_version = 269629306; diff --git a/api/kessel/inventory/v1beta1/resource_label.pb.go b/api/kessel/inventory/v1beta1/resource_label.pb.go index 4d7d04ca..6c23ffc8 100644 --- a/api/kessel/inventory/v1beta1/resource_label.pb.go +++ b/api/kessel/inventory/v1beta1/resource_label.pb.go @@ -7,6 +7,7 @@ package v1beta1 import ( + _ "github.com/envoyproxy/protoc-gen-validate/validate" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -82,19 +83,21 @@ var file_kessel_inventory_v1beta1_resource_label_proto_rawDesc = []byte{ 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x18, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, - 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x22, 0x3c, 0x0a, 0x0d, 0x52, 0x65, 0x73, - 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x12, 0x12, 0x0a, 0x03, 0x6b, 0x65, - 0x79, 0x18, 0xdf, 0xbc, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x17, - 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0xf1, 0xa2, 0xb2, 0x35, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x72, 0x0a, 0x28, 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, 0x50, 0x01, 0x5a, 0x44, 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, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 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, 0x4e, 0x0a, 0x0d, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4c, 0x61, + 0x62, 0x65, 0x6c, 0x12, 0x1b, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0xdf, 0xbc, 0x06, 0x20, 0x01, + 0x28, 0x09, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x03, 0x6b, 0x65, 0x79, + 0x12, 0x20, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0xf1, 0xa2, 0xb2, 0x35, 0x20, 0x01, + 0x28, 0x09, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x42, 0x72, 0x0a, 0x28, 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, 0x50, 0x01, + 0x5a, 0x44, 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, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/kessel/inventory/v1beta1/resource_label.pb.validate.go b/api/kessel/inventory/v1beta1/resource_label.pb.validate.go index 42acf19d..6be39fcf 100644 --- a/api/kessel/inventory/v1beta1/resource_label.pb.validate.go +++ b/api/kessel/inventory/v1beta1/resource_label.pb.validate.go @@ -57,9 +57,27 @@ func (m *ResourceLabel) validate(all bool) error { var errors []error - // no validation rules for Key + if utf8.RuneCountInString(m.GetKey()) < 1 { + err := ResourceLabelValidationError{ + field: "Key", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } - // no validation rules for Value + if utf8.RuneCountInString(m.GetValue()) < 1 { + err := ResourceLabelValidationError{ + field: "Value", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } if len(errors) > 0 { return ResourceLabelMultiError(errors) diff --git a/api/kessel/inventory/v1beta1/resource_label.pb.validate_test.go b/api/kessel/inventory/v1beta1/resource_label.pb.validate_test.go new file mode 100644 index 00000000..e01fdf21 --- /dev/null +++ b/api/kessel/inventory/v1beta1/resource_label.pb.validate_test.go @@ -0,0 +1,48 @@ +package v1beta1 + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestResourceLabelValid(t *testing.T) { + label := ResourceLabel{ + Key: "key", + Value: "value", + } + + err := label.ValidateAll() + + assert.NoError(t, err) +} + +func TestResourceLabelEmpty(t *testing.T) { + label := ResourceLabel{} + + err := label.ValidateAll() + + assert.ErrorContains(t, err, "invalid ResourceLabel.Key") + assert.ErrorContains(t, err, "invalid ResourceLabel.Value") +} + +func TestResourceLabelNoKey(t *testing.T) { + label := ResourceLabel{ + Value: "value", + } + + err := label.ValidateAll() + + assert.ErrorContains(t, err, "invalid ResourceLabel.Key") + assert.NotContains(t, err.Error(), "invalid ResourceLabel.Value") +} + +func TestResourceLabelNoValue(t *testing.T) { + label := ResourceLabel{ + Key: "key", + } + + err := label.ValidateAll() + + assert.NotContains(t, err.Error(), "invalid ResourceLabel.Key") + assert.ErrorContains(t, err, "invalid ResourceLabel.Value") +} diff --git a/api/kessel/inventory/v1beta1/resource_label.proto b/api/kessel/inventory/v1beta1/resource_label.proto index 129169f4..48352635 100644 --- a/api/kessel/inventory/v1beta1/resource_label.proto +++ b/api/kessel/inventory/v1beta1/resource_label.proto @@ -2,13 +2,15 @@ syntax = "proto3"; package kessel.inventory.v1beta1; +import "validate/validate.proto"; + option go_package = "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1"; option java_multiple_files = true; option java_package = "org.project_kessel.api.inventory.v1beta1"; message ResourceLabel { - string key = 106079; + string key = 106079 [ (validate.rules).string.min_len = 1 ]; - string value = 111972721; + string value = 111972721 [ (validate.rules).string.min_len = 1 ]; } diff --git a/api/kessel/inventory/v1beta1/rhel_host.pb.go b/api/kessel/inventory/v1beta1/rhel_host.pb.go index e88124ff..62de6599 100644 --- a/api/kessel/inventory/v1beta1/rhel_host.pb.go +++ b/api/kessel/inventory/v1beta1/rhel_host.pb.go @@ -31,9 +31,6 @@ type RhelHost struct { Metadata *Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` // Write only reporter specific data ReporterData *ReporterData `protobuf:"bytes,245278792,opt,name=reporter_data,json=reporterData,proto3" json:"reporter_data,omitempty"` - // The entities that registered this item in the Kessel Asset Inventory. The - // same resource may be registered by multiple reporters. - Reporters []*ReporterData `protobuf:"bytes,353323086,rep,name=reporters,proto3" json:"reporters,omitempty"` } func (x *RhelHost) Reset() { @@ -82,13 +79,6 @@ func (x *RhelHost) GetReporterData() *ReporterData { return nil } -func (x *RhelHost) GetReporters() []*ReporterData { - if x != nil { - return x.Reporters - } - return nil -} - var File_kessel_inventory_v1beta1_rhel_host_proto protoreflect.FileDescriptor var file_kessel_inventory_v1beta1_rhel_host_proto_rawDesc = []byte{ @@ -105,30 +95,26 @@ var file_kessel_inventory_v1beta1_rhel_host_proto_rawDesc = []byte{ 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2c, 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, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xf8, 0x01, 0x0a, 0x08, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, - 0x73, 0x74, 0x12, 0x48, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb3, 0x01, 0x0a, 0x08, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, + 0x73, 0x74, 0x12, 0x4a, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 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, - 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x42, 0x08, 0xfa, 0x42, 0x05, 0xa2, 0x01, 0x02, - 0x08, 0x01, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x53, 0x0a, 0x0d, - 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0xc8, 0xd0, - 0xfa, 0x74, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 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, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x42, 0x03, - 0xe0, 0x41, 0x04, 0x52, 0x0c, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, - 0x61, 0x12, 0x4d, 0x0a, 0x09, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x73, 0x18, 0xce, - 0x90, 0xbd, 0xa8, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, + 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x42, 0x0a, 0xfa, 0x42, 0x07, 0x8a, 0x01, 0x04, + 0x08, 0x00, 0x10, 0x00, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x5b, + 0x0a, 0x0d, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, + 0xc8, 0xd0, 0xfa, 0x74, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 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, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, - 0x42, 0x03, 0xe0, 0x41, 0x03, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x73, - 0x42, 0x72, 0x0a, 0x28, 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, 0x50, 0x01, 0x5a, 0x44, - 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, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x42, 0x0b, 0xe0, 0x41, 0x04, 0xfa, 0x42, 0x05, 0x8a, 0x01, 0x02, 0x10, 0x01, 0x52, 0x0c, 0x72, + 0x65, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x42, 0x72, 0x0a, 0x28, 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, 0x50, 0x01, 0x5a, 0x44, 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, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -152,12 +138,11 @@ var file_kessel_inventory_v1beta1_rhel_host_proto_goTypes = []any{ var file_kessel_inventory_v1beta1_rhel_host_proto_depIdxs = []int32{ 1, // 0: kessel.inventory.v1beta1.RhelHost.metadata:type_name -> kessel.inventory.v1beta1.Metadata 2, // 1: kessel.inventory.v1beta1.RhelHost.reporter_data:type_name -> kessel.inventory.v1beta1.ReporterData - 2, // 2: kessel.inventory.v1beta1.RhelHost.reporters:type_name -> kessel.inventory.v1beta1.ReporterData - 3, // [3:3] is the sub-list for method output_type - 3, // [3:3] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_kessel_inventory_v1beta1_rhel_host_proto_init() } diff --git a/api/kessel/inventory/v1beta1/rhel_host.pb.validate.go b/api/kessel/inventory/v1beta1/rhel_host.pb.validate.go index e42b83c2..517db88d 100644 --- a/api/kessel/inventory/v1beta1/rhel_host.pb.validate.go +++ b/api/kessel/inventory/v1beta1/rhel_host.pb.validate.go @@ -57,9 +57,38 @@ func (m *RhelHost) validate(all bool) error { var errors []error - if m.GetMetadata() == nil { + if all { + switch v := interface{}(m.GetMetadata()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, RhelHostValidationError{ + field: "Metadata", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, RhelHostValidationError{ + field: "Metadata", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetMetadata()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return RhelHostValidationError{ + field: "Metadata", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if m.GetReporterData() == nil { err := RhelHostValidationError{ - field: "Metadata", + field: "ReporterData", reason: "value is required", } if !all { @@ -68,10 +97,6 @@ func (m *RhelHost) validate(all bool) error { errors = append(errors, err) } - if a := m.GetMetadata(); a != nil { - - } - if all { switch v := interface{}(m.GetReporterData()).(type) { case interface{ ValidateAll() error }: @@ -101,40 +126,6 @@ func (m *RhelHost) validate(all bool) error { } } - for idx, item := range m.GetReporters() { - _, _ = idx, item - - if all { - switch v := interface{}(item).(type) { - case interface{ ValidateAll() error }: - if err := v.ValidateAll(); err != nil { - errors = append(errors, RhelHostValidationError{ - field: fmt.Sprintf("Reporters[%v]", idx), - reason: "embedded message failed validation", - cause: err, - }) - } - case interface{ Validate() error }: - if err := v.Validate(); err != nil { - errors = append(errors, RhelHostValidationError{ - field: fmt.Sprintf("Reporters[%v]", idx), - reason: "embedded message failed validation", - cause: err, - }) - } - } - } else if v, ok := interface{}(item).(interface{ Validate() error }); ok { - if err := v.Validate(); err != nil { - return RhelHostValidationError{ - field: fmt.Sprintf("Reporters[%v]", idx), - reason: "embedded message failed validation", - cause: err, - } - } - } - - } - if len(errors) > 0 { return RhelHostMultiError(errors) } diff --git a/api/kessel/inventory/v1beta1/rhel_host.pb.validate_test.go b/api/kessel/inventory/v1beta1/rhel_host.pb.validate_test.go new file mode 100644 index 00000000..5ee6bc1c --- /dev/null +++ b/api/kessel/inventory/v1beta1/rhel_host.pb.validate_test.go @@ -0,0 +1,43 @@ +package v1beta1 + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestRhelHostOptionalMetadata(t *testing.T) { + host := RhelHost{ + ReporterData: &ReporterData{ + ReporterType: ReporterData_REPORTER_TYPE_OCM, + LocalResourceId: "foo", + }, + } + err := host.ValidateAll() + + assert.NoError(t, err) +} + +func TestRhelHostMetadataIsValidatedIfFound(t *testing.T) { + host := RhelHost{ + ReporterData: &ReporterData{ + ReporterType: ReporterData_REPORTER_TYPE_OCM, + LocalResourceId: "foo", + }, + Metadata: &Metadata{ + Labels: []*ResourceLabel{ + {}, + }, + }, + } + err := host.ValidateAll() + + assert.ErrorContains(t, err, "RhelHost.Metadata") + assert.ErrorContains(t, err, "Metadata.Labels") +} + +func TestRhelHostReporterDataIsValidated(t *testing.T) { + host := RhelHost{} + err := host.ValidateAll() + + assert.ErrorContains(t, err, "RhelHost.ReporterData") +} diff --git a/api/kessel/inventory/v1beta1/rhel_host.proto b/api/kessel/inventory/v1beta1/rhel_host.proto index ff9ed771..f75d2e53 100644 --- a/api/kessel/inventory/v1beta1/rhel_host.proto +++ b/api/kessel/inventory/v1beta1/rhel_host.proto @@ -14,14 +14,9 @@ option java_package = "org.project_kessel.api.inventory.v1beta1"; message RhelHost { // Metadata about this resource - Metadata metadata = 1 [ (validate.rules).any.required = true ]; + Metadata metadata = 1 [ (validate.rules).message = {required: false, skip: false} ]; // Write only reporter specific data ReporterData reporter_data = 245278792 - [ (google.api.field_behavior) = INPUT_ONLY ]; - - // The entities that registered this item in the Kessel Asset Inventory. The - // same resource may be registered by multiple reporters. - repeated ReporterData reporters = 353323086 - [ (google.api.field_behavior) = OUTPUT_ONLY ]; + [ (google.api.field_behavior) = INPUT_ONLY, (validate.rules).message.required = true ]; } diff --git a/api/kessel/inventory/v1beta1/rhel_hosts_service.pb.go b/api/kessel/inventory/v1beta1/rhel_hosts_service.pb.go index cc8cba91..310af6e5 100644 --- a/api/kessel/inventory/v1beta1/rhel_hosts_service.pb.go +++ b/api/kessel/inventory/v1beta1/rhel_hosts_service.pb.go @@ -7,6 +7,7 @@ package v1beta1 import ( + _ "github.com/envoyproxy/protoc-gen-validate/validate" _ "google.golang.org/genproto/googleapis/api/annotations" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -27,7 +28,7 @@ type CreateRhelHostRequest struct { unknownFields protoimpl.UnknownFields // The Rhel Host to create in Kessel Asset Inventory - Host *RhelHost `protobuf:"bytes,1,opt,name=host,proto3" json:"host,omitempty"` + RhelHost *RhelHost `protobuf:"bytes,1,opt,name=rhel_host,json=rhelHost,proto3" json:"rhel_host,omitempty"` } func (x *CreateRhelHostRequest) Reset() { @@ -62,9 +63,9 @@ func (*CreateRhelHostRequest) Descriptor() ([]byte, []int) { return file_kessel_inventory_v1beta1_rhel_hosts_service_proto_rawDescGZIP(), []int{0} } -func (x *CreateRhelHostRequest) GetHost() *RhelHost { +func (x *CreateRhelHostRequest) GetRhelHost() *RhelHost { if x != nil { - return x.Host + return x.RhelHost } return nil } @@ -73,9 +74,6 @@ type CreateRhelHostResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - - // The Rhel Host created in Kessel Asset Inventory - Host *RhelHost `protobuf:"bytes,1,opt,name=host,proto3" json:"host,omitempty"` } func (x *CreateRhelHostResponse) Reset() { @@ -110,13 +108,6 @@ func (*CreateRhelHostResponse) Descriptor() ([]byte, []int) { return file_kessel_inventory_v1beta1_rhel_hosts_service_proto_rawDescGZIP(), []int{1} } -func (x *CreateRhelHostResponse) GetHost() *RhelHost { - if x != nil { - return x.Host - } - return nil -} - type UpdateRhelHostRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -126,7 +117,7 @@ type UpdateRhelHostRequest struct { // \":\" Resource string `protobuf:"bytes,1,opt,name=resource,proto3" json:"resource,omitempty"` // The Rhel host to update - Host *RhelHost `protobuf:"bytes,2,opt,name=host,proto3" json:"host,omitempty"` + RhelHost *RhelHost `protobuf:"bytes,2,opt,name=rhel_host,json=rhelHost,proto3" json:"rhel_host,omitempty"` } func (x *UpdateRhelHostRequest) Reset() { @@ -168,9 +159,9 @@ func (x *UpdateRhelHostRequest) GetResource() string { return "" } -func (x *UpdateRhelHostRequest) GetHost() *RhelHost { +func (x *UpdateRhelHostRequest) GetRhelHost() *RhelHost { if x != nil { - return x.Host + return x.RhelHost } return nil } @@ -309,74 +300,76 @@ var file_kessel_inventory_v1beta1_rhel_hosts_service_proto_rawDesc = []byte{ 0x6f, 0x74, 0x6f, 0x12, 0x18, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x28, 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, 0x68, 0x65, 0x6c, 0x5f, 0x68, 0x6f, 0x73, 0x74, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x4f, 0x0a, 0x15, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, - 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x36, - 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 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, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, - 0x52, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x22, 0x50, 0x0a, 0x16, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x36, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 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, 0x1a, 0x28, 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, + 0x68, 0x65, 0x6c, 0x5f, 0x68, 0x6f, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x62, + 0x0a, 0x15, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x49, 0x0a, 0x09, 0x72, 0x68, 0x65, 0x6c, 0x5f, + 0x68, 0x6f, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 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, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x42, 0x08, + 0xfa, 0x42, 0x05, 0x8a, 0x01, 0x02, 0x10, 0x01, 0x52, 0x08, 0x72, 0x68, 0x65, 0x6c, 0x48, 0x6f, + 0x73, 0x74, 0x22, 0x18, 0x0a, 0x16, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, + 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x87, 0x01, 0x0a, + 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x23, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, + 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, + 0x01, 0x52, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x49, 0x0a, 0x09, 0x72, + 0x68, 0x65, 0x6c, 0x5f, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 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, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, - 0x73, 0x74, 0x52, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x22, 0x6b, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, - 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x36, 0x0a, - 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 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, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, - 0x04, 0x68, 0x6f, 0x73, 0x74, 0x22, 0x18, 0x0a, 0x16, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, - 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x33, 0x0a, 0x15, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, - 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x6f, - 0x75, 0x72, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, 0x73, 0x6f, - 0x75, 0x72, 0x63, 0x65, 0x22, 0x18, 0x0a, 0x16, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x68, - 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x93, - 0x04, 0x0a, 0x15, 0x4b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, - 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0xa0, 0x01, 0x0a, 0x0e, 0x43, 0x72, 0x65, - 0x61, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x2f, 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, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x68, 0x65, - 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x30, 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, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x68, - 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2b, - 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x25, 0x3a, 0x01, 0x2a, 0x22, 0x20, 0x2f, 0x61, 0x70, 0x69, 0x2f, - 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, - 0x31, 0x2f, 0x72, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x73, 0x12, 0xab, 0x01, 0x0a, 0x0e, - 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x2f, - 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, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, - 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x30, 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, 0x55, 0x70, 0x64, 0x61, 0x74, - 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x36, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x30, 0x3a, 0x01, 0x2a, 0x1a, 0x2b, 0x2f, 0x61, - 0x70, 0x69, 0x2f, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, - 0x65, 0x74, 0x61, 0x31, 0x2f, 0x72, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x73, 0x2f, 0x7b, - 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x7d, 0x12, 0xa8, 0x01, 0x0a, 0x0e, 0x44, 0x65, - 0x6c, 0x65, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x2f, 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, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x68, - 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x30, 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, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, - 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x33, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2d, 0x2a, 0x2b, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x69, 0x6e, - 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, - 0x72, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x73, 0x2f, 0x7b, 0x72, 0x65, 0x73, 0x6f, 0x75, - 0x72, 0x63, 0x65, 0x7d, 0x42, 0x72, 0x0a, 0x28, 0x6f, 0x72, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x6a, - 0x65, 0x63, 0x74, 0x5f, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x69, + 0x73, 0x74, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x8a, 0x01, 0x02, 0x10, 0x01, 0x52, 0x08, 0x72, 0x68, + 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x22, 0x18, 0x0a, 0x16, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x3c, 0x0a, 0x15, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, + 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x23, 0x0a, 0x08, 0x72, 0x65, 0x73, + 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xfa, 0x42, 0x04, + 0x72, 0x02, 0x10, 0x01, 0x52, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, 0x18, + 0x0a, 0x16, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x93, 0x04, 0x0a, 0x15, 0x4b, 0x65, 0x73, + 0x73, 0x65, 0x6c, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x12, 0xa0, 0x01, 0x0a, 0x0e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x68, 0x65, + 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x2f, 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, - 0x50, 0x01, 0x5a, 0x44, 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, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x30, 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, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x25, + 0x3a, 0x01, 0x2a, 0x22, 0x20, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, + 0x6f, 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x72, 0x68, 0x65, 0x6c, + 0x48, 0x6f, 0x73, 0x74, 0x73, 0x12, 0xab, 0x01, 0x0a, 0x0e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x2f, 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, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, + 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x30, 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, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, + 0x6f, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x36, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x30, 0x3a, 0x01, 0x2a, 0x1a, 0x2b, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x69, 0x6e, 0x76, + 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x72, + 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x73, 0x2f, 0x7b, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, + 0x63, 0x65, 0x7d, 0x12, 0xa8, 0x01, 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x68, + 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x2f, 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, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, 0x74, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x30, 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, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x68, 0x65, 0x6c, 0x48, 0x6f, 0x73, + 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x33, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x2d, 0x2a, 0x2b, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x69, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, + 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x72, 0x68, 0x65, 0x6c, 0x48, 0x6f, + 0x73, 0x74, 0x73, 0x2f, 0x7b, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x7d, 0x42, 0x72, + 0x0a, 0x28, 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, 0x50, 0x01, 0x5a, 0x44, 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, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -402,20 +395,19 @@ var file_kessel_inventory_v1beta1_rhel_hosts_service_proto_goTypes = []any{ (*RhelHost)(nil), // 6: kessel.inventory.v1beta1.RhelHost } var file_kessel_inventory_v1beta1_rhel_hosts_service_proto_depIdxs = []int32{ - 6, // 0: kessel.inventory.v1beta1.CreateRhelHostRequest.host:type_name -> kessel.inventory.v1beta1.RhelHost - 6, // 1: kessel.inventory.v1beta1.CreateRhelHostResponse.host:type_name -> kessel.inventory.v1beta1.RhelHost - 6, // 2: kessel.inventory.v1beta1.UpdateRhelHostRequest.host:type_name -> kessel.inventory.v1beta1.RhelHost - 0, // 3: kessel.inventory.v1beta1.KesselRhelHostService.CreateRhelHost:input_type -> kessel.inventory.v1beta1.CreateRhelHostRequest - 2, // 4: kessel.inventory.v1beta1.KesselRhelHostService.UpdateRhelHost:input_type -> kessel.inventory.v1beta1.UpdateRhelHostRequest - 4, // 5: kessel.inventory.v1beta1.KesselRhelHostService.DeleteRhelHost:input_type -> kessel.inventory.v1beta1.DeleteRhelHostRequest - 1, // 6: kessel.inventory.v1beta1.KesselRhelHostService.CreateRhelHost:output_type -> kessel.inventory.v1beta1.CreateRhelHostResponse - 3, // 7: kessel.inventory.v1beta1.KesselRhelHostService.UpdateRhelHost:output_type -> kessel.inventory.v1beta1.UpdateRhelHostResponse - 5, // 8: kessel.inventory.v1beta1.KesselRhelHostService.DeleteRhelHost:output_type -> kessel.inventory.v1beta1.DeleteRhelHostResponse - 6, // [6:9] is the sub-list for method output_type - 3, // [3:6] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 6, // 0: kessel.inventory.v1beta1.CreateRhelHostRequest.rhel_host:type_name -> kessel.inventory.v1beta1.RhelHost + 6, // 1: kessel.inventory.v1beta1.UpdateRhelHostRequest.rhel_host:type_name -> kessel.inventory.v1beta1.RhelHost + 0, // 2: kessel.inventory.v1beta1.KesselRhelHostService.CreateRhelHost:input_type -> kessel.inventory.v1beta1.CreateRhelHostRequest + 2, // 3: kessel.inventory.v1beta1.KesselRhelHostService.UpdateRhelHost:input_type -> kessel.inventory.v1beta1.UpdateRhelHostRequest + 4, // 4: kessel.inventory.v1beta1.KesselRhelHostService.DeleteRhelHost:input_type -> kessel.inventory.v1beta1.DeleteRhelHostRequest + 1, // 5: kessel.inventory.v1beta1.KesselRhelHostService.CreateRhelHost:output_type -> kessel.inventory.v1beta1.CreateRhelHostResponse + 3, // 6: kessel.inventory.v1beta1.KesselRhelHostService.UpdateRhelHost:output_type -> kessel.inventory.v1beta1.UpdateRhelHostResponse + 5, // 7: kessel.inventory.v1beta1.KesselRhelHostService.DeleteRhelHost:output_type -> kessel.inventory.v1beta1.DeleteRhelHostResponse + 5, // [5:8] is the sub-list for method output_type + 2, // [2:5] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_kessel_inventory_v1beta1_rhel_hosts_service_proto_init() } diff --git a/api/kessel/inventory/v1beta1/rhel_hosts_service.pb.validate.go b/api/kessel/inventory/v1beta1/rhel_hosts_service.pb.validate.go index 37f5fe12..1696f057 100644 --- a/api/kessel/inventory/v1beta1/rhel_hosts_service.pb.validate.go +++ b/api/kessel/inventory/v1beta1/rhel_hosts_service.pb.validate.go @@ -57,12 +57,23 @@ func (m *CreateRhelHostRequest) validate(all bool) error { var errors []error + if m.GetRhelHost() == nil { + err := CreateRhelHostRequestValidationError{ + field: "RhelHost", + reason: "value is required", + } + if !all { + return err + } + errors = append(errors, err) + } + if all { - switch v := interface{}(m.GetHost()).(type) { + switch v := interface{}(m.GetRhelHost()).(type) { case interface{ ValidateAll() error }: if err := v.ValidateAll(); err != nil { errors = append(errors, CreateRhelHostRequestValidationError{ - field: "Host", + field: "RhelHost", reason: "embedded message failed validation", cause: err, }) @@ -70,16 +81,16 @@ func (m *CreateRhelHostRequest) validate(all bool) error { case interface{ Validate() error }: if err := v.Validate(); err != nil { errors = append(errors, CreateRhelHostRequestValidationError{ - field: "Host", + field: "RhelHost", reason: "embedded message failed validation", cause: err, }) } } - } else if v, ok := interface{}(m.GetHost()).(interface{ Validate() error }); ok { + } else if v, ok := interface{}(m.GetRhelHost()).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return CreateRhelHostRequestValidationError{ - field: "Host", + field: "RhelHost", reason: "embedded message failed validation", cause: err, } @@ -188,35 +199,6 @@ func (m *CreateRhelHostResponse) validate(all bool) error { var errors []error - if all { - switch v := interface{}(m.GetHost()).(type) { - case interface{ ValidateAll() error }: - if err := v.ValidateAll(); err != nil { - errors = append(errors, CreateRhelHostResponseValidationError{ - field: "Host", - reason: "embedded message failed validation", - cause: err, - }) - } - case interface{ Validate() error }: - if err := v.Validate(); err != nil { - errors = append(errors, CreateRhelHostResponseValidationError{ - field: "Host", - reason: "embedded message failed validation", - cause: err, - }) - } - } - } else if v, ok := interface{}(m.GetHost()).(interface{ Validate() error }); ok { - if err := v.Validate(); err != nil { - return CreateRhelHostResponseValidationError{ - field: "Host", - reason: "embedded message failed validation", - cause: err, - } - } - } - if len(errors) > 0 { return CreateRhelHostResponseMultiError(errors) } @@ -319,14 +301,34 @@ func (m *UpdateRhelHostRequest) validate(all bool) error { var errors []error - // no validation rules for Resource + if utf8.RuneCountInString(m.GetResource()) < 1 { + err := UpdateRhelHostRequestValidationError{ + field: "Resource", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } + + if m.GetRhelHost() == nil { + err := UpdateRhelHostRequestValidationError{ + field: "RhelHost", + reason: "value is required", + } + if !all { + return err + } + errors = append(errors, err) + } if all { - switch v := interface{}(m.GetHost()).(type) { + switch v := interface{}(m.GetRhelHost()).(type) { case interface{ ValidateAll() error }: if err := v.ValidateAll(); err != nil { errors = append(errors, UpdateRhelHostRequestValidationError{ - field: "Host", + field: "RhelHost", reason: "embedded message failed validation", cause: err, }) @@ -334,16 +336,16 @@ func (m *UpdateRhelHostRequest) validate(all bool) error { case interface{ Validate() error }: if err := v.Validate(); err != nil { errors = append(errors, UpdateRhelHostRequestValidationError{ - field: "Host", + field: "RhelHost", reason: "embedded message failed validation", cause: err, }) } } - } else if v, ok := interface{}(m.GetHost()).(interface{ Validate() error }); ok { + } else if v, ok := interface{}(m.GetRhelHost()).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { return UpdateRhelHostRequestValidationError{ - field: "Host", + field: "RhelHost", reason: "embedded message failed validation", cause: err, } @@ -554,7 +556,16 @@ func (m *DeleteRhelHostRequest) validate(all bool) error { var errors []error - // no validation rules for Resource + if utf8.RuneCountInString(m.GetResource()) < 1 { + err := DeleteRhelHostRequestValidationError{ + field: "Resource", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } if len(errors) > 0 { return DeleteRhelHostRequestMultiError(errors) diff --git a/api/kessel/inventory/v1beta1/rhel_hosts_service.proto b/api/kessel/inventory/v1beta1/rhel_hosts_service.proto index 8dcc0f90..1e087071 100644 --- a/api/kessel/inventory/v1beta1/rhel_hosts_service.proto +++ b/api/kessel/inventory/v1beta1/rhel_hosts_service.proto @@ -3,6 +3,7 @@ syntax = "proto3"; package kessel.inventory.v1beta1; import "google/api/annotations.proto"; +import "validate/validate.proto"; import "kessel/inventory/v1beta1/rhel_host.proto"; @@ -12,20 +13,17 @@ option java_package = "org.project_kessel.api.inventory.v1beta1"; message CreateRhelHostRequest { // The Rhel Host to create in Kessel Asset Inventory - RhelHost host = 1; + RhelHost rhel_host = 1 [ (validate.rules).message.required = true ]; } -message CreateRhelHostResponse { - // The Rhel Host created in Kessel Asset Inventory - RhelHost host = 1; -} +message CreateRhelHostResponse {} message UpdateRhelHostRequest { // A resource instance using the format: // \":\" - string resource = 1; + string resource = 1 [ (validate.rules).string.min_len = 1 ]; // The Rhel host to update - RhelHost host = 2; + RhelHost rhel_host = 2 [ (validate.rules).message.required = true ]; } message UpdateRhelHostResponse {} @@ -33,7 +31,7 @@ message UpdateRhelHostResponse {} message DeleteRhelHostRequest { // A resource instance using the format: // \":\" - string resource = 1; + string resource = 1 [ (validate.rules).string.min_len = 1 ]; } message DeleteRhelHostResponse {} diff --git a/data/host-service-account.json b/data/host-service-account.json index 37f94e9b..7f20fcd2 100644 --- a/data/host-service-account.json +++ b/data/host-service-account.json @@ -1,12 +1,10 @@ { "host": { "metadata": { - "resource_type": "rhel-host", "workspace": "" }, "reporter_data": { "reporter_type": "REPORTER_TYPE_OCM", - "reporter_instance_id": "service-account-svc-test", "reporter_version": "0.1", "local_resource_id": "1", "api_href": "www.example.com", diff --git a/data/host.json b/data/host.json index 0c374552..7f20fcd2 100644 --- a/data/host.json +++ b/data/host.json @@ -1,12 +1,10 @@ { "host": { "metadata": { - "resource_type": "rhel-host", "workspace": "" }, "reporter_data": { "reporter_type": "REPORTER_TYPE_OCM", - "reporter_instance_id": "user@example.com", "reporter_version": "0.1", "local_resource_id": "1", "api_href": "www.example.com", diff --git a/internal/service/hosts/hosts.go b/internal/service/hosts/hosts.go index 2f687f78..6c4d787e 100644 --- a/internal/service/hosts/hosts.go +++ b/internal/service/hosts/hosts.go @@ -2,9 +2,6 @@ package hosts import ( "context" - "fmt" - "strings" - "github.com/go-kratos/kratos/v2/errors" pb "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1" authnapi "github.com/project-kessel/inventory-api/internal/authn/api" @@ -29,12 +26,7 @@ func New(c *biz.HostUsecase) *HostsService { func (c *HostsService) CreateRhelHost(ctx context.Context, r *pb.CreateRhelHostRequest) (*pb.CreateRhelHostResponse, error) { if err := r.ValidateAll(); err != nil { - return nil, err - } - - //TODO: refactor / abstract resource type strings - if !strings.EqualFold(r.Host.Metadata.ResourceType, biz.ResourceType) { - return nil, errors.BadRequest("BADREQUEST", fmt.Sprintf("incorrect resource type: expected %s", biz.ResourceType)) + return nil, errors.BadRequest("BADREQUEST", err.Error()) } identity, err := middleware.GetIdentity(ctx) @@ -69,20 +61,16 @@ func (c *HostsService) DeleteRhelHost(ctx context.Context, r *pb.DeleteRhelHostR } func hostFromCreateRequest(r *pb.CreateRhelHostRequest, identity *authnapi.Identity) (*biz.Host, error) { - if identity.Principal != r.Host.ReporterData.ReporterInstanceId { - return nil, errors.Forbidden("FORBIDDEN", "Reporter identity must match the provided reporter instance identity") + var metadata = &pb.Metadata{} + if r.RhelHost.Metadata != nil { + metadata = r.RhelHost.Metadata } return &biz.Host{ - Metadata: *conv.MetadataFromPb(r.Host.Metadata, r.Host.ReporterData, identity), + Metadata: *conv.MetadataFromPb(metadata, r.RhelHost.ReporterData, identity), }, nil } func createResponseFromHost(h *biz.Host) *pb.CreateRhelHostResponse { - return &pb.CreateRhelHostResponse{ - Host: &pb.RhelHost{ - Metadata: conv.MetadataFromModel(&h.Metadata), - Reporters: conv.ReportersFromModel(h.Metadata.Reporters), - }, - } + return &pb.CreateRhelHostResponse{} } diff --git a/internal/service/hosts/hosts_test.go b/internal/service/hosts/hosts_test.go new file mode 100644 index 00000000..3e6627aa --- /dev/null +++ b/internal/service/hosts/hosts_test.go @@ -0,0 +1,126 @@ +package hosts + +import ( + "context" + "github.com/go-kratos/kratos/v2/log" + pb "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1" + "github.com/project-kessel/inventory-api/internal/authn/api" + "github.com/project-kessel/inventory-api/internal/biz/hosts" + "github.com/project-kessel/inventory-api/internal/middleware" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "testing" +) + +type HostRepoMock struct { + mock.Mock +} + +func (m *HostRepoMock) Save(ctx context.Context, host *hosts.Host) (*hosts.Host, error) { + return host, nil +} + +func (m *HostRepoMock) Update(ctx context.Context, host *hosts.Host, hostId string) (*hosts.Host, error) { + return host, nil +} + +func (m *HostRepoMock) Delete(ctx context.Context, hostId string) error { + return nil +} + +func (m *HostRepoMock) FindByID(ctx context.Context, hostId string) (*hosts.Host, error) { + return nil, nil +} + +func (m *HostRepoMock) ListAll(ctx context.Context) ([]*hosts.Host, error) { + return []*hosts.Host{}, nil +} + +func mockContext() context.Context { + return context.WithValue( + context.Background(), + middleware.IdentityRequestKey, + &api.Identity{ + Principal: "test-principal", + }, + ) +} + +func TestCreateHostWithRequiredDataIsSuccess(t *testing.T) { + repo := new(HostRepoMock) + hostUsecase := hosts.New(repo, log.DefaultLogger) + + service := HostsService{ + Ctl: hostUsecase, + } + + ctx := mockContext() + + request := pb.CreateRhelHostRequest{ + RhelHost: &pb.RhelHost{ + Metadata: nil, + ReporterData: &pb.ReporterData{ + ReporterType: pb.ReporterData_REPORTER_TYPE_OCM, + LocalResourceId: "testing", + }, + }, + } + + _, err := service.CreateRhelHost(ctx, &request) + + assert.NoError(t, err) +} + +func TestCreateHostWithOptionalAttributesIsSuccess(t *testing.T) { + repo := new(HostRepoMock) + hostUsecase := hosts.New(repo, log.DefaultLogger) + + service := HostsService{ + Ctl: hostUsecase, + } + + ctx := mockContext() + + request := pb.CreateRhelHostRequest{ + RhelHost: &pb.RhelHost{ + Metadata: &pb.Metadata{ + Labels: []*pb.ResourceLabel{}, + Workspace: "foobar", + }, + ReporterData: &pb.ReporterData{ + ReporterType: pb.ReporterData_REPORTER_TYPE_OCM, + LocalResourceId: "testing", + ConsoleHref: "http://my-console", + ApiHref: "http://my-api", + ReporterVersion: "1337", + }, + }, + } + + _, err := service.CreateRhelHost(ctx, &request) + + assert.NoError(t, err) +} + +func TestCreateInvalidHostIsBadRequest(t *testing.T) { + repo := new(HostRepoMock) + hostUsecase := hosts.New(repo, log.DefaultLogger) + + service := HostsService{ + Ctl: hostUsecase, + } + ctx := mockContext() + + request := pb.CreateRhelHostRequest{ + RhelHost: &pb.RhelHost{ + Metadata: nil, + ReporterData: &pb.ReporterData{ + ReporterType: pb.ReporterData_REPORTER_TYPE_OCM, + }, + }, + } + + _, err := service.CreateRhelHost(ctx, &request) + + assert.ErrorContains(t, err, "400") +} diff --git a/internal/service/notificationsintegrations/notificationsintegrations.go b/internal/service/notificationsintegrations/notificationsintegrations.go index 36a94c5b..03bbc156 100644 --- a/internal/service/notificationsintegrations/notificationsintegrations.go +++ b/internal/service/notificationsintegrations/notificationsintegrations.go @@ -2,9 +2,6 @@ package notificationsintegrations import ( "context" - "fmt" - "strings" - "github.com/go-kratos/kratos/v2/errors" pb "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1" authnapi "github.com/project-kessel/inventory-api/internal/authn/api" @@ -29,12 +26,7 @@ func New(c *biz.NotificationsIntegrationUsecase) *NotificationsIntegrationsServi func (c *NotificationsIntegrationsService) CreateNotificationsIntegration(ctx context.Context, r *pb.CreateNotificationsIntegrationRequest) (*pb.CreateNotificationsIntegrationResponse, error) { if err := r.ValidateAll(); err != nil { - return nil, err - } - - //TODO: refactor / abstract resource type strings - if !strings.EqualFold(r.Integration.Metadata.ResourceType, biz.ResourceType) { - return nil, errors.BadRequest("BADREQUEST", fmt.Sprintf("incorrect resource type: expected %s", biz.ResourceType)) + return nil, errors.BadRequest("BADREQUEST", err.Error()) } identity, err := middleware.GetIdentity(ctx) @@ -69,20 +61,20 @@ func (c *NotificationsIntegrationsService) DeleteNotificationsIntegration(ctx co } func notificationsIntegrationFromCreateRequest(r *pb.CreateNotificationsIntegrationRequest, identity *authnapi.Identity) (*biz.NotificationsIntegration, error) { - if identity.Principal != r.Integration.ReporterData.ReporterInstanceId { - return nil, errors.Forbidden("FORBIDDEN", "Reporter identity must match the provided reporter instance identity") + var metadata = &pb.Metadata{} + if r.Integration.Metadata != nil { + metadata = r.Integration.Metadata } return &biz.NotificationsIntegration{ - Metadata: *conv.MetadataFromPb(r.Integration.Metadata, r.Integration.ReporterData, identity), + Metadata: *conv.MetadataFromPb(metadata, r.Integration.ReporterData, identity), }, nil } func createResponseFromNotificationsIntegration(h *biz.NotificationsIntegration) *pb.CreateNotificationsIntegrationResponse { return &pb.CreateNotificationsIntegrationResponse{ Integration: &pb.NotificationsIntegration{ - Metadata: conv.MetadataFromModel(&h.Metadata), - Reporters: conv.ReportersFromModel(h.Metadata.Reporters), + Metadata: conv.MetadataFromModel(&h.Metadata), }, } } diff --git a/internal/service/notificationsintegrations/notificationsintegrations_test.go b/internal/service/notificationsintegrations/notificationsintegrations_test.go new file mode 100644 index 00000000..5782760d --- /dev/null +++ b/internal/service/notificationsintegrations/notificationsintegrations_test.go @@ -0,0 +1,96 @@ +package notificationsintegrations + +import ( + "context" + "github.com/go-kratos/kratos/v2/log" + pb "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1" + "github.com/project-kessel/inventory-api/internal/authn/api" + biz "github.com/project-kessel/inventory-api/internal/biz/notificationsintegrations" + "github.com/project-kessel/inventory-api/internal/middleware" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "testing" +) + +type NotificationIntegrationsRepoMock struct { + mock.Mock +} + +func (m *NotificationIntegrationsRepoMock) Save(ctx context.Context, integration *biz.NotificationsIntegration) (*biz.NotificationsIntegration, error) { + return integration, nil +} + +func (m *NotificationIntegrationsRepoMock) Update(ctx context.Context, integration *biz.NotificationsIntegration, id string) (*biz.NotificationsIntegration, error) { + return integration, nil +} + +func (m *NotificationIntegrationsRepoMock) Delete(ctx context.Context, id string) error { + return nil +} + +func (m *NotificationIntegrationsRepoMock) FindByID(ctx context.Context, id string) (*biz.NotificationsIntegration, error) { + return nil, nil +} + +func (m *NotificationIntegrationsRepoMock) ListAll(ctx context.Context) ([]*biz.NotificationsIntegration, error) { + return []*biz.NotificationsIntegration{}, nil +} + +func mockContext() context.Context { + return context.WithValue( + context.Background(), + middleware.IdentityRequestKey, + &api.Identity{ + Principal: "test-principal", + }, + ) +} + +func TestCreateNotificationIntegrationWithRequiredDataIsSuccess(t *testing.T) { + repo := new(NotificationIntegrationsRepoMock) + notificationsintegrationsUsecase := biz.New(repo, log.DefaultLogger) + + service := NotificationsIntegrationsService{ + Ctl: notificationsintegrationsUsecase, + } + + ctx := mockContext() + + request := pb.CreateNotificationsIntegrationRequest{ + Integration: &pb.NotificationsIntegration{ + Metadata: nil, + ReporterData: &pb.ReporterData{ + ReporterType: pb.ReporterData_REPORTER_TYPE_HBI, + LocalResourceId: "testing", + }, + }, + } + + _, err := service.CreateNotificationsIntegration(ctx, &request) + + assert.NoError(t, err) +} + +func TestCreateInvalidNotificationIntegrationIsBadRequest(t *testing.T) { + repo := new(NotificationIntegrationsRepoMock) + notificationsintegrationsUsecase := biz.New(repo, log.DefaultLogger) + + service := NotificationsIntegrationsService{ + Ctl: notificationsintegrationsUsecase, + } + + ctx := mockContext() + + request := pb.CreateNotificationsIntegrationRequest{ + Integration: &pb.NotificationsIntegration{ + Metadata: nil, + ReporterData: &pb.ReporterData{ + ReporterType: pb.ReporterData_REPORTER_TYPE_HBI, + }, + }, + } + + _, err := service.CreateNotificationsIntegration(ctx, &request) + + assert.ErrorContains(t, err, "400") +} diff --git a/openapi.yaml b/openapi.yaml index 53dc1f4f..2d7fe8d2 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -418,17 +418,13 @@ components: kessel.inventory.v1beta1.CreateRhelHostRequest: type: object properties: - host: + rhel_host: allOf: - $ref: '#/components/schemas/kessel.inventory.v1beta1.RhelHost' description: The Rhel Host to create in Kessel Asset Inventory kessel.inventory.v1beta1.CreateRhelHostResponse: type: object - properties: - host: - allOf: - - $ref: '#/components/schemas/kessel.inventory.v1beta1.RhelHost' - description: The Rhel Host created in Kessel Asset Inventory + properties: {} kessel.inventory.v1beta1.DeleteK8sClusterResponse: type: object properties: {} @@ -501,6 +497,7 @@ components: description: |- Map of string keys and string values that can be used to organize and categorize (scope and select) resources + Todo: Do we require at least 1 label? kessel.inventory.v1beta1.Metadata: type: object properties: @@ -551,14 +548,6 @@ components: allOf: - $ref: '#/components/schemas/kessel.inventory.v1beta1.ReporterData' description: Write only reporter specific data - reporters: - readOnly: true - type: array - items: - $ref: '#/components/schemas/kessel.inventory.v1beta1.ReporterData' - description: |- - The entities that registered this item in the Kessel Asset Inventory. The - same resource may be registered by multiple reporters. kessel.inventory.v1beta1.Policy: type: object properties: @@ -660,14 +649,6 @@ components: allOf: - $ref: '#/components/schemas/kessel.inventory.v1beta1.ReporterData' description: Write only reporter specific data - reporters: - readOnly: true - type: array - items: - $ref: '#/components/schemas/kessel.inventory.v1beta1.ReporterData' - description: |- - The entities that registered this item in the Kessel Asset Inventory. The - same resource may be registered by multiple reporters. kessel.inventory.v1beta1.UpdateK8sClusterRequest: type: object properties: @@ -750,7 +731,7 @@ components: description: |- A resource instance using the format: \":\" - host: + rhel_host: allOf: - $ref: '#/components/schemas/kessel.inventory.v1beta1.RhelHost' description: The Rhel host to update