From 73347979765ac791dab3eea869056984a3ebb5c4 Mon Sep 17 00:00:00 2001 From: yurique Date: Mon, 9 Oct 2023 22:12:46 +0200 Subject: [PATCH] support for custom API requests --- .../kubernetes/client/KubernetesClient.scala | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/kubernetes-client/src/com/goyeau/kubernetes/client/KubernetesClient.scala b/kubernetes-client/src/com/goyeau/kubernetes/client/KubernetesClient.scala index 14aab96a..337a0af0 100644 --- a/kubernetes-client/src/com/goyeau/kubernetes/client/KubernetesClient.scala +++ b/kubernetes-client/src/com/goyeau/kubernetes/client/KubernetesClient.scala @@ -7,10 +7,12 @@ import com.goyeau.kubernetes.client.api.* import com.goyeau.kubernetes.client.crd.{CrdContext, CustomResource, CustomResourceList} import com.goyeau.kubernetes.client.util.SslContexts import com.goyeau.kubernetes.client.util.cache.{AuthorizationParse, ExecToken} +import com.goyeau.kubernetes.client.operation.* import io.circe.{Decoder, Encoder} +import org.http4s.Request import org.http4s.client.Client import org.http4s.headers.Authorization -import org.http4s.jdkhttpclient.{JdkHttpClient, JdkWSClient, WSClient} +import org.http4s.jdkhttpclient.{JdkHttpClient, JdkWSClient, WSClient, WSRequest} import org.typelevel.log4cats.Logger import java.net.http.HttpClient @@ -61,6 +63,24 @@ class KubernetesClient[F[_]: Async: Logger]( encoder: Encoder[CustomResource[A, B]], decoder: Decoder[CustomResource[A, B]] ) = new CustomResourcesApi[F, A, B](httpClient, config, authorization, context) + + def customRequest( + request: Request[F] + ): F[Request[F]] = + Request[F]( + method = request.method, + uri = config.server.resolve(request.uri), + httpVersion = request.httpVersion, + headers = request.headers, + body = request.body, + attributes = request.attributes + ).withOptionalAuthorization(authorization) + + def customRequest(request: WSRequest): F[WSRequest] = + request + .copy(uri = config.server.resolve(request.uri)) + .withOptionalAuthorization(authorization) + } object KubernetesClient {