Skip to content

Commit

Permalink
Upgraded to the jdk client version 0.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
domaspoliakas authored and joan38 committed Oct 9, 2023
1 parent d4b4986 commit 44f8000
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import com.goyeau.kubernetes.client.util.cache.{AuthorizationParse, ExecToken}
import io.circe.{Decoder, Encoder}
import org.http4s.client.Client
import org.http4s.headers.Authorization
import org.http4s.jdkhttpclient.{JdkHttpClient, JdkWSClient, WSClient}
import org.http4s.client.websocket.WSClient
import org.http4s.jdkhttpclient.{JdkHttpClient, JdkWSClient}
import org.typelevel.log4cats.Logger

import java.net.http.HttpClient
Expand Down Expand Up @@ -69,8 +70,8 @@ object KubernetesClient {
client <- Resource.eval {
Sync[F].delay(HttpClient.newBuilder().sslContext(SslContexts.fromConfig(config)).build())
}
httpClient <- JdkHttpClient[F](client)
wsClient <- JdkWSClient[F](client)
httpClient = JdkHttpClient[F](client)
wsClient = JdkWSClient[F](client)
authorization <- Resource.eval {
OptionT
.fromOption(config.authorization)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ import org.http4s.*
import org.http4s.client.Client
import org.http4s.headers.Authorization
import org.http4s.implicits.*
import org.http4s.jdkhttpclient.*
import org.http4s.client.websocket.WSClient
import org.http4s.client.websocket.WSRequest
import org.typelevel.ci.CIString
import org.typelevel.log4cats.Logger
import scodec.bits.ByteVector

import java.nio.file.Path as JPath
import scala.concurrent.duration.DurationInt
import org.http4s.client.websocket.WSFrame
import org.http4s.client.websocket.WSDataFrame

private[client] class PodsApi[F[_]: Logger](
val httpClient: Client[F],
Expand Down Expand Up @@ -113,13 +116,11 @@ private[client] class NamespacedPodsApi[F[_]](
("container" -> container) ++?
("command" -> commands)

WSRequest(uri, method = Method.POST)
WSRequest(uri, Headers.empty, Method.POST)
.withOptionalAuthorization(authorization)
.map { r =>
r.copy(
headers = r.headers.put(Header.Raw(CIString("Sec-WebSocket-Protocol"), "v4.channel.k8s.io"))
)
}
.map(r =>
r.withHeaders(headers = r.headers.put(Header.Raw(CIString("Sec-WebSocket-Protocol"), "v4.channel.k8s.io")))
)
}

@deprecated("Use download() which uses fs2.io.file.Path", "0.8.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cats.syntax.all.*
import cats.{Applicative, FlatMap}
import org.http4s.client.Client
import org.http4s.headers.Authorization
import org.http4s.jdkhttpclient.WSRequest
import org.http4s.client.websocket.WSRequest
import org.http4s.{EntityDecoder, Request, Response}

package object operation {
Expand All @@ -21,9 +21,7 @@ package object operation {
implicit private[client] class KubernetesWsRequestOps[F[_]: Applicative](request: WSRequest) {
def withOptionalAuthorization(authorization: Option[F[Authorization]]): F[WSRequest] =
authorization.fold(request.pure[F]) { authorization =>
authorization.map { auth =>
request.copy(headers = request.headers.put(auth))
}
authorization.map(auth => request.withHeaders(request.headers.put(auth)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,21 @@ object SslContexts {
val keyDataStream = config.clientKeyData.map(data => new ByteArrayInputStream(Base64.getDecoder.decode(data)))
val keyFileStream = config.clientKeyFile.map(_.toNioPath.toFile).map(new FileInputStream(_))

for {
val _ = for {
keyStream <- keyDataStream.orElse(keyFileStream)
certStream <- certDataStream.orElse(certFileStream)
} yield {
Security.addProvider(new BouncyCastleProvider())
val pemKeyPair =
new PEMParser(new InputStreamReader(keyStream)).readObject().asInstanceOf[PEMKeyPair]
val privateKey = new JcaPEMKeyConverter().setProvider("BC").getPrivateKey(pemKeyPair.getPrivateKeyInfo)

val certificateFactory = CertificateFactory.getInstance("X509")
val certificate = certificateFactory.generateCertificate(certStream).asInstanceOf[X509Certificate]

defaultKeyStore.setKeyEntry(
certificate.getSubjectX500Principal.getName,
privateKey,
config.clientKeyPass.fold(Array.empty[Char])(_.toCharArray),
Array(certificate)
)
}
_ = Security.addProvider(new BouncyCastleProvider())
pemKeyPair = new PEMParser(new InputStreamReader(keyStream)).readObject().asInstanceOf[PEMKeyPair]
privateKey = new JcaPEMKeyConverter().setProvider("BC").getPrivateKey(pemKeyPair.getPrivateKeyInfo)

certificateFactory = CertificateFactory.getInstance("X509")
certificate = certificateFactory.generateCertificate(certStream).asInstanceOf[X509Certificate]
} yield defaultKeyStore.setKeyEntry(
certificate.getSubjectX500Principal.getName,
privateKey,
config.clientKeyPass.fold(Array.empty[Char])(_.toCharArray),
Array(certificate)
)

val keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm)
keyManagerFactory.init(defaultKeyStore, Array.empty)
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.sc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object Dependencies {

lazy val http4s = {
val version = "0.23.23"
val jdkClientVersion = "0.5.0"
val jdkClientVersion = "0.9.1"
Agg(
ivy"org.http4s::http4s-dsl:$version",
ivy"org.http4s::http4s-circe:$version",
Expand Down

0 comments on commit 44f8000

Please sign in to comment.