From 4456604ce7eef2ab830c39c9a021fb96197cf181 Mon Sep 17 00:00:00 2001 From: Jonathan Marcantonio Date: Mon, 17 Jun 2024 10:56:27 -0400 Subject: [PATCH] Use kratos validation for lookup.proto Signed-off-by: Jonathan Marcantonio --- Makefile | 13 + api/health/v1/health.pb.go | 12 +- api/health/v1/health.pb.validate.go | 436 +++++++ api/relations/v0/check.pb.go | 8 +- api/relations/v0/check.pb.validate.go | 297 +++++ api/relations/v0/common.pb.go | 116 +- api/relations/v0/common.pb.validate.go | 769 ++++++++++++ api/relations/v0/common.proto | 6 +- api/relations/v0/lookup.pb.go | 110 +- api/relations/v0/lookup.pb.validate.go | 376 ++++++ api/relations/v0/lookup.proto | 8 +- api/relations/v0/relation_tuples.pb.go | 26 +- .../v0/relation_tuples.pb.validate.go | 1100 +++++++++++++++++ go.mod | 4 +- go.sum | 4 +- internal/biz/lookup.go | 31 +- internal/server/grpc.go | 2 + internal/server/http.go | 2 + 18 files changed, 3156 insertions(+), 164 deletions(-) create mode 100644 api/health/v1/health.pb.validate.go create mode 100644 api/relations/v0/check.pb.validate.go create mode 100644 api/relations/v0/common.pb.validate.go create mode 100644 api/relations/v0/lookup.pb.validate.go create mode 100644 api/relations/v0/relation_tuples.pb.validate.go diff --git a/Makefile b/Makefile index 46a84ce..2b854a9 100644 --- a/Makefile +++ b/Makefile @@ -68,9 +68,22 @@ generate: # generate all all: make api; + make validate; make config; make generate; + +# generate validate proto +validate: + protoc --proto_path=./api \ + --proto_path=./third_party \ + --go_out=paths=source_relative:./api \ + --go-http_out=paths=source_relative:./api \ + --go-grpc_out=paths=source_relative:./api \ + --openapi_out=fq_schema_naming=true,default_response=false:. \ + --validate_out=paths=source_relative,lang=go:./api \ + $(API_PROTO_FILES) + # run go linter with the repositories lint config .PHONY: lint lint: diff --git a/api/health/v1/health.pb.go b/api/health/v1/health.pb.go index 7ef95e2..d6888e2 100644 --- a/api/health/v1/health.pb.go +++ b/api/health/v1/health.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 +// protoc-gen-go v1.34.2 // protoc v5.27.0 // source: health/v1/health.proto @@ -220,7 +220,7 @@ func file_health_v1_health_proto_rawDescGZIP() []byte { } var file_health_v1_health_proto_msgTypes = make([]protoimpl.MessageInfo, 4) -var file_health_v1_health_proto_goTypes = []interface{}{ +var file_health_v1_health_proto_goTypes = []any{ (*GetLivezRequest)(nil), // 0: kessel.relations.v1.GetLivezRequest (*GetLivezReply)(nil), // 1: kessel.relations.v1.GetLivezReply (*GetReadyzRequest)(nil), // 2: kessel.relations.v1.GetReadyzRequest @@ -244,7 +244,7 @@ func file_health_v1_health_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_health_v1_health_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_health_v1_health_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*GetLivezRequest); i { case 0: return &v.state @@ -256,7 +256,7 @@ func file_health_v1_health_proto_init() { return nil } } - file_health_v1_health_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_health_v1_health_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*GetLivezReply); i { case 0: return &v.state @@ -268,7 +268,7 @@ func file_health_v1_health_proto_init() { return nil } } - file_health_v1_health_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_health_v1_health_proto_msgTypes[2].Exporter = func(v any, i int) any { switch v := v.(*GetReadyzRequest); i { case 0: return &v.state @@ -280,7 +280,7 @@ func file_health_v1_health_proto_init() { return nil } } - file_health_v1_health_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_health_v1_health_proto_msgTypes[3].Exporter = func(v any, i int) any { switch v := v.(*GetReadyzReply); i { case 0: return &v.state diff --git a/api/health/v1/health.pb.validate.go b/api/health/v1/health.pb.validate.go new file mode 100644 index 0000000..76547cd --- /dev/null +++ b/api/health/v1/health.pb.validate.go @@ -0,0 +1,436 @@ +// Code generated by protoc-gen-validate. DO NOT EDIT. +// source: health/v1/health.proto + +package v1 + +import ( + "bytes" + "errors" + "fmt" + "net" + "net/mail" + "net/url" + "regexp" + "sort" + "strings" + "time" + "unicode/utf8" + + "google.golang.org/protobuf/types/known/anypb" +) + +// ensure the imports are used +var ( + _ = bytes.MinRead + _ = errors.New("") + _ = fmt.Print + _ = utf8.UTFMax + _ = (*regexp.Regexp)(nil) + _ = (*strings.Reader)(nil) + _ = net.IPv4len + _ = time.Duration(0) + _ = (*url.URL)(nil) + _ = (*mail.Address)(nil) + _ = anypb.Any{} + _ = sort.Sort +) + +// Validate checks the field values on GetLivezRequest with the rules defined +// in the proto definition for this message. If any rules are violated, the +// first error encountered is returned, or nil if there are no violations. +func (m *GetLivezRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on GetLivezRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// GetLivezRequestMultiError, or nil if none found. +func (m *GetLivezRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *GetLivezRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if len(errors) > 0 { + return GetLivezRequestMultiError(errors) + } + + return nil +} + +// GetLivezRequestMultiError is an error wrapping multiple validation errors +// returned by GetLivezRequest.ValidateAll() if the designated constraints +// aren't met. +type GetLivezRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m GetLivezRequestMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m GetLivezRequestMultiError) AllErrors() []error { return m } + +// GetLivezRequestValidationError is the validation error returned by +// GetLivezRequest.Validate if the designated constraints aren't met. +type GetLivezRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e GetLivezRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e GetLivezRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e GetLivezRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e GetLivezRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e GetLivezRequestValidationError) ErrorName() string { return "GetLivezRequestValidationError" } + +// Error satisfies the builtin error interface +func (e GetLivezRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sGetLivezRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = GetLivezRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = GetLivezRequestValidationError{} + +// Validate checks the field values on GetLivezReply with the rules defined in +// the proto definition for this message. If any rules are violated, the first +// error encountered is returned, or nil if there are no violations. +func (m *GetLivezReply) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on GetLivezReply with the rules defined +// in the proto definition for this message. If any rules are violated, the +// result is a list of violation errors wrapped in GetLivezReplyMultiError, or +// nil if none found. +func (m *GetLivezReply) ValidateAll() error { + return m.validate(true) +} + +func (m *GetLivezReply) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if len(errors) > 0 { + return GetLivezReplyMultiError(errors) + } + + return nil +} + +// GetLivezReplyMultiError is an error wrapping multiple validation errors +// returned by GetLivezReply.ValidateAll() if the designated constraints +// aren't met. +type GetLivezReplyMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m GetLivezReplyMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m GetLivezReplyMultiError) AllErrors() []error { return m } + +// GetLivezReplyValidationError is the validation error returned by +// GetLivezReply.Validate if the designated constraints aren't met. +type GetLivezReplyValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e GetLivezReplyValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e GetLivezReplyValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e GetLivezReplyValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e GetLivezReplyValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e GetLivezReplyValidationError) ErrorName() string { return "GetLivezReplyValidationError" } + +// Error satisfies the builtin error interface +func (e GetLivezReplyValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sGetLivezReply.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = GetLivezReplyValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = GetLivezReplyValidationError{} + +// Validate checks the field values on GetReadyzRequest with the rules defined +// in the proto definition for this message. If any rules are violated, the +// first error encountered is returned, or nil if there are no violations. +func (m *GetReadyzRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on GetReadyzRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// GetReadyzRequestMultiError, or nil if none found. +func (m *GetReadyzRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *GetReadyzRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if len(errors) > 0 { + return GetReadyzRequestMultiError(errors) + } + + return nil +} + +// GetReadyzRequestMultiError is an error wrapping multiple validation errors +// returned by GetReadyzRequest.ValidateAll() if the designated constraints +// aren't met. +type GetReadyzRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m GetReadyzRequestMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m GetReadyzRequestMultiError) AllErrors() []error { return m } + +// GetReadyzRequestValidationError is the validation error returned by +// GetReadyzRequest.Validate if the designated constraints aren't met. +type GetReadyzRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e GetReadyzRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e GetReadyzRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e GetReadyzRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e GetReadyzRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e GetReadyzRequestValidationError) ErrorName() string { return "GetReadyzRequestValidationError" } + +// Error satisfies the builtin error interface +func (e GetReadyzRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sGetReadyzRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = GetReadyzRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = GetReadyzRequestValidationError{} + +// Validate checks the field values on GetReadyzReply with the rules defined in +// the proto definition for this message. If any rules are violated, the first +// error encountered is returned, or nil if there are no violations. +func (m *GetReadyzReply) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on GetReadyzReply with the rules defined +// in the proto definition for this message. If any rules are violated, the +// result is a list of violation errors wrapped in GetReadyzReplyMultiError, +// or nil if none found. +func (m *GetReadyzReply) ValidateAll() error { + return m.validate(true) +} + +func (m *GetReadyzReply) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if len(errors) > 0 { + return GetReadyzReplyMultiError(errors) + } + + return nil +} + +// GetReadyzReplyMultiError is an error wrapping multiple validation errors +// returned by GetReadyzReply.ValidateAll() if the designated constraints +// aren't met. +type GetReadyzReplyMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m GetReadyzReplyMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m GetReadyzReplyMultiError) AllErrors() []error { return m } + +// GetReadyzReplyValidationError is the validation error returned by +// GetReadyzReply.Validate if the designated constraints aren't met. +type GetReadyzReplyValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e GetReadyzReplyValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e GetReadyzReplyValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e GetReadyzReplyValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e GetReadyzReplyValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e GetReadyzReplyValidationError) ErrorName() string { return "GetReadyzReplyValidationError" } + +// Error satisfies the builtin error interface +func (e GetReadyzReplyValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sGetReadyzReply.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = GetReadyzReplyValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = GetReadyzReplyValidationError{} diff --git a/api/relations/v0/check.pb.go b/api/relations/v0/check.pb.go index ff55a8e..4d1cdc3 100644 --- a/api/relations/v0/check.pb.go +++ b/api/relations/v0/check.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 +// protoc-gen-go v1.34.2 // protoc v5.27.0 // source: relations/v0/check.proto @@ -240,7 +240,7 @@ func file_relations_v0_check_proto_rawDescGZIP() []byte { var file_relations_v0_check_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_relations_v0_check_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_relations_v0_check_proto_goTypes = []interface{}{ +var file_relations_v0_check_proto_goTypes = []any{ (CheckResponse_Allowed)(0), // 0: kessel.relations.v0.CheckResponse.Allowed (*CheckRequest)(nil), // 1: kessel.relations.v0.CheckRequest (*CheckResponse)(nil), // 2: kessel.relations.v0.CheckResponse @@ -267,7 +267,7 @@ func file_relations_v0_check_proto_init() { } file_relations_v0_common_proto_init() if !protoimpl.UnsafeEnabled { - file_relations_v0_check_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_check_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*CheckRequest); i { case 0: return &v.state @@ -279,7 +279,7 @@ func file_relations_v0_check_proto_init() { return nil } } - file_relations_v0_check_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_check_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*CheckResponse); i { case 0: return &v.state diff --git a/api/relations/v0/check.pb.validate.go b/api/relations/v0/check.pb.validate.go new file mode 100644 index 0000000..1c98967 --- /dev/null +++ b/api/relations/v0/check.pb.validate.go @@ -0,0 +1,297 @@ +// Code generated by protoc-gen-validate. DO NOT EDIT. +// source: relations/v0/check.proto + +package v0 + +import ( + "bytes" + "errors" + "fmt" + "net" + "net/mail" + "net/url" + "regexp" + "sort" + "strings" + "time" + "unicode/utf8" + + "google.golang.org/protobuf/types/known/anypb" +) + +// ensure the imports are used +var ( + _ = bytes.MinRead + _ = errors.New("") + _ = fmt.Print + _ = utf8.UTFMax + _ = (*regexp.Regexp)(nil) + _ = (*strings.Reader)(nil) + _ = net.IPv4len + _ = time.Duration(0) + _ = (*url.URL)(nil) + _ = (*mail.Address)(nil) + _ = anypb.Any{} + _ = sort.Sort +) + +// Validate checks the field values on CheckRequest with the rules defined in +// the proto definition for this message. If any rules are violated, the first +// error encountered is returned, or nil if there are no violations. +func (m *CheckRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on CheckRequest with the rules defined +// in the proto definition for this message. If any rules are violated, the +// result is a list of violation errors wrapped in CheckRequestMultiError, or +// nil if none found. +func (m *CheckRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *CheckRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if all { + switch v := interface{}(m.GetResource()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, CheckRequestValidationError{ + field: "Resource", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, CheckRequestValidationError{ + field: "Resource", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetResource()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return CheckRequestValidationError{ + field: "Resource", + reason: "embedded message failed validation", + cause: err, + } + } + } + + // no validation rules for Relation + + if all { + switch v := interface{}(m.GetSubject()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, CheckRequestValidationError{ + field: "Subject", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, CheckRequestValidationError{ + field: "Subject", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetSubject()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return CheckRequestValidationError{ + field: "Subject", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if len(errors) > 0 { + return CheckRequestMultiError(errors) + } + + return nil +} + +// CheckRequestMultiError is an error wrapping multiple validation errors +// returned by CheckRequest.ValidateAll() if the designated constraints aren't met. +type CheckRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m CheckRequestMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m CheckRequestMultiError) AllErrors() []error { return m } + +// CheckRequestValidationError is the validation error returned by +// CheckRequest.Validate if the designated constraints aren't met. +type CheckRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e CheckRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e CheckRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e CheckRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e CheckRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e CheckRequestValidationError) ErrorName() string { return "CheckRequestValidationError" } + +// Error satisfies the builtin error interface +func (e CheckRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sCheckRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = CheckRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = CheckRequestValidationError{} + +// Validate checks the field values on CheckResponse with the rules defined in +// the proto definition for this message. If any rules are violated, the first +// error encountered is returned, or nil if there are no violations. +func (m *CheckResponse) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on CheckResponse with the rules defined +// in the proto definition for this message. If any rules are violated, the +// result is a list of violation errors wrapped in CheckResponseMultiError, or +// nil if none found. +func (m *CheckResponse) ValidateAll() error { + return m.validate(true) +} + +func (m *CheckResponse) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + // no validation rules for Allowed + + if len(errors) > 0 { + return CheckResponseMultiError(errors) + } + + return nil +} + +// CheckResponseMultiError is an error wrapping multiple validation errors +// returned by CheckResponse.ValidateAll() if the designated constraints +// aren't met. +type CheckResponseMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m CheckResponseMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m CheckResponseMultiError) AllErrors() []error { return m } + +// CheckResponseValidationError is the validation error returned by +// CheckResponse.Validate if the designated constraints aren't met. +type CheckResponseValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e CheckResponseValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e CheckResponseValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e CheckResponseValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e CheckResponseValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e CheckResponseValidationError) ErrorName() string { return "CheckResponseValidationError" } + +// Error satisfies the builtin error interface +func (e CheckResponseValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sCheckResponse.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = CheckResponseValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = CheckResponseValidationError{} diff --git a/api/relations/v0/common.pb.go b/api/relations/v0/common.pb.go index 0a31ce4..91bf6d0 100644 --- a/api/relations/v0/common.pb.go +++ b/api/relations/v0/common.pb.go @@ -1,12 +1,13 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 +// protoc-gen-go v1.34.2 // protoc v5.27.0 // source: relations/v0/common.proto package v0 import ( + _ "github.com/envoyproxy/protoc-gen-validate/validate" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -368,52 +369,55 @@ var file_relations_v0_common_proto_rawDesc = []byte{ 0x0a, 0x19, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x76, 0x30, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x13, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, - 0x22, 0xad, 0x01, 0x0a, 0x0c, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x68, 0x69, - 0x70, 0x12, 0x40, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, - 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, - 0x72, 0x63, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, - 0x3f, 0x0a, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x25, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, - 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, - 0x22, 0x80, 0x01, 0x0a, 0x10, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x66, 0x65, - 0x72, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1f, 0x0a, 0x08, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x08, 0x72, 0x65, 0x6c, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x88, 0x01, 0x01, 0x12, 0x3e, 0x0a, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, - 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, - 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x4f, 0x62, - 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x07, 0x73, - 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x72, 0x65, 0x6c, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x22, 0x74, 0x0a, 0x11, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x50, 0x61, - 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, - 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x32, - 0x0a, 0x12, 0x63, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, - 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x11, 0x63, 0x6f, - 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x88, - 0x01, 0x01, 0x42, 0x15, 0x0a, 0x13, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x43, 0x0a, 0x12, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x50, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, - 0x2d, 0x0a, 0x12, 0x63, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, - 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x63, 0x6f, 0x6e, - 0x74, 0x69, 0x6e, 0x75, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x56, - 0x0a, 0x0f, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, - 0x65, 0x12, 0x33, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x1f, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x54, 0x79, 0x70, 0x65, - 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x3e, 0x0a, 0x0a, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, - 0x54, 0x79, 0x70, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, - 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, - 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x42, 0x47, 0x0a, 0x23, 0x6f, 0x72, 0x67, 0x2e, 0x70, 0x72, - 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x50, 0x01, 0x5a, - 0x1e, 0x63, 0x69, 0x61, 0x6d, 0x2d, 0x72, 0x65, 0x62, 0x61, 0x63, 0x2f, 0x61, 0x70, 0x69, 0x2f, - 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x76, 0x30, 0x3b, 0x76, 0x30, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 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, 0xad, 0x01, 0x0a, 0x0c, 0x52, 0x65, + 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x68, 0x69, 0x70, 0x12, 0x40, 0x0a, 0x08, 0x72, 0x65, + 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6b, + 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, + 0x76, 0x30, 0x2e, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, + 0x63, 0x65, 0x52, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x1a, 0x0a, 0x08, + 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x3f, 0x0a, 0x07, 0x73, 0x75, 0x62, 0x6a, + 0x65, 0x63, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x6b, 0x65, 0x73, 0x73, + 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, + 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, + 0x52, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x80, 0x01, 0x0a, 0x10, 0x53, 0x75, + 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1f, + 0x0a, 0x08, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x48, 0x00, 0x52, 0x08, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x88, 0x01, 0x01, 0x12, + 0x3e, 0x0a, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x24, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x66, + 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x42, + 0x0b, 0x0a, 0x09, 0x5f, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x74, 0x0a, 0x11, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x50, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, + 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x32, 0x0a, 0x12, 0x63, 0x6f, 0x6e, 0x74, 0x69, + 0x6e, 0x75, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x11, 0x63, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x88, 0x01, 0x01, 0x42, 0x15, 0x0a, 0x13, 0x5f, + 0x63, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x22, 0x43, 0x0a, 0x12, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x50, 0x61, + 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x2d, 0x0a, 0x12, 0x63, 0x6f, 0x6e, 0x74, + 0x69, 0x6e, 0x75, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x63, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x69, 0x0a, 0x0f, 0x4f, 0x62, 0x6a, 0x65, 0x63, + 0x74, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x3d, 0x0a, 0x04, 0x74, 0x79, + 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, + 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x4f, + 0x62, 0x6a, 0x65, 0x63, 0x74, 0x54, 0x79, 0x70, 0x65, 0x42, 0x08, 0xfa, 0x42, 0x05, 0xa2, 0x01, + 0x02, 0x08, 0x01, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x02, + 0x69, 0x64, 0x22, 0x3e, 0x0a, 0x0a, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x54, 0x79, 0x70, 0x65, + 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x12, + 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x42, 0x47, 0x0a, 0x23, 0x6f, 0x72, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, + 0x74, 0x5f, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x72, 0x65, 0x6c, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x50, 0x01, 0x5a, 0x1e, 0x63, 0x69, 0x61, + 0x6d, 0x2d, 0x72, 0x65, 0x62, 0x61, 0x63, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x72, 0x65, 0x6c, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x76, 0x30, 0x3b, 0x76, 0x30, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -429,7 +433,7 @@ func file_relations_v0_common_proto_rawDescGZIP() []byte { } var file_relations_v0_common_proto_msgTypes = make([]protoimpl.MessageInfo, 6) -var file_relations_v0_common_proto_goTypes = []interface{}{ +var file_relations_v0_common_proto_goTypes = []any{ (*Relationship)(nil), // 0: kessel.relations.v0.Relationship (*SubjectReference)(nil), // 1: kessel.relations.v0.SubjectReference (*RequestPagination)(nil), // 2: kessel.relations.v0.RequestPagination @@ -455,7 +459,7 @@ func file_relations_v0_common_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_relations_v0_common_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_common_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*Relationship); i { case 0: return &v.state @@ -467,7 +471,7 @@ func file_relations_v0_common_proto_init() { return nil } } - file_relations_v0_common_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_common_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*SubjectReference); i { case 0: return &v.state @@ -479,7 +483,7 @@ func file_relations_v0_common_proto_init() { return nil } } - file_relations_v0_common_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_common_proto_msgTypes[2].Exporter = func(v any, i int) any { switch v := v.(*RequestPagination); i { case 0: return &v.state @@ -491,7 +495,7 @@ func file_relations_v0_common_proto_init() { return nil } } - file_relations_v0_common_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_common_proto_msgTypes[3].Exporter = func(v any, i int) any { switch v := v.(*ResponsePagination); i { case 0: return &v.state @@ -503,7 +507,7 @@ func file_relations_v0_common_proto_init() { return nil } } - file_relations_v0_common_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_common_proto_msgTypes[4].Exporter = func(v any, i int) any { switch v := v.(*ObjectReference); i { case 0: return &v.state @@ -515,7 +519,7 @@ func file_relations_v0_common_proto_init() { return nil } } - file_relations_v0_common_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_common_proto_msgTypes[5].Exporter = func(v any, i int) any { switch v := v.(*ObjectType); i { case 0: return &v.state @@ -528,8 +532,8 @@ func file_relations_v0_common_proto_init() { } } } - file_relations_v0_common_proto_msgTypes[1].OneofWrappers = []interface{}{} - file_relations_v0_common_proto_msgTypes[2].OneofWrappers = []interface{}{} + file_relations_v0_common_proto_msgTypes[1].OneofWrappers = []any{} + file_relations_v0_common_proto_msgTypes[2].OneofWrappers = []any{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ diff --git a/api/relations/v0/common.pb.validate.go b/api/relations/v0/common.pb.validate.go new file mode 100644 index 0000000..eb6dd38 --- /dev/null +++ b/api/relations/v0/common.pb.validate.go @@ -0,0 +1,769 @@ +// Code generated by protoc-gen-validate. DO NOT EDIT. +// source: relations/v0/common.proto + +package v0 + +import ( + "bytes" + "errors" + "fmt" + "net" + "net/mail" + "net/url" + "regexp" + "sort" + "strings" + "time" + "unicode/utf8" + + "google.golang.org/protobuf/types/known/anypb" +) + +// ensure the imports are used +var ( + _ = bytes.MinRead + _ = errors.New("") + _ = fmt.Print + _ = utf8.UTFMax + _ = (*regexp.Regexp)(nil) + _ = (*strings.Reader)(nil) + _ = net.IPv4len + _ = time.Duration(0) + _ = (*url.URL)(nil) + _ = (*mail.Address)(nil) + _ = anypb.Any{} + _ = sort.Sort +) + +// Validate checks the field values on Relationship with the rules defined in +// the proto definition for this message. If any rules are violated, the first +// error encountered is returned, or nil if there are no violations. +func (m *Relationship) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on Relationship with the rules defined +// in the proto definition for this message. If any rules are violated, the +// result is a list of violation errors wrapped in RelationshipMultiError, or +// nil if none found. +func (m *Relationship) ValidateAll() error { + return m.validate(true) +} + +func (m *Relationship) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if all { + switch v := interface{}(m.GetResource()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, RelationshipValidationError{ + field: "Resource", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, RelationshipValidationError{ + field: "Resource", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetResource()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return RelationshipValidationError{ + field: "Resource", + reason: "embedded message failed validation", + cause: err, + } + } + } + + // no validation rules for Relation + + if all { + switch v := interface{}(m.GetSubject()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, RelationshipValidationError{ + field: "Subject", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, RelationshipValidationError{ + field: "Subject", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetSubject()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return RelationshipValidationError{ + field: "Subject", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if len(errors) > 0 { + return RelationshipMultiError(errors) + } + + return nil +} + +// RelationshipMultiError is an error wrapping multiple validation errors +// returned by Relationship.ValidateAll() if the designated constraints aren't met. +type RelationshipMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m RelationshipMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m RelationshipMultiError) AllErrors() []error { return m } + +// RelationshipValidationError is the validation error returned by +// Relationship.Validate if the designated constraints aren't met. +type RelationshipValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e RelationshipValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e RelationshipValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e RelationshipValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e RelationshipValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e RelationshipValidationError) ErrorName() string { return "RelationshipValidationError" } + +// Error satisfies the builtin error interface +func (e RelationshipValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sRelationship.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = RelationshipValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = RelationshipValidationError{} + +// Validate checks the field values on SubjectReference with the rules defined +// in the proto definition for this message. If any rules are violated, the +// first error encountered is returned, or nil if there are no violations. +func (m *SubjectReference) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on SubjectReference with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// SubjectReferenceMultiError, or nil if none found. +func (m *SubjectReference) ValidateAll() error { + return m.validate(true) +} + +func (m *SubjectReference) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if all { + switch v := interface{}(m.GetSubject()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, SubjectReferenceValidationError{ + field: "Subject", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, SubjectReferenceValidationError{ + field: "Subject", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetSubject()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return SubjectReferenceValidationError{ + field: "Subject", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if m.Relation != nil { + // no validation rules for Relation + } + + if len(errors) > 0 { + return SubjectReferenceMultiError(errors) + } + + return nil +} + +// SubjectReferenceMultiError is an error wrapping multiple validation errors +// returned by SubjectReference.ValidateAll() if the designated constraints +// aren't met. +type SubjectReferenceMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m SubjectReferenceMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m SubjectReferenceMultiError) AllErrors() []error { return m } + +// SubjectReferenceValidationError is the validation error returned by +// SubjectReference.Validate if the designated constraints aren't met. +type SubjectReferenceValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e SubjectReferenceValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e SubjectReferenceValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e SubjectReferenceValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e SubjectReferenceValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e SubjectReferenceValidationError) ErrorName() string { return "SubjectReferenceValidationError" } + +// Error satisfies the builtin error interface +func (e SubjectReferenceValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sSubjectReference.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = SubjectReferenceValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = SubjectReferenceValidationError{} + +// Validate checks the field values on RequestPagination with the rules defined +// in the proto definition for this message. If any rules are violated, the +// first error encountered is returned, or nil if there are no violations. +func (m *RequestPagination) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on RequestPagination with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// RequestPaginationMultiError, or nil if none found. +func (m *RequestPagination) ValidateAll() error { + return m.validate(true) +} + +func (m *RequestPagination) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + // no validation rules for Limit + + if m.ContinuationToken != nil { + // no validation rules for ContinuationToken + } + + if len(errors) > 0 { + return RequestPaginationMultiError(errors) + } + + return nil +} + +// RequestPaginationMultiError is an error wrapping multiple validation errors +// returned by RequestPagination.ValidateAll() if the designated constraints +// aren't met. +type RequestPaginationMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m RequestPaginationMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m RequestPaginationMultiError) AllErrors() []error { return m } + +// RequestPaginationValidationError is the validation error returned by +// RequestPagination.Validate if the designated constraints aren't met. +type RequestPaginationValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e RequestPaginationValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e RequestPaginationValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e RequestPaginationValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e RequestPaginationValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e RequestPaginationValidationError) ErrorName() string { + return "RequestPaginationValidationError" +} + +// Error satisfies the builtin error interface +func (e RequestPaginationValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sRequestPagination.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = RequestPaginationValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = RequestPaginationValidationError{} + +// Validate checks the field values on ResponsePagination with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *ResponsePagination) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on ResponsePagination with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// ResponsePaginationMultiError, or nil if none found. +func (m *ResponsePagination) ValidateAll() error { + return m.validate(true) +} + +func (m *ResponsePagination) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + // no validation rules for ContinuationToken + + if len(errors) > 0 { + return ResponsePaginationMultiError(errors) + } + + return nil +} + +// ResponsePaginationMultiError is an error wrapping multiple validation errors +// returned by ResponsePagination.ValidateAll() if the designated constraints +// aren't met. +type ResponsePaginationMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m ResponsePaginationMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m ResponsePaginationMultiError) AllErrors() []error { return m } + +// ResponsePaginationValidationError is the validation error returned by +// ResponsePagination.Validate if the designated constraints aren't met. +type ResponsePaginationValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e ResponsePaginationValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e ResponsePaginationValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e ResponsePaginationValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e ResponsePaginationValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e ResponsePaginationValidationError) ErrorName() string { + return "ResponsePaginationValidationError" +} + +// Error satisfies the builtin error interface +func (e ResponsePaginationValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sResponsePagination.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = ResponsePaginationValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = ResponsePaginationValidationError{} + +// Validate checks the field values on ObjectReference with the rules defined +// in the proto definition for this message. If any rules are violated, the +// first error encountered is returned, or nil if there are no violations. +func (m *ObjectReference) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on ObjectReference with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// ObjectReferenceMultiError, or nil if none found. +func (m *ObjectReference) ValidateAll() error { + return m.validate(true) +} + +func (m *ObjectReference) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if m.GetType() == nil { + err := ObjectReferenceValidationError{ + field: "Type", + reason: "value is required", + } + if !all { + return err + } + errors = append(errors, err) + } + + if a := m.GetType(); a != nil { + + } + + if utf8.RuneCountInString(m.GetId()) < 1 { + err := ObjectReferenceValidationError{ + field: "Id", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } + + if len(errors) > 0 { + return ObjectReferenceMultiError(errors) + } + + return nil +} + +// ObjectReferenceMultiError is an error wrapping multiple validation errors +// returned by ObjectReference.ValidateAll() if the designated constraints +// aren't met. +type ObjectReferenceMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m ObjectReferenceMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m ObjectReferenceMultiError) AllErrors() []error { return m } + +// ObjectReferenceValidationError is the validation error returned by +// ObjectReference.Validate if the designated constraints aren't met. +type ObjectReferenceValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e ObjectReferenceValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e ObjectReferenceValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e ObjectReferenceValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e ObjectReferenceValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e ObjectReferenceValidationError) ErrorName() string { return "ObjectReferenceValidationError" } + +// Error satisfies the builtin error interface +func (e ObjectReferenceValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sObjectReference.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = ObjectReferenceValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = ObjectReferenceValidationError{} + +// Validate checks the field values on ObjectType with the rules defined in the +// proto definition for this message. If any rules are violated, the first +// error encountered is returned, or nil if there are no violations. +func (m *ObjectType) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on ObjectType with the rules defined in +// the proto definition for this message. If any rules are violated, the +// result is a list of violation errors wrapped in ObjectTypeMultiError, or +// nil if none found. +func (m *ObjectType) ValidateAll() error { + return m.validate(true) +} + +func (m *ObjectType) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + // no validation rules for Namespace + + // no validation rules for Name + + if len(errors) > 0 { + return ObjectTypeMultiError(errors) + } + + return nil +} + +// ObjectTypeMultiError is an error wrapping multiple validation errors +// returned by ObjectType.ValidateAll() if the designated constraints aren't met. +type ObjectTypeMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m ObjectTypeMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m ObjectTypeMultiError) AllErrors() []error { return m } + +// ObjectTypeValidationError is the validation error returned by +// ObjectType.Validate if the designated constraints aren't met. +type ObjectTypeValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e ObjectTypeValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e ObjectTypeValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e ObjectTypeValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e ObjectTypeValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e ObjectTypeValidationError) ErrorName() string { return "ObjectTypeValidationError" } + +// Error satisfies the builtin error interface +func (e ObjectTypeValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sObjectType.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = ObjectTypeValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = ObjectTypeValidationError{} diff --git a/api/relations/v0/common.proto b/api/relations/v0/common.proto index 2218c0f..16a6c06 100644 --- a/api/relations/v0/common.proto +++ b/api/relations/v0/common.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package kessel.relations.v0; +import "validate/validate.proto"; + option go_package = "ciam-rebac/api/relations/v0;v0"; option java_multiple_files = true; option java_package = "org.project_kessel.api.relations.v0"; @@ -39,8 +41,8 @@ message ResponsePagination { } message ObjectReference { - ObjectType type = 1; - string id = 2; + ObjectType type = 1 [(validate.rules).any.required = true]; + string id = 2 [(validate.rules).string.min_len = 1]; } message ObjectType { diff --git a/api/relations/v0/lookup.pb.go b/api/relations/v0/lookup.pb.go index 894e964..6ee2e4b 100644 --- a/api/relations/v0/lookup.pb.go +++ b/api/relations/v0/lookup.pb.go @@ -1,12 +1,13 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 +// protoc-gen-go v1.34.2 // protoc v5.27.0 // source: relations/v0/lookup.proto package v0 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" @@ -164,54 +165,57 @@ var file_relations_v0_lookup_proto_rawDesc = []byte{ 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, 0x19, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x76, 0x30, 0x2f, 0x63, 0x6f, 0x6d, - 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xda, 0x02, 0x0a, 0x15, 0x4c, 0x6f, - 0x6f, 0x6b, 0x75, 0x70, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x40, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x72, - 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x4f, 0x62, 0x6a, 0x65, - 0x63, 0x74, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x72, 0x65, 0x73, - 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x12, 0x42, 0x0a, 0x0c, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x74, 0x79, 0x70, - 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, - 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x4f, 0x62, - 0x6a, 0x65, 0x63, 0x74, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0b, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, - 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x2e, 0x0a, 0x10, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, - 0x5f, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x48, - 0x00, 0x52, 0x0f, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x88, 0x01, 0x01, 0x12, 0x4b, 0x0a, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x6b, 0x65, 0x73, 0x73, - 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x50, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x48, 0x01, 0x52, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x88, - 0x01, 0x01, 0x42, 0x13, 0x0a, 0x11, 0x5f, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x72, - 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x70, 0x61, 0x67, 0x69, - 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0xa2, 0x01, 0x0a, 0x16, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, - 0x70, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x3f, 0x0a, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, - 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, - 0x63, 0x74, 0x12, 0x47, 0x0a, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, - 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x50, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, - 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x32, 0x99, 0x01, 0x0a, 0x13, - 0x4b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x53, 0x65, 0x72, 0x76, - 0x69, 0x63, 0x65, 0x12, 0x81, 0x01, 0x0a, 0x0e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x53, 0x75, - 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x12, 0x2a, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, - 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x4c, 0x6f, 0x6f, - 0x6b, 0x75, 0x70, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x53, - 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x14, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0e, 0x12, 0x0c, 0x2f, 0x76, 0x30, 0x2f, 0x73, 0x75, 0x62, - 0x6a, 0x65, 0x63, 0x74, 0x73, 0x30, 0x01, 0x42, 0x47, 0x0a, 0x23, 0x6f, 0x72, 0x67, 0x2e, 0x70, - 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x61, 0x70, - 0x69, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x50, 0x01, - 0x5a, 0x1e, 0x63, 0x69, 0x61, 0x6d, 0x2d, 0x72, 0x65, 0x62, 0x61, 0x63, 0x2f, 0x61, 0x70, 0x69, - 0x2f, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x76, 0x30, 0x3b, 0x76, 0x30, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x76, 0x61, 0x6c, 0x69, 0x64, + 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x22, 0xf7, 0x02, 0x0a, 0x15, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x53, 0x75, 0x62, + 0x6a, 0x65, 0x63, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x4a, 0x0a, 0x08, + 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, + 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x66, 0x65, 0x72, + 0x65, 0x6e, 0x63, 0x65, 0x42, 0x08, 0xfa, 0x42, 0x05, 0xa2, 0x01, 0x02, 0x08, 0x01, 0x52, 0x08, + 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x23, 0x0a, 0x08, 0x72, 0x65, 0x6c, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, + 0x02, 0x10, 0x01, 0x52, 0x08, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x4c, 0x0a, + 0x0c, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, + 0x54, 0x79, 0x70, 0x65, 0x42, 0x08, 0xfa, 0x42, 0x05, 0xa2, 0x01, 0x02, 0x08, 0x01, 0x52, 0x0b, + 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x2e, 0x0a, 0x10, 0x73, + 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0f, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, + 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x88, 0x01, 0x01, 0x12, 0x4b, 0x0a, 0x0a, 0x70, + 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x26, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x50, 0x61, 0x67, + 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x48, 0x01, 0x52, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x88, 0x01, 0x01, 0x42, 0x13, 0x0a, 0x11, 0x5f, 0x73, 0x75, 0x62, + 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x0d, 0x0a, + 0x0b, 0x5f, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0xa2, 0x01, 0x0a, + 0x16, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3f, 0x0a, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, + 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, + 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x53, + 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x52, + 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x47, 0x0a, 0x0a, 0x70, 0x61, 0x67, 0x69, + 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x6b, + 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, + 0x76, 0x30, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x50, 0x61, 0x67, 0x69, 0x6e, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x32, 0x99, 0x01, 0x0a, 0x13, 0x4b, 0x65, 0x73, 0x73, 0x65, 0x6c, 0x4c, 0x6f, 0x6f, 0x6b, + 0x75, 0x70, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x81, 0x01, 0x0a, 0x0e, 0x4c, 0x6f, + 0x6f, 0x6b, 0x75, 0x70, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x12, 0x2a, 0x2e, 0x6b, + 0x65, 0x73, 0x73, 0x65, 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, + 0x76, 0x30, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, + 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x6b, 0x65, 0x73, 0x73, 0x65, + 0x6c, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x76, 0x30, 0x2e, 0x4c, + 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x14, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0e, 0x12, 0x0c, 0x2f, + 0x76, 0x30, 0x2f, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x30, 0x01, 0x42, 0x47, 0x0a, + 0x23, 0x6f, 0x72, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x6b, 0x65, 0x73, + 0x73, 0x65, 0x6c, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x2e, 0x76, 0x30, 0x50, 0x01, 0x5a, 0x1e, 0x63, 0x69, 0x61, 0x6d, 0x2d, 0x72, 0x65, 0x62, + 0x61, 0x63, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x2f, 0x76, 0x30, 0x3b, 0x76, 0x30, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -227,7 +231,7 @@ func file_relations_v0_lookup_proto_rawDescGZIP() []byte { } var file_relations_v0_lookup_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_relations_v0_lookup_proto_goTypes = []interface{}{ +var file_relations_v0_lookup_proto_goTypes = []any{ (*LookupSubjectsRequest)(nil), // 0: kessel.relations.v0.LookupSubjectsRequest (*LookupSubjectsResponse)(nil), // 1: kessel.relations.v0.LookupSubjectsResponse (*ObjectReference)(nil), // 2: kessel.relations.v0.ObjectReference @@ -258,7 +262,7 @@ func file_relations_v0_lookup_proto_init() { } file_relations_v0_common_proto_init() if !protoimpl.UnsafeEnabled { - file_relations_v0_lookup_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_lookup_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*LookupSubjectsRequest); i { case 0: return &v.state @@ -270,7 +274,7 @@ func file_relations_v0_lookup_proto_init() { return nil } } - file_relations_v0_lookup_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_lookup_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*LookupSubjectsResponse); i { case 0: return &v.state @@ -283,7 +287,7 @@ func file_relations_v0_lookup_proto_init() { } } } - file_relations_v0_lookup_proto_msgTypes[0].OneofWrappers = []interface{}{} + file_relations_v0_lookup_proto_msgTypes[0].OneofWrappers = []any{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ diff --git a/api/relations/v0/lookup.pb.validate.go b/api/relations/v0/lookup.pb.validate.go new file mode 100644 index 0000000..9dcfbf4 --- /dev/null +++ b/api/relations/v0/lookup.pb.validate.go @@ -0,0 +1,376 @@ +// Code generated by protoc-gen-validate. DO NOT EDIT. +// source: relations/v0/lookup.proto + +package v0 + +import ( + "bytes" + "errors" + "fmt" + "net" + "net/mail" + "net/url" + "regexp" + "sort" + "strings" + "time" + "unicode/utf8" + + "google.golang.org/protobuf/types/known/anypb" +) + +// ensure the imports are used +var ( + _ = bytes.MinRead + _ = errors.New("") + _ = fmt.Print + _ = utf8.UTFMax + _ = (*regexp.Regexp)(nil) + _ = (*strings.Reader)(nil) + _ = net.IPv4len + _ = time.Duration(0) + _ = (*url.URL)(nil) + _ = (*mail.Address)(nil) + _ = anypb.Any{} + _ = sort.Sort +) + +// Validate checks the field values on LookupSubjectsRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *LookupSubjectsRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on LookupSubjectsRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// LookupSubjectsRequestMultiError, or nil if none found. +func (m *LookupSubjectsRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *LookupSubjectsRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if m.GetResource() == nil { + err := LookupSubjectsRequestValidationError{ + field: "Resource", + reason: "value is required", + } + if !all { + return err + } + errors = append(errors, err) + } + + if a := m.GetResource(); a != nil { + + } + + if utf8.RuneCountInString(m.GetRelation()) < 1 { + err := LookupSubjectsRequestValidationError{ + field: "Relation", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } + + if m.GetSubjectType() == nil { + err := LookupSubjectsRequestValidationError{ + field: "SubjectType", + reason: "value is required", + } + if !all { + return err + } + errors = append(errors, err) + } + + if a := m.GetSubjectType(); a != nil { + + } + + if m.SubjectRelation != nil { + // no validation rules for SubjectRelation + } + + if m.Pagination != nil { + + if all { + switch v := interface{}(m.GetPagination()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, LookupSubjectsRequestValidationError{ + field: "Pagination", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, LookupSubjectsRequestValidationError{ + field: "Pagination", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetPagination()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return LookupSubjectsRequestValidationError{ + field: "Pagination", + reason: "embedded message failed validation", + cause: err, + } + } + } + + } + + if len(errors) > 0 { + return LookupSubjectsRequestMultiError(errors) + } + + return nil +} + +// LookupSubjectsRequestMultiError is an error wrapping multiple validation +// errors returned by LookupSubjectsRequest.ValidateAll() if the designated +// constraints aren't met. +type LookupSubjectsRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m LookupSubjectsRequestMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m LookupSubjectsRequestMultiError) AllErrors() []error { return m } + +// LookupSubjectsRequestValidationError is the validation error returned by +// LookupSubjectsRequest.Validate if the designated constraints aren't met. +type LookupSubjectsRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e LookupSubjectsRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e LookupSubjectsRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e LookupSubjectsRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e LookupSubjectsRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e LookupSubjectsRequestValidationError) ErrorName() string { + return "LookupSubjectsRequestValidationError" +} + +// Error satisfies the builtin error interface +func (e LookupSubjectsRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sLookupSubjectsRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = LookupSubjectsRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = LookupSubjectsRequestValidationError{} + +// Validate checks the field values on LookupSubjectsResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *LookupSubjectsResponse) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on LookupSubjectsResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// LookupSubjectsResponseMultiError, or nil if none found. +func (m *LookupSubjectsResponse) ValidateAll() error { + return m.validate(true) +} + +func (m *LookupSubjectsResponse) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if all { + switch v := interface{}(m.GetSubject()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, LookupSubjectsResponseValidationError{ + field: "Subject", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, LookupSubjectsResponseValidationError{ + field: "Subject", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetSubject()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return LookupSubjectsResponseValidationError{ + field: "Subject", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if all { + switch v := interface{}(m.GetPagination()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, LookupSubjectsResponseValidationError{ + field: "Pagination", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, LookupSubjectsResponseValidationError{ + field: "Pagination", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetPagination()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return LookupSubjectsResponseValidationError{ + field: "Pagination", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if len(errors) > 0 { + return LookupSubjectsResponseMultiError(errors) + } + + return nil +} + +// LookupSubjectsResponseMultiError is an error wrapping multiple validation +// errors returned by LookupSubjectsResponse.ValidateAll() if the designated +// constraints aren't met. +type LookupSubjectsResponseMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m LookupSubjectsResponseMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m LookupSubjectsResponseMultiError) AllErrors() []error { return m } + +// LookupSubjectsResponseValidationError is the validation error returned by +// LookupSubjectsResponse.Validate if the designated constraints aren't met. +type LookupSubjectsResponseValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e LookupSubjectsResponseValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e LookupSubjectsResponseValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e LookupSubjectsResponseValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e LookupSubjectsResponseValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e LookupSubjectsResponseValidationError) ErrorName() string { + return "LookupSubjectsResponseValidationError" +} + +// Error satisfies the builtin error interface +func (e LookupSubjectsResponseValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sLookupSubjectsResponse.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = LookupSubjectsResponseValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = LookupSubjectsResponseValidationError{} diff --git a/api/relations/v0/lookup.proto b/api/relations/v0/lookup.proto index de97bab..2fc9626 100644 --- a/api/relations/v0/lookup.proto +++ b/api/relations/v0/lookup.proto @@ -4,6 +4,8 @@ package kessel.relations.v0; import "google/api/annotations.proto"; import "relations/v0/common.proto"; +import "validate/validate.proto"; + option go_package = "ciam-rebac/api/relations/v0;v0"; option java_multiple_files = true; @@ -18,9 +20,9 @@ service KesselLookupService { } message LookupSubjectsRequest { - ObjectReference resource = 1; - string relation = 2; - ObjectType subject_type = 3; + ObjectReference resource = 1 [(validate.rules).any.required = true]; + string relation = 2 [(validate.rules).string.min_len = 1]; + ObjectType subject_type = 3 [(validate.rules).any.required = true]; optional string subject_relation = 4; optional RequestPagination pagination = 5; } diff --git a/api/relations/v0/relation_tuples.pb.go b/api/relations/v0/relation_tuples.pb.go index 426e2cb..db720e9 100644 --- a/api/relations/v0/relation_tuples.pb.go +++ b/api/relations/v0/relation_tuples.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 +// protoc-gen-go v1.34.2 // protoc v5.27.0 // source: relations/v0/relation_tuples.proto @@ -594,7 +594,7 @@ func file_relations_v0_relation_tuples_proto_rawDescGZIP() []byte { } var file_relations_v0_relation_tuples_proto_msgTypes = make([]protoimpl.MessageInfo, 8) -var file_relations_v0_relation_tuples_proto_goTypes = []interface{}{ +var file_relations_v0_relation_tuples_proto_goTypes = []any{ (*CreateTuplesRequest)(nil), // 0: kessel.relations.v0.CreateTuplesRequest (*CreateTuplesResponse)(nil), // 1: kessel.relations.v0.CreateTuplesResponse (*ReadTuplesRequest)(nil), // 2: kessel.relations.v0.ReadTuplesRequest @@ -635,7 +635,7 @@ func file_relations_v0_relation_tuples_proto_init() { } file_relations_v0_common_proto_init() if !protoimpl.UnsafeEnabled { - file_relations_v0_relation_tuples_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_relation_tuples_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*CreateTuplesRequest); i { case 0: return &v.state @@ -647,7 +647,7 @@ func file_relations_v0_relation_tuples_proto_init() { return nil } } - file_relations_v0_relation_tuples_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_relation_tuples_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*CreateTuplesResponse); i { case 0: return &v.state @@ -659,7 +659,7 @@ func file_relations_v0_relation_tuples_proto_init() { return nil } } - file_relations_v0_relation_tuples_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_relation_tuples_proto_msgTypes[2].Exporter = func(v any, i int) any { switch v := v.(*ReadTuplesRequest); i { case 0: return &v.state @@ -671,7 +671,7 @@ func file_relations_v0_relation_tuples_proto_init() { return nil } } - file_relations_v0_relation_tuples_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_relation_tuples_proto_msgTypes[3].Exporter = func(v any, i int) any { switch v := v.(*ReadTuplesResponse); i { case 0: return &v.state @@ -683,7 +683,7 @@ func file_relations_v0_relation_tuples_proto_init() { return nil } } - file_relations_v0_relation_tuples_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_relation_tuples_proto_msgTypes[4].Exporter = func(v any, i int) any { switch v := v.(*DeleteTuplesRequest); i { case 0: return &v.state @@ -695,7 +695,7 @@ func file_relations_v0_relation_tuples_proto_init() { return nil } } - file_relations_v0_relation_tuples_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_relation_tuples_proto_msgTypes[5].Exporter = func(v any, i int) any { switch v := v.(*DeleteTuplesResponse); i { case 0: return &v.state @@ -707,7 +707,7 @@ func file_relations_v0_relation_tuples_proto_init() { return nil } } - file_relations_v0_relation_tuples_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_relation_tuples_proto_msgTypes[6].Exporter = func(v any, i int) any { switch v := v.(*RelationTupleFilter); i { case 0: return &v.state @@ -719,7 +719,7 @@ func file_relations_v0_relation_tuples_proto_init() { return nil } } - file_relations_v0_relation_tuples_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + file_relations_v0_relation_tuples_proto_msgTypes[7].Exporter = func(v any, i int) any { switch v := v.(*SubjectFilter); i { case 0: return &v.state @@ -732,9 +732,9 @@ func file_relations_v0_relation_tuples_proto_init() { } } } - file_relations_v0_relation_tuples_proto_msgTypes[2].OneofWrappers = []interface{}{} - file_relations_v0_relation_tuples_proto_msgTypes[6].OneofWrappers = []interface{}{} - file_relations_v0_relation_tuples_proto_msgTypes[7].OneofWrappers = []interface{}{} + file_relations_v0_relation_tuples_proto_msgTypes[2].OneofWrappers = []any{} + file_relations_v0_relation_tuples_proto_msgTypes[6].OneofWrappers = []any{} + file_relations_v0_relation_tuples_proto_msgTypes[7].OneofWrappers = []any{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ diff --git a/api/relations/v0/relation_tuples.pb.validate.go b/api/relations/v0/relation_tuples.pb.validate.go new file mode 100644 index 0000000..558cc58 --- /dev/null +++ b/api/relations/v0/relation_tuples.pb.validate.go @@ -0,0 +1,1100 @@ +// Code generated by protoc-gen-validate. DO NOT EDIT. +// source: relations/v0/relation_tuples.proto + +package v0 + +import ( + "bytes" + "errors" + "fmt" + "net" + "net/mail" + "net/url" + "regexp" + "sort" + "strings" + "time" + "unicode/utf8" + + "google.golang.org/protobuf/types/known/anypb" +) + +// ensure the imports are used +var ( + _ = bytes.MinRead + _ = errors.New("") + _ = fmt.Print + _ = utf8.UTFMax + _ = (*regexp.Regexp)(nil) + _ = (*strings.Reader)(nil) + _ = net.IPv4len + _ = time.Duration(0) + _ = (*url.URL)(nil) + _ = (*mail.Address)(nil) + _ = anypb.Any{} + _ = sort.Sort +) + +// Validate checks the field values on CreateTuplesRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *CreateTuplesRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on CreateTuplesRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// CreateTuplesRequestMultiError, or nil if none found. +func (m *CreateTuplesRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *CreateTuplesRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + // no validation rules for Upsert + + for idx, item := range m.GetTuples() { + _, _ = idx, item + + if all { + switch v := interface{}(item).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, CreateTuplesRequestValidationError{ + field: fmt.Sprintf("Tuples[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, CreateTuplesRequestValidationError{ + field: fmt.Sprintf("Tuples[%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 CreateTuplesRequestValidationError{ + field: fmt.Sprintf("Tuples[%v]", idx), + reason: "embedded message failed validation", + cause: err, + } + } + } + + } + + if len(errors) > 0 { + return CreateTuplesRequestMultiError(errors) + } + + return nil +} + +// CreateTuplesRequestMultiError is an error wrapping multiple validation +// errors returned by CreateTuplesRequest.ValidateAll() if the designated +// constraints aren't met. +type CreateTuplesRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m CreateTuplesRequestMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m CreateTuplesRequestMultiError) AllErrors() []error { return m } + +// CreateTuplesRequestValidationError is the validation error returned by +// CreateTuplesRequest.Validate if the designated constraints aren't met. +type CreateTuplesRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e CreateTuplesRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e CreateTuplesRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e CreateTuplesRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e CreateTuplesRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e CreateTuplesRequestValidationError) ErrorName() string { + return "CreateTuplesRequestValidationError" +} + +// Error satisfies the builtin error interface +func (e CreateTuplesRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sCreateTuplesRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = CreateTuplesRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = CreateTuplesRequestValidationError{} + +// Validate checks the field values on CreateTuplesResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *CreateTuplesResponse) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on CreateTuplesResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// CreateTuplesResponseMultiError, or nil if none found. +func (m *CreateTuplesResponse) ValidateAll() error { + return m.validate(true) +} + +func (m *CreateTuplesResponse) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if len(errors) > 0 { + return CreateTuplesResponseMultiError(errors) + } + + return nil +} + +// CreateTuplesResponseMultiError is an error wrapping multiple validation +// errors returned by CreateTuplesResponse.ValidateAll() if the designated +// constraints aren't met. +type CreateTuplesResponseMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m CreateTuplesResponseMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m CreateTuplesResponseMultiError) AllErrors() []error { return m } + +// CreateTuplesResponseValidationError is the validation error returned by +// CreateTuplesResponse.Validate if the designated constraints aren't met. +type CreateTuplesResponseValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e CreateTuplesResponseValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e CreateTuplesResponseValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e CreateTuplesResponseValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e CreateTuplesResponseValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e CreateTuplesResponseValidationError) ErrorName() string { + return "CreateTuplesResponseValidationError" +} + +// Error satisfies the builtin error interface +func (e CreateTuplesResponseValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sCreateTuplesResponse.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = CreateTuplesResponseValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = CreateTuplesResponseValidationError{} + +// Validate checks the field values on ReadTuplesRequest with the rules defined +// in the proto definition for this message. If any rules are violated, the +// first error encountered is returned, or nil if there are no violations. +func (m *ReadTuplesRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on ReadTuplesRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// ReadTuplesRequestMultiError, or nil if none found. +func (m *ReadTuplesRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *ReadTuplesRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if all { + switch v := interface{}(m.GetFilter()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, ReadTuplesRequestValidationError{ + field: "Filter", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, ReadTuplesRequestValidationError{ + field: "Filter", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetFilter()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return ReadTuplesRequestValidationError{ + field: "Filter", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if m.Pagination != nil { + + if all { + switch v := interface{}(m.GetPagination()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, ReadTuplesRequestValidationError{ + field: "Pagination", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, ReadTuplesRequestValidationError{ + field: "Pagination", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetPagination()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return ReadTuplesRequestValidationError{ + field: "Pagination", + reason: "embedded message failed validation", + cause: err, + } + } + } + + } + + if len(errors) > 0 { + return ReadTuplesRequestMultiError(errors) + } + + return nil +} + +// ReadTuplesRequestMultiError is an error wrapping multiple validation errors +// returned by ReadTuplesRequest.ValidateAll() if the designated constraints +// aren't met. +type ReadTuplesRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m ReadTuplesRequestMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m ReadTuplesRequestMultiError) AllErrors() []error { return m } + +// ReadTuplesRequestValidationError is the validation error returned by +// ReadTuplesRequest.Validate if the designated constraints aren't met. +type ReadTuplesRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e ReadTuplesRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e ReadTuplesRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e ReadTuplesRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e ReadTuplesRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e ReadTuplesRequestValidationError) ErrorName() string { + return "ReadTuplesRequestValidationError" +} + +// Error satisfies the builtin error interface +func (e ReadTuplesRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sReadTuplesRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = ReadTuplesRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = ReadTuplesRequestValidationError{} + +// Validate checks the field values on ReadTuplesResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *ReadTuplesResponse) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on ReadTuplesResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// ReadTuplesResponseMultiError, or nil if none found. +func (m *ReadTuplesResponse) ValidateAll() error { + return m.validate(true) +} + +func (m *ReadTuplesResponse) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if all { + switch v := interface{}(m.GetTuple()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, ReadTuplesResponseValidationError{ + field: "Tuple", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, ReadTuplesResponseValidationError{ + field: "Tuple", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetTuple()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return ReadTuplesResponseValidationError{ + field: "Tuple", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if all { + switch v := interface{}(m.GetPagination()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, ReadTuplesResponseValidationError{ + field: "Pagination", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, ReadTuplesResponseValidationError{ + field: "Pagination", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetPagination()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return ReadTuplesResponseValidationError{ + field: "Pagination", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if len(errors) > 0 { + return ReadTuplesResponseMultiError(errors) + } + + return nil +} + +// ReadTuplesResponseMultiError is an error wrapping multiple validation errors +// returned by ReadTuplesResponse.ValidateAll() if the designated constraints +// aren't met. +type ReadTuplesResponseMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m ReadTuplesResponseMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m ReadTuplesResponseMultiError) AllErrors() []error { return m } + +// ReadTuplesResponseValidationError is the validation error returned by +// ReadTuplesResponse.Validate if the designated constraints aren't met. +type ReadTuplesResponseValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e ReadTuplesResponseValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e ReadTuplesResponseValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e ReadTuplesResponseValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e ReadTuplesResponseValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e ReadTuplesResponseValidationError) ErrorName() string { + return "ReadTuplesResponseValidationError" +} + +// Error satisfies the builtin error interface +func (e ReadTuplesResponseValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sReadTuplesResponse.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = ReadTuplesResponseValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = ReadTuplesResponseValidationError{} + +// Validate checks the field values on DeleteTuplesRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *DeleteTuplesRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on DeleteTuplesRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// DeleteTuplesRequestMultiError, or nil if none found. +func (m *DeleteTuplesRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *DeleteTuplesRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if all { + switch v := interface{}(m.GetFilter()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, DeleteTuplesRequestValidationError{ + field: "Filter", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, DeleteTuplesRequestValidationError{ + field: "Filter", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetFilter()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return DeleteTuplesRequestValidationError{ + field: "Filter", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if len(errors) > 0 { + return DeleteTuplesRequestMultiError(errors) + } + + return nil +} + +// DeleteTuplesRequestMultiError is an error wrapping multiple validation +// errors returned by DeleteTuplesRequest.ValidateAll() if the designated +// constraints aren't met. +type DeleteTuplesRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m DeleteTuplesRequestMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m DeleteTuplesRequestMultiError) AllErrors() []error { return m } + +// DeleteTuplesRequestValidationError is the validation error returned by +// DeleteTuplesRequest.Validate if the designated constraints aren't met. +type DeleteTuplesRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e DeleteTuplesRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e DeleteTuplesRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e DeleteTuplesRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e DeleteTuplesRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e DeleteTuplesRequestValidationError) ErrorName() string { + return "DeleteTuplesRequestValidationError" +} + +// Error satisfies the builtin error interface +func (e DeleteTuplesRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sDeleteTuplesRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = DeleteTuplesRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = DeleteTuplesRequestValidationError{} + +// Validate checks the field values on DeleteTuplesResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *DeleteTuplesResponse) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on DeleteTuplesResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// DeleteTuplesResponseMultiError, or nil if none found. +func (m *DeleteTuplesResponse) ValidateAll() error { + return m.validate(true) +} + +func (m *DeleteTuplesResponse) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if len(errors) > 0 { + return DeleteTuplesResponseMultiError(errors) + } + + return nil +} + +// DeleteTuplesResponseMultiError is an error wrapping multiple validation +// errors returned by DeleteTuplesResponse.ValidateAll() if the designated +// constraints aren't met. +type DeleteTuplesResponseMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m DeleteTuplesResponseMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m DeleteTuplesResponseMultiError) AllErrors() []error { return m } + +// DeleteTuplesResponseValidationError is the validation error returned by +// DeleteTuplesResponse.Validate if the designated constraints aren't met. +type DeleteTuplesResponseValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e DeleteTuplesResponseValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e DeleteTuplesResponseValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e DeleteTuplesResponseValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e DeleteTuplesResponseValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e DeleteTuplesResponseValidationError) ErrorName() string { + return "DeleteTuplesResponseValidationError" +} + +// Error satisfies the builtin error interface +func (e DeleteTuplesResponseValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sDeleteTuplesResponse.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = DeleteTuplesResponseValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = DeleteTuplesResponseValidationError{} + +// Validate checks the field values on RelationTupleFilter with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *RelationTupleFilter) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on RelationTupleFilter with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// RelationTupleFilterMultiError, or nil if none found. +func (m *RelationTupleFilter) ValidateAll() error { + return m.validate(true) +} + +func (m *RelationTupleFilter) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if m.ResourceNamespace != nil { + // no validation rules for ResourceNamespace + } + + if m.ResourceType != nil { + // no validation rules for ResourceType + } + + if m.ResourceId != nil { + // no validation rules for ResourceId + } + + if m.Relation != nil { + // no validation rules for Relation + } + + if m.SubjectFilter != nil { + + if all { + switch v := interface{}(m.GetSubjectFilter()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, RelationTupleFilterValidationError{ + field: "SubjectFilter", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, RelationTupleFilterValidationError{ + field: "SubjectFilter", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetSubjectFilter()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return RelationTupleFilterValidationError{ + field: "SubjectFilter", + reason: "embedded message failed validation", + cause: err, + } + } + } + + } + + if len(errors) > 0 { + return RelationTupleFilterMultiError(errors) + } + + return nil +} + +// RelationTupleFilterMultiError is an error wrapping multiple validation +// errors returned by RelationTupleFilter.ValidateAll() if the designated +// constraints aren't met. +type RelationTupleFilterMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m RelationTupleFilterMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m RelationTupleFilterMultiError) AllErrors() []error { return m } + +// RelationTupleFilterValidationError is the validation error returned by +// RelationTupleFilter.Validate if the designated constraints aren't met. +type RelationTupleFilterValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e RelationTupleFilterValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e RelationTupleFilterValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e RelationTupleFilterValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e RelationTupleFilterValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e RelationTupleFilterValidationError) ErrorName() string { + return "RelationTupleFilterValidationError" +} + +// Error satisfies the builtin error interface +func (e RelationTupleFilterValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sRelationTupleFilter.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = RelationTupleFilterValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = RelationTupleFilterValidationError{} + +// Validate checks the field values on SubjectFilter with the rules defined in +// the proto definition for this message. If any rules are violated, the first +// error encountered is returned, or nil if there are no violations. +func (m *SubjectFilter) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on SubjectFilter with the rules defined +// in the proto definition for this message. If any rules are violated, the +// result is a list of violation errors wrapped in SubjectFilterMultiError, or +// nil if none found. +func (m *SubjectFilter) ValidateAll() error { + return m.validate(true) +} + +func (m *SubjectFilter) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if m.SubjectNamespace != nil { + // no validation rules for SubjectNamespace + } + + if m.SubjectType != nil { + // no validation rules for SubjectType + } + + if m.SubjectId != nil { + // no validation rules for SubjectId + } + + if m.Relation != nil { + // no validation rules for Relation + } + + if len(errors) > 0 { + return SubjectFilterMultiError(errors) + } + + return nil +} + +// SubjectFilterMultiError is an error wrapping multiple validation errors +// returned by SubjectFilter.ValidateAll() if the designated constraints +// aren't met. +type SubjectFilterMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m SubjectFilterMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m SubjectFilterMultiError) AllErrors() []error { return m } + +// SubjectFilterValidationError is the validation error returned by +// SubjectFilter.Validate if the designated constraints aren't met. +type SubjectFilterValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e SubjectFilterValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e SubjectFilterValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e SubjectFilterValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e SubjectFilterValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e SubjectFilterValidationError) ErrorName() string { return "SubjectFilterValidationError" } + +// Error satisfies the builtin error interface +func (e SubjectFilterValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sSubjectFilter.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = SubjectFilterValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = SubjectFilterValidationError{} diff --git a/go.mod b/go.mod index cfb2bee..e612439 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.21 require ( github.com/authzed/authzed-go v0.12.0 github.com/authzed/grpcutil v0.0.0-20230908193239-4286bb1d6403 + github.com/envoyproxy/protoc-gen-validate v1.0.4 github.com/go-kratos/kratos/v2 v2.7.3 github.com/google/wire v0.6.0 github.com/ory/dockertest v3.3.5+incompatible @@ -27,7 +28,6 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/docker/go-connections v0.5.0 // indirect github.com/docker/go-units v0.5.0 // indirect - github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/go-kratos/aegis v0.2.0 // indirect github.com/go-logr/logr v1.4.1 // indirect @@ -54,7 +54,7 @@ require ( go.opentelemetry.io/otel v1.16.0 // indirect go.opentelemetry.io/otel/metric v1.16.0 // indirect go.opentelemetry.io/otel/trace v1.16.0 // indirect - golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect + golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.25.0 // indirect golang.org/x/sync v0.7.0 // indirect diff --git a/go.sum b/go.sum index e13e6d1..b34a3ca 100644 --- a/go.sum +++ b/go.sum @@ -163,8 +163,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM= -golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= +golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 h1:aAcj0Da7eBAtrTp03QXWvm88pSyOt+UgdZw2BFZ+lEw= +golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= diff --git a/internal/biz/lookup.go b/internal/biz/lookup.go index ea4b050..7667cd3 100644 --- a/internal/biz/lookup.go +++ b/internal/biz/lookup.go @@ -36,33 +36,18 @@ func (s *GetSubjectsUsecase) Get(ctx context.Context, req *v0.LookupSubjectsRequ } } - if req.Resource == nil { - s.log.WithContext(ctx).Infof("Missing Resource in request %v", req) - return nil, nil, errors.BadRequest("Invalid request", "Object is required") + if err := req.Validate(); err != nil { + s.log.WithContext(ctx).Error("Request failed to pass validation: %v", req) + return nil, nil, errors.BadRequest("Invalid request", err.Error()) } - if req.SubjectRelation != nil { - subjectRelation = *req.SubjectRelation - } - - if req.SubjectType == nil { - s.log.WithContext(ctx).Infof("Missing SubjectType in request %v", req) - return nil, nil, errors.BadRequest("Invalid request", "Subject type is required") - } - - if req.Relation == "" { - s.log.WithContext(ctx).Infof("Missing relation in request %v", req) - return nil, nil, errors.BadRequest("Invalid request", "Relation is required") - } - - if req.Resource.Type == nil { - s.log.WithContext(ctx).Infof("Missing Resource Type in request %v", req) - return nil, nil, errors.BadRequest("Invalid request", "Resource Type is required") + if err := req.Resource.Validate(); err != nil { + s.log.WithContext(ctx).Error("Request failed to pass validation: %v", req) + return nil, nil, errors.BadRequest("Invalid request", err.Error()) } - if req.Resource.Id == "" { - s.log.WithContext(ctx).Infof("Missing Resource Id in request %v", req) - return nil, nil, errors.BadRequest("Invalid request", "Resource Id is required") + if req.SubjectRelation != nil { + subjectRelation = *req.SubjectRelation } subs, errs, err := s.repo.LookupSubjects(ctx, req.SubjectType, subjectRelation, req.Relation, &v0.ObjectReference{ diff --git a/internal/server/grpc.go b/internal/server/grpc.go index 678848c..3c5c8a8 100644 --- a/internal/server/grpc.go +++ b/internal/server/grpc.go @@ -8,6 +8,7 @@ import ( "github.com/go-kratos/kratos/v2/log" "github.com/go-kratos/kratos/v2/middleware/recovery" + "github.com/go-kratos/kratos/v2/middleware/validate" "github.com/go-kratos/kratos/v2/transport/grpc" ) @@ -16,6 +17,7 @@ func NewGRPCServer(c *conf.Server, relations *service.RelationshipsService, heal var opts = []grpc.ServerOption{ grpc.Middleware( recovery.Recovery(), + validate.Validator(), ), } if c.Grpc.Network != "" { diff --git a/internal/server/http.go b/internal/server/http.go index 37b3034..5ba8dc0 100644 --- a/internal/server/http.go +++ b/internal/server/http.go @@ -8,6 +8,7 @@ import ( "github.com/go-kratos/kratos/v2/log" "github.com/go-kratos/kratos/v2/middleware/recovery" + "github.com/go-kratos/kratos/v2/middleware/validate" "github.com/go-kratos/kratos/v2/transport/http" ) @@ -16,6 +17,7 @@ func NewHTTPServer(c *conf.Server, relationships *service.RelationshipsService, var opts = []http.ServerOption{ http.Middleware( recovery.Recovery(), + validate.Validator(), ), } if c.Http.Network != "" {