Skip to content

Commit

Permalink
allow adapting http clients
Browse files Browse the repository at this point in the history
  • Loading branch information
yurique committed Nov 28, 2023
1 parent 734769a commit df5a25c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,27 @@ import java.net.http.HttpClient
trait PlatformSpecific {
self: KubernetesClient.type =>

def jdk[F[_]: Async: Logger: Files: Network: Processes: Env](
config: KubeConfig[F],
adaptClients: Clients[F] => Resource[F, Clients[F]]
): Resource[F, KubernetesClient[F]] =
create(config, PlatformSpecific.jdkClients(_), adaptClients)

def jdk[F[_]: Async: Logger: Files: Network: Processes: Env](
config: KubeConfig[F]
): Resource[F, KubernetesClient[F]] =
create(config, PlatformSpecific.jdkClients(_))
create(config, PlatformSpecific.jdkClients(_), noAdapt[F])

def jdk[F[_]: Async: Files: Logger: Network: Processes: Env](
config: F[KubeConfig[F]],
adaptClients: Clients[F] => Resource[F, Clients[F]]
): Resource[F, KubernetesClient[F]] =
Resource.eval(config).flatMap(create(_, PlatformSpecific.jdkClients(_), adaptClients))

def jdk[F[_]: Async: Files: Logger: Network: Processes: Env](
config: F[KubeConfig[F]]
): Resource[F, KubernetesClient[F]] =
Resource.eval(config).flatMap(jdk(_))
Resource.eval(config).flatMap(create(_, PlatformSpecific.jdkClients(_), noAdapt[F]))

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package com.goyeau.kubernetes.client
import org.http4s.client.Client
import org.http4s.client.websocket.WSClient

private case class Clients[F[_]](httpClient: Client[F], wsClient: WSClient[F])
case class Clients[F[_]](httpClient: Client[F], wsClient: WSClient[F])
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.goyeau.kubernetes.client

import cats.Monad
import cats.syntax.all.*
import cats.effect.syntax.all.*
import cats.data.OptionT
import cats.effect.*
import cats.effect.std.Env
Expand Down Expand Up @@ -71,10 +73,12 @@ object KubernetesClient extends PlatformSpecific {

private[client] def create[F[_]: Async: Logger: Files: Network: Processes: Env](
config: KubeConfig[F],
clients: KubeConfig[F] => Resource[F, Clients[F]]
clients: KubeConfig[F] => Resource[F, Clients[F]],
adaptClients: Clients[F] => Resource[F, Clients[F]]
): Resource[F, KubernetesClient[F]] =
for {
clients <- clients(config)
clients <- adaptClients(clients)
authorization <- Resource.eval {
OptionT
.fromOption(config.authorization)
Expand Down Expand Up @@ -106,15 +110,27 @@ object KubernetesClient extends PlatformSpecific {
authorization
)

def ember[F[_]: Async: Logger: Files: Network: Processes: Env](
config: KubeConfig[F],
adaptClients: Clients[F] => Resource[F, Clients[F]]
): Resource[F, KubernetesClient[F]] =
create(config, emberClients(_), adaptClients)

def ember[F[_]: Async: Logger: Files: Network: Processes: Env](
config: KubeConfig[F]
): Resource[F, KubernetesClient[F]] =
create(config, emberClients(_))
create(config, emberClients(_), noAdapt[F])

def ember[F[_]: Async: Files: Logger: Network: Processes: Env](
config: F[KubeConfig[F]],
adaptClients: Clients[F] => Resource[F, Clients[F]]
): Resource[F, KubernetesClient[F]] =
Resource.eval(config).flatMap(ember(_, adaptClients))

def ember[F[_]: Async: Files: Logger: Network: Processes: Env](
config: F[KubeConfig[F]]
): Resource[F, KubernetesClient[F]] =
Resource.eval(config).flatMap(ember(_))
Resource.eval(config).flatMap(ember(_, noAdapt[F]))

@deprecated("use .ember", "0.12.0")
def apply[F[_]: Async: Logger: Files: Network: Processes: Env](
Expand All @@ -137,4 +153,7 @@ object KubernetesClient extends PlatformSpecific {
(http, ws) = clients
} yield Clients(http, ws)

private[client] def noAdapt[F[_]: Monad]: Clients[F] => Resource[F, Clients[F]] =
(c: Clients[F]) => c.pure[F].toResource

}

0 comments on commit df5a25c

Please sign in to comment.