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)
| 500 | // e is the endpoint expression. |
| 501 | // req if true indicates the Request metadata is being validated. |
| 502 | func 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. |