MCPcopy Create free account
hub / github.com/goadesign/goa / validateMetadata

Function validateMetadata

expr/grpc_endpoint.go:502–526  ·  view source on GitHub ↗

validateMetadata validates the gRPC metadata. It compares the given metadata with the service type (Payload or Result) and ensures all the attributes defined in the metadata type are found in the service type. metAtt is the Request/Response metadata attribute. validateMetadata assumes that the metA

(metAtt *MappedAttributeExpr, serviceAtt *AttributeExpr, e *GRPCEndpointExpr, req bool)

Source from the content-addressed store, hash-verified

500// e is the endpoint expression.
501// req if true indicates the Request metadata is being validated.
502func validateMetadata(metAtt *MappedAttributeExpr, serviceAtt *AttributeExpr, e *GRPCEndpointExpr, req bool) *eval.ValidationErrors {
503 verr := new(eval.ValidationErrors)
504 metKind := "Response"
505 serviceKind := "Result"
506 if req {
507 metKind = "Request"
508 serviceKind = "Payload"
509 }
510 if isEmpty(serviceAtt) {
511 verr.Add(e, "%s metadata is defined but %s is not defined in method", metKind, serviceKind)
512 return verr
513 }
514 if IsObject(serviceAtt.Type) {
515 // service type is an object type. Ensure the attributes defined in
516 // the metadata are found in the service type.
517 for _, nat := range *AsObject(metAtt.Type) {
518 if a := serviceAtt.Find(nat.Name); a == nil {
519 verr.Add(e, "%s metadata attribute %q is not found in %s", metKind, nat.Name, serviceKind)
520 }
521 }
522 } else {
523 verr.Add(e, "%s metadata is defined but method %s is not an object type", metKind, serviceKind)
524 }
525 return verr
526}
527
528// getSecurityAttributes returns the attributes that describes a security
529// scheme from a method expression.

Callers 2

ValidateMethod · 0.85
ValidateMethod · 0.85

Calls 5

IsObjectFunction · 0.85
AsObjectFunction · 0.85
AddMethod · 0.80
FindMethod · 0.80
isEmptyFunction · 0.70

Tested by

no test coverage detected