Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for custom API requests #246

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using a copy here like below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http4s' Request is a final class (not case class) thus it doesn't provide the .copy methods unfortunately.


def customRequest(request: WSRequest): F[WSRequest] =
request
.copy(uri = config.server.resolve(request.uri))
.withOptionalAuthorization(authorization)

}

object KubernetesClient {
Expand Down