MCPcopy Create free account
hub / github.com/clouditor/clouditor / Validate

Function Validate

api/validate.go:51–67  ·  view source on GitHub ↗

Validate validates an incoming request according to different criteria: - If the request is nil, [api.ErrEmptyRequest] is returned - The request is validated according to the generated validation method - Lastly, if the request is a [api.PaginatedRequest], an additional check is performed to ensure

(req IncomingRequest)

Source from the content-addressed store, hash-verified

49// Note: This function already returns a gRPC error, so the error can be returned directly without any wrapping in a
50// request function.
51func Validate(req IncomingRequest) (err error) {
52 // Check, if request is nil. We need to check whether the interface itself is nil (untyped nil); this happens if
53 // someone is directly setting nil to a variable of the interface IncomingRequest. Furthermore, we need to check,
54 // whether the *value* of the interface is nil. This can happen if nil is first assigned to a variable of a struct
55 // (pointer) that implements the interface. If this variable is then passed to the validate function, the req
56 // parameter is not nil, but the value of the interface representing it is.
57 if util.IsNil(req) {
58 return status.Errorf(codes.InvalidArgument, "%s", ErrEmptyRequest)
59 }
60 // Validate request
61 err = validator.Validate(req)
62 if err != nil {
63 return status.Errorf(codes.InvalidArgument, "%v: %v", ErrInvalidRequest, err)
64 }
65
66 return nil
67}
68
69type IncomingRequest interface {
70 proto.Message

Callers 15

AssessEvidenceMethod · 0.92
handleEvidenceMethod · 0.92
StartMethod · 0.92
ListResourcesMethod · 0.92
ListGraphEdgesMethod · 0.92
UpdateResourceMethod · 0.92
TestService_GetEvidenceFunction · 0.92
StoreEvidenceMethod · 0.92
ListEvidencesMethod · 0.92
GetEvidenceMethod · 0.92

Calls 2

IsNilFunction · 0.92
ErrorfMethod · 0.80

Tested by 15

TestService_GetEvidenceFunction · 0.74
Test_CreateCertificateFunction · 0.74
Test_GetCertificateFunction · 0.74
TestService_CreateMetricFunction · 0.74
TestService_UpdateMetricFunction · 0.74
TestService_GetMetricFunction · 0.74
TestService_ListMetricsFunction · 0.74