Skip to content

Commit

Permalink
Merge pull request #1 from ThatScalaGuy/update-structure
Browse files Browse the repository at this point in the history
Prepare for scala-steward
  • Loading branch information
ThatScalaGuy authored Aug 6, 2024
2 parents 58c1c49 + adce785 commit 3d82b14
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 66 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,31 @@ jobs:
modules-ignore: root_2.13 root_3 docs_2.13 docs_3
configs-ignore: test scala-tool scala-doc-tool test-internal

validate-steward:
name: Validate Steward Config
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (fast)
uses: actions/checkout@v4

- name: Setup Java (temurin@11)
id: setup-java-temurin-11
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11

- uses: coursier/setup-action@v1
with:
apps: scala-steward

- run: scala-steward validate-repo-config .scala-steward.conf

site:
name: Generate Site
strategy:
Expand Down
5 changes: 5 additions & 0 deletions .scala-steward.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pullRequests.grouping = [
{ name = "patches", "title" = "Patch updates", "filter" = [{"version" = "patch"}] },
{ name = "minor_major", "title" = "Minor/major updates", "filter" = [{"version" = "minor"}, {"version" = "major"}] },
{ name = "all", title = "Dependency updates", "filter" = [{"group" = "*"}] }
]
21 changes: 19 additions & 2 deletions .scalafix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,22 @@ rules = [
OrganizeImports
]

OrganizeImports.removeUnused = false
OrganizeImports.targetDialect = Scala3
OrganizeImports {
blankLines = Auto
coalesceToWildcardImportThreshold = null
expandRelative = false
groupExplicitlyImportedImplicitsSeparately = true
groupedImports = AggressiveMerge
groups = [
"cats"
"cats.effect"
"nats4cats"
"*"
"re:(javax?|scala)\\."
]
importSelectorsOrder = Ascii
importsOrder = Ascii
preset = DEFAULT
}

OrganizeImports.removeUnused = false
9 changes: 8 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
version = 3.7.1
version = 3.8.3
runner.dialect = scala213source3
style = defaultWithAlign
maxColumn = 160
includeCurlyBraceInSelectChains = false
newlines.penalizeSingleSelectMultiArgList = false
project.git = true
project.excludeFilters = ["target/"]


fileOverride {
"glob:**/scala-3/**" {
Expand Down
38 changes: 23 additions & 15 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
lazy val V = new {
val Scala213 = "2.13.14"
val Scala3 = "3.3.3"
val Skunk = "1.0.0-M7"
val Cats = "2.12.0"
val CatsEffect = "3.5.4"
val Munit = "1.0.0"
val MunitCatsEffect = "2.0.0"
val Testcontainers = "0.41.4"
}

// https://typelevel.org/sbt-typelevel/faq.html#what-is-a-base-version-anyway
ThisBuild / tlBaseVersion := "0.0" // your current series x.y

ThisBuild / organization := "de.thatscalaguy"
ThisBuild / organization := "de.thatscalaguy"
ThisBuild / organizationName := "ThatScalaGuy"
ThisBuild / startYear := Some(2024)
ThisBuild / licenses := Seq(License.Apache2)
ThisBuild / startYear := Some(2024)
ThisBuild / licenses := Seq(License.Apache2)
ThisBuild / developers := List(
// your GitHub handle and name
tlGitHubDev("ThatScalaGuy", "Sven Herrmann")
Expand All @@ -16,13 +27,10 @@ ThisBuild / tlSonatypeUseLegacyHost := false
// publish website from this branch
ThisBuild / tlSitePublishBranch := Some("main")

val Scala213 = "2.13.14"
val Scala3 = "3.3.3"

ThisBuild / crossScalaVersions := Seq(Scala213, Scala3)
ThisBuild / scalaVersion := Scala213 // the default Scala
ThisBuild / crossScalaVersions := Seq(V.Scala213, V.Scala3)
ThisBuild / scalaVersion := V.Scala213 // the default Scala

Test / fork := true
Test / fork := true
Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat

lazy val root = (project in file("."))
Expand All @@ -34,12 +42,12 @@ lazy val core = project
.settings(
name := "skunk-crypt",
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "2.12.0",
"org.typelevel" %% "cats-effect" % "3.5.4",
"org.tpolecat" %% "skunk-core" % "1.0.0-M7",
"org.scalameta" %% "munit" % "1.0.0" % Test,
"org.typelevel" %% "munit-cats-effect" % "2.0.0" % Test,
"com.dimafeng" %% "testcontainers-scala-munit" % "0.41.4" % Test
"org.typelevel" %% "cats-core" % V.Cats % "provided",
"org.typelevel" %% "cats-effect" % V.CatsEffect % "provided",
"org.tpolecat" %% "skunk-core" % V.Skunk % "provided",
"org.scalameta" %% "munit" % "1.0.0" % Test,
"org.typelevel" %% "munit-cats-effect" % "2.0.0" % Test,
"com.dimafeng" %% "testcontainers-scala-munit" % "0.41.4" % Test
)
)

Expand Down
20 changes: 10 additions & 10 deletions core/src/main/scala/de/thatscalaguy/skunkcrypt/CryptCodecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

package de.thatscalaguy.skunkcrypt

import cats.syntax.all.*
import cats.syntax.all._

import skunk.Codec
import skunk.codec.numeric.safe
import skunk.data.Type

import java.security.SecureRandom
import java.util.Base64
import javax.crypto.Cipher
import javax.crypto.SecretKey
import javax.crypto.spec.GCMParameterSpec
import javax.crypto.{Cipher, SecretKey}

trait CryptCodecs {
val GCM_IV_LENGTH = 12
val GCM_IV_LENGTH = 12
val GCM_TAG_LENGTH = 16

private[skunkcrypt] def encrypt(implicit c: CryptContext): String => String
Expand All @@ -40,8 +40,8 @@ trait CryptCodecs {
value: String
) = {
val secretKey = secretKeys.last
val ivSpec = new GCMParameterSpec(GCM_TAG_LENGTH * 8, iv)
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
val ivSpec = new GCMParameterSpec(GCM_TAG_LENGTH * 8, iv)
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivSpec)
val encryptedBytes = cipher.doFinal(value.getBytes())
Base64.getEncoder.encodeToString(
Expand All @@ -56,8 +56,8 @@ trait CryptCodecs {
encrypted: String
) = {
val encryptedBytes = Base64.getDecoder.decode(encrypted)
val ivSpec = new GCMParameterSpec(GCM_TAG_LENGTH * 8, iv)
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
val ivSpec = new GCMParameterSpec(GCM_TAG_LENGTH * 8, iv)
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
cipher.init(Cipher.DECRYPT_MODE, secretKey, ivSpec)
new String(cipher.doFinal(encryptedBytes))
}
Expand Down Expand Up @@ -113,7 +113,7 @@ object crypt extends CryptCodecs {
def decrypt(implicit c: CryptContext) = value =>
value.split("\\.").toList match {
case iv :: keyIndex :: encrypted :: Nil =>
val ivBytes = Base64.getDecoder.decode(iv)
val ivBytes = Base64.getDecoder.decode(iv)
val secretKey = c.secretKeys(keyIndex.toInt)
genDecrypt(ivBytes, secretKey, encrypted)
case _ => throw new Exception("Invalid input")
Expand All @@ -130,7 +130,7 @@ object cryptd extends CryptCodecs {
def decrypt(implicit c: CryptContext) = value =>
value.split("\\.").toList match {
case iv :: keyIndex :: encrypted :: Nil =>
val ivBytes = Base64.getDecoder.decode(iv)
val ivBytes = Base64.getDecoder.decode(iv)
val secretKey = c.secretKeys(keyIndex.toInt)
genDecrypt(ivBytes, secretKey, encrypted)
case _ => throw new Exception("Invalid input")
Expand Down
65 changes: 31 additions & 34 deletions core/src/test/scala/de/thatscalaguy/skunkcrypt/MainSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
package de.thatscalaguy.skunkcrypt

import cats.effect.IO

import com.dimafeng.testcontainers.GenericContainer
import com.dimafeng.testcontainers.munit.TestContainerForAll
import munit.CatsEffectSuite
import org.testcontainers.containers.wait.strategy.Wait
import skunk._
import skunk.codec.all._
import skunk.implicits._

import org.typelevel.otel4s.trace.Tracer.Implicits.noop
import skunk.*
import skunk.SSL
import skunk.Session
import skunk.codec.all.*
import skunk.implicits.*

class MainSuite extends CatsEffectSuite with TestContainerForAll {
override val containerDef = GenericContainer.Def(
Expand All @@ -52,13 +52,11 @@ class MainSuite extends CatsEffectSuite with TestContainerForAll {

session(
containers.asInstanceOf[GenericContainer].container.getMappedPort(5432)
)
.use { session =>
session.execute(
sql"CREATE TABLE test (string TEXT, numbers TEXT)".command
)
}
.void
).use { session =>
session.execute(
sql"CREATE TABLE test (string TEXT, numbers TEXT)".command
)
}.void
.unsafeRunSync()
}

Expand All @@ -70,30 +68,29 @@ class MainSuite extends CatsEffectSuite with TestContainerForAll {
"c0e5c54c2a40c95b40d6e837a9c147d4cd7cadeccc555e679efed48f726a5fef"
)
.get
session(database.container.getMappedPort(5432))
.use { session =>
for {
// _ <- session.execute(
// sql"INSERT INTO test (string, numbers) VALUES (${text}, ${crypt.int4})".command
// )("hpc3AZ+t1m7mDBf2.e11YUVCQUkPdytj441OjImPhnElN+wSOLL7liXcB+TeRbrsESuGdidbndfu3", 123)
_ <- session.execute(
sql"INSERT INTO test (string, numbers) VALUES (${cryptd.text}, ${cryptd.int4})".command
)(("Hello", 123))
_ <- session
.execute(
sql"SELECT * FROM test".query(cryptd.text ~ text)
)
.map(_.foreach(println))
session(database.container.getMappedPort(5432)).use { session =>
for {
// _ <- session.execute(
// sql"INSERT INTO test (string, numbers) VALUES (${text}, ${crypt.int4})".command
// )("hpc3AZ+t1m7mDBf2.e11YUVCQUkPdytj441OjImPhnElN+wSOLL7liXcB+TeRbrsESuGdidbndfu3", 123)
_ <- session.execute(
sql"INSERT INTO test (string, numbers) VALUES (${cryptd.text}, ${cryptd.int4})".command
)(("Hello", 123))
_ <- session
.execute(
sql"SELECT * FROM test".query(cryptd.text ~ text)
)
.map(_.foreach(println))

_ <- session
.execute(
sql"SELECT * FROM test"
.query(cryptd.text ~ cryptd.int4)
)
.map(_.foreach(println))
} yield ()
_ <- session
.execute(
sql"SELECT * FROM test"
.query(cryptd.text ~ cryptd.int4)
)
.map(_.foreach(println))
} yield ()

}
}
.unsafeRunSync()
}
}
Expand Down
8 changes: 4 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.7.2")
addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % "0.7.2")
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.7.2")
addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % "0.7.2")
addSbtPlugin("org.typelevel" % "sbt-typelevel-scalafix" % "0.7.2")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.4")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.4")

0 comments on commit 3d82b14

Please sign in to comment.