showuon commented on code in PR #14306: URL: https://github.com/apache/kafka/pull/14306#discussion_r1312733661
########## core/src/main/scala/kafka/server/AuthHelper.scala: ########## @@ -130,4 +134,57 @@ class AuthHelper(authorizer: Option[Authorizer]) { } } + def computeDescribeClusterResponse( + request: RequestChannel.Request, + expectedEndpointType: EndpointType, + clusterId: String, + getNodes: () => DescribeClusterBrokerCollection, + getControllerId: () => Int + ): DescribeClusterResponseData = { + val describeClusterRequest = request.body[DescribeClusterRequest] + val requestEndpointType = EndpointType.fromId(describeClusterRequest.data().endpointType()) + if (requestEndpointType.equals(EndpointType.UNKNOWN)) { + return new DescribeClusterResponseData(). + setErrorCode(if (request.header.data().requestApiVersion() == 0) { + Errors.INVALID_REQUEST.code() + } else { + Errors.UNSUPPORTED_ENDPOINT_TYPE.code() + }). + setErrorMessage("Unsupported endpoint type " + describeClusterRequest.data().endpointType().toInt) + } else if (!expectedEndpointType.equals(requestEndpointType)) { + return new DescribeClusterResponseData(). + setErrorCode(if (request.header.data().requestApiVersion() == 0) { + Errors.INVALID_REQUEST.code() + } else { + Errors.MISMATCHED_ENDPOINT_TYPE.code() + }). + setErrorMessage("The request was sent to an endpoint of type " + expectedEndpointType + + ", but we wanted an endpoint of type " + requestEndpointType) + } Review Comment: Yes, but that's under the assumption of users are using our java client. What if they use other client that no validation during serialization? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org