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


##########
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:
   It's not possible to have request API version 0 and have an endpoint type 
other than BROKER. That's enforced by the serialization layer, so we don't have 
to do anything here.



-- 
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