Skip to content

Commit

Permalink
Merge pull request typelevel#399 from tpolecat/ce3-again
Browse files Browse the repository at this point in the history
CE3 (conflicts resolved)
  • Loading branch information
tpolecat authored Mar 2, 2021
2 parents e29f6aa + 9779dcd commit 91c51d1
Show file tree
Hide file tree
Showing 42 changed files with 614 additions and 580 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Start up Postgres instances
run: docker-compose up -d
- name: Compile (All) and Test/Coverage (Scala 2 Only)
run: csbt headerCheck +clean coverage test docs/makeSite coverageReport coverageOff +test
run: csbt headerCheck +clean evictionCheck coverage test docs/makeSite coverageReport coverageOff +test
- name: Shut down Postgres instances
run: docker-compose down
- name: Upload code coverage data
Expand Down
40 changes: 25 additions & 15 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ lazy val `scala-3.0-prev` = "3.0.0-M3"
lazy val `scala-3.0-curr` = "3.0.0-RC1"

// This is used in a couple places
lazy val fs2Version = "2.5.3"
lazy val fs2Version = "3.0.0-M9"
lazy val natchezVersion = "0.1.0-M4"


// We do `evictionCheck` in CI
inThisBuild(Seq(
evictionRules ++= Seq(
"org.typelevel" % "cats-*" % "semver-spec",
)
))

// Global Settings
lazy val commonSettings = Seq(
Expand Down Expand Up @@ -104,14 +113,14 @@ lazy val core = project
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "2.4.2",
"org.typelevel" %% "cats-effect" % "2.3.3",
"org.typelevel" %% "cats-effect" % "3.0.0-RC2",
"co.fs2" %% "fs2-core" % fs2Version,
"co.fs2" %% "fs2-io" % fs2Version,
"org.scodec" %% "scodec-core" % (if (isDotty.value) "2.0.0-RC1" else "1.11.7"),
"org.scodec" %% "scodec-cats" % "1.1.0-RC1",
"org.tpolecat" %% "natchez-core" % "0.0.20",
"org.tpolecat" %% "sourcepos" % "0.1.1",
"org.tpolecat" %% "natchez-core" % natchezVersion,
"com.ongres.scram" % "client" % "2.1",
"org.tpolecat" %% "sourcepos" % "0.1.1",
) ++ Seq(
"com.beachape" %% "enumeratum" % "1.6.1",
).map(_.withDottyCompat(scalaVersion.value)) ++ Seq(
Expand Down Expand Up @@ -153,14 +162,14 @@ lazy val tests = project
scalacOptions -= "-Xfatal-warnings",
libraryDependencies ++= Seq(
"org.typelevel" %% "scalacheck-effect-munit" % "0.7.1",
"org.typelevel" %% "munit-cats-effect-2" % "0.13.1",
"org.typelevel" %% "munit-cats-effect-3" % "0.13.1",
"org.typelevel" %% "cats-free" % "2.4.2",
"org.typelevel" %% "cats-laws" % "2.4.2",
"org.typelevel" %% "discipline-munit" % "1.0.6",
) ++ Seq(
"io.chrisdavenport" %% "cats-time" % "0.3.4",
).filterNot(_ => isDotty.value),
testFrameworks += new TestFramework("munit.Framework")
testFrameworks += new TestFramework("munit.Framework"),
)

lazy val example = project
Expand All @@ -171,14 +180,15 @@ lazy val example = project
.settings(
publish / skip := true,
libraryDependencies ++= Seq(
"org.tpolecat" %% "natchez-honeycomb" % "0.0.20",
"org.tpolecat" %% "natchez-jaeger" % "0.0.20",
) ++ Seq(
"org.http4s" %% "http4s-dsl" % "0.21.20",
"org.http4s" %% "http4s-blaze-server" % "0.21.20",
"org.http4s" %% "http4s-circe" % "0.21.20",
"io.circe" %% "circe-generic" % "0.13.0",
).filterNot(_ => isDotty.value)
"org.tpolecat" %% "natchez-honeycomb" % natchezVersion,
"org.tpolecat" %% "natchez-jaeger" % natchezVersion,
)
// ) ++ Seq(
// "org.http4s" %% "http4s-dsl" % "0.21.13",
// "org.http4s" %% "http4s-blaze-server" % "0.21.13",
// "org.http4s" %% "http4s-circe" % "0.21.13",
// "io.circe" %% "circe-generic" % "0.13.0",
// ).filterNot(_ => isDotty.value)
)

lazy val docs = project
Expand Down Expand Up @@ -212,6 +222,6 @@ lazy val docs = project
makeSite := makeSite.dependsOn(mdoc.toTask("")).value,
mdocExtraArguments := Seq("--no-link-hygiene"), // paradox handles this
libraryDependencies ++= Seq(
"org.tpolecat" %% "natchez-jaeger" % "0.0.14-M2",
"org.tpolecat" %% "natchez-jaeger" % natchezVersion,
)
)
3 changes: 2 additions & 1 deletion modules/core/src/main/scala/Channel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package skunk
import cats.{ Contravariant, Functor, ~> }
import cats.arrow.Profunctor
import cats.effect.Resource
import cats.effect.kernel.MonadCancelThrow
import cats.syntax.all._
import fs2.{ Pipe, Stream }
import skunk.data.{ Identifier, Notification }
Expand Down Expand Up @@ -96,7 +97,7 @@ object Channel {
* normally a `Channel` is obtained from a `Session`).
* @group Constructors
*/
def fromNameAndProtocol[F[_]: Functor](name: Identifier, proto: Protocol[F]): Channel[F, String, String] =
def fromNameAndProtocol[F[_]: MonadCancelThrow](name: Identifier, proto: Protocol[F]): Channel[F, String, String] =
new Channel[F, String, String] {

val listen: F[Unit] =
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/main/scala/PreparedCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package skunk

import cats.{ Contravariant, ~> }
import cats.effect.Bracket
import cats.effect.MonadCancel
import skunk.data.Completion
import skunk.net.Protocol
import skunk.util.Origin
Expand Down Expand Up @@ -50,7 +50,7 @@ object PreparedCommand {
}

def fromProto[F[_], A](pc: Protocol.PreparedCommand[F, A])(
implicit ev: Bracket[F, Throwable]
implicit ev: MonadCancel[F, Throwable]
): PreparedCommand[F, A] =
new PreparedCommand[F, A] {
override def execute(args: A)(implicit origin: Origin): F[Completion] =
Expand Down
10 changes: 7 additions & 3 deletions modules/core/src/main/scala/PreparedQuery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ trait PreparedQuery[F[_], A, B] {
object PreparedQuery {

def fromProto[F[_], A, B](proto: Protocol.PreparedQuery[F, A, B])(
implicit ev: Bracket[F, Throwable]
implicit ev: MonadCancel[F, Throwable]
): PreparedQuery[F, A, B] =
new PreparedQuery[F, A, B] {

Expand Down Expand Up @@ -180,13 +180,17 @@ object PreparedQuery {
override def rmap[A, B, C](fab: PreparedQuery[F, A, B])(f: B => C): PreparedQuery[F, A, C] = fab.map(f)
}

implicit class PreparedQueryOps[F[_], A, B](outer: PreparedQuery[F, A, B]) {
implicit class PreparedQueryOps[F[_], A, B](outer: PreparedQuery[F, A, B])(
implicit mcf: MonadCancel[F, _]
) {

/**
* Transform this `PreparedQuery` by a given `FunctionK`.
* @group Transformations
*/
def mapK[G[_]: Applicative: Defer](fk: F ~> G): PreparedQuery[G, A, B] =
def mapK[G[_]](fk: F ~> G)(
implicit mcg: MonadCancel[G, _]
): PreparedQuery[G, A, B] =
new PreparedQuery[G, A, B] {
override def cursor(args: A)(implicit or: Origin): Resource[G,Cursor[G,B]] = outer.cursor(args).mapK(fk).map(_.mapK(fk))
override def option(args: A)(implicit or: Origin): G[Option[B]] = fk(outer.option(args))
Expand Down
51 changes: 27 additions & 24 deletions modules/core/src/main/scala/SSL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,41 @@

package skunk

import cats.effect._
import cats._
import cats.syntax.all._
import fs2.io.tls.TLSContext
import java.nio.file.Path
import java.security.KeyStore
import javax.net.ssl.SSLContext
import fs2.io.tls.TLSParameters
import fs2.io.net.Network
import fs2.io.net.tls.TLSContext
import fs2.io.net.tls.TLSParameters
import skunk.net.SSLNegotiation

sealed abstract class SSL(
val tlsParameters: TLSParameters = TLSParameters.Default,
val fallbackOk: Boolean = false,
) { outer =>

def tlsContext[F[_]: Sync: ContextShift](b: Blocker): F[TLSContext]
def tlsContext[F[_]: Network](implicit ev: ApplicativeError[F, Throwable]): F[TLSContext[F]]

def withTLSParameters(tlsParameters: TLSParameters): SSL =
new SSL(tlsParameters, fallbackOk) {
def tlsContext[F[_]: Sync: ContextShift](b: Blocker): F[TLSContext] =
outer.tlsContext(b)
def tlsContext[F[_]: Network](implicit ev: ApplicativeError[F, Throwable]): F[TLSContext[F]] =
outer.tlsContext
}

def withFallback(fallbackOk: Boolean): SSL =
new SSL(tlsParameters, fallbackOk) {
def tlsContext[F[_]: Sync: ContextShift](b: Blocker): F[TLSContext] =
outer.tlsContext(b)
def tlsContext[F[_]: Network](implicit ev: ApplicativeError[F, Throwable]): F[TLSContext[F]] =
outer.tlsContext
}

def toSSLNegotiationOptions[F[_]: Sync: ContextShift](b: Blocker, logger: Option[String => F[Unit]]): F[Option[SSLNegotiation.Options[F]]] =
def toSSLNegotiationOptions[F[_]: Network](logger: Option[String => F[Unit]])(
implicit ev: ApplicativeError[F, Throwable]
): F[Option[SSLNegotiation.Options[F]]] =
this match {
case SSL.None => none.pure[F]
case _ => tlsContext(b).map(SSLNegotiation.Options(_, tlsParameters, fallbackOk, logger).some)
case _ => tlsContext.map(SSLNegotiation.Options(_, tlsParameters, fallbackOk, logger).some)
}

}
Expand All @@ -44,29 +47,29 @@ object SSL {

/** `SSL` which indicates that SSL is not to be used. */
object None extends SSL() {
def tlsContext[F[_]: Sync: ContextShift](b: Blocker): F[TLSContext] =
Sync[F].raiseError(new Exception("SSL.None: cannot create a TLSContext."))
def tlsContext[F[_]: Network](implicit ev: ApplicativeError[F, Throwable]): F[TLSContext[F]] =
ev.raiseError(new Exception("SSL.None: cannot create a TLSContext."))
override def withFallback(fallbackOk: Boolean): SSL = this
override def withTLSParameters(tlsParameters: TLSParameters): SSL = this
}

/** `SSL` which trusts all certificates. */
object Trusted extends SSL() {
def tlsContext[F[_]: Sync: ContextShift](b: Blocker): F[TLSContext] =
TLSContext.insecure(b)
def tlsContext[F[_]: Network](implicit ev: ApplicativeError[F, Throwable]): F[TLSContext[F]] =
Network[F].tlsContext.insecure
}

/** `SSL` from the system default `SSLContext`. */
object System extends SSL() {
def tlsContext[F[_]: Sync: ContextShift](b: Blocker): F[TLSContext] =
TLSContext.system(b)
def tlsContext[F[_]: Network](implicit ev: ApplicativeError[F, Throwable]): F[TLSContext[F]] =
Network[F].tlsContext.system
}

/** Creates a `SSL` from an `SSLContext`. */
def fromSSLContext(ctx: SSLContext): SSL =
new SSL() {
def tlsContext[F[_]: Sync: ContextShift](b: Blocker): F[TLSContext] =
TLSContext.fromSSLContext(ctx, b).pure[F]
def tlsContext[F[_]: Network](implicit ev: ApplicativeError[F, Throwable]): F[TLSContext[F]] =
Network[F].tlsContext.fromSSLContext(ctx).pure[F]
}

/** Creates a `SSL` from the specified key store file. */
Expand All @@ -76,8 +79,8 @@ object SSL {
keyPassword: Array[Char],
): SSL =
new SSL() {
def tlsContext[F[_]: Sync: ContextShift](b: Blocker): F[TLSContext] =
TLSContext.fromKeyStoreFile(file, storePassword, keyPassword, b)
def tlsContext[F[_]: Network](implicit ev: ApplicativeError[F, Throwable]): F[TLSContext[F]] =
Network[F].tlsContext.fromKeyStoreFile(file, storePassword, keyPassword)
}

/** Creates a `SSL` from the specified class path resource. */
Expand All @@ -87,8 +90,8 @@ object SSL {
keyPassword: Array[Char],
): SSL =
new SSL() {
def tlsContext[F[_]: Sync: ContextShift](b: Blocker): F[TLSContext] =
TLSContext.fromKeyStoreResource(resource, storePassword, keyPassword, b)
def tlsContext[F[_]: Network](implicit ev: ApplicativeError[F, Throwable]): F[TLSContext[F]] =
Network[F].tlsContext.fromKeyStoreResource(resource, storePassword, keyPassword)
}

/** Creates a `TLSContext` from the specified key store. */
Expand All @@ -97,8 +100,8 @@ object SSL {
keyPassword: Array[Char],
): SSL =
new SSL() {
def tlsContext[F[_]: Sync: ContextShift](b: Blocker): F[TLSContext] =
TLSContext.fromKeyStore(keyStore, keyPassword, b)
def tlsContext[F[_]: Network](implicit ev: ApplicativeError[F, Throwable]): F[TLSContext[F]] =
Network[F].tlsContext.fromKeyStore(keyStore, keyPassword)
}

}
Loading

0 comments on commit 91c51d1

Please sign in to comment.