showuon commented on code in PR #14306:
URL: https://github.com/apache/kafka/pull/14306#discussion_r1311278157


##########
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:
   Looks like we won't return `INVALID_REQUEST` response when `request API 
version == 0`, and all other info are valid (i.e. endpoint type is correct and 
matching). Is that expected? I think we should throw `INVALID_REQUEST` error in 
any case?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to