Skip to content

Commit

Permalink
Merge pull request #85 from pauljamescleary/update-deps
Browse files Browse the repository at this point in the history
Update dependencies to latest under Scala 2.12.6
  • Loading branch information
pauljamescleary committed May 19, 2018
2 parents fd1ef15 + 39db8ff commit 066489e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,7 +1,7 @@
language: scala

scala:
- 2.12.3
- 2.12.6

python:
- "2.7"
Expand Down
23 changes: 9 additions & 14 deletions build.sbt
@@ -1,24 +1,21 @@
organization := "io.github.pauljamescleary"
name := "scala-pet-store"
version := "0.0.1-SNAPSHOT"
scalaVersion := "2.12.3"
scalaVersion := "2.12.6"

resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots"),
"jmcardon at bintray" at "https://dl.bintray.com/jmcardon/tsec"
)
resolvers += Resolver.sonatypeRepo("snapshots")

val CatsVersion = "1.0.1"
val CirceVersion = "0.9.1"
val DoobieVersion = "0.5.1"
val CatsVersion = "1.1.0"
val CirceVersion = "0.9.3"
val DoobieVersion = "0.5.2"
val H2Version = "1.4.196"
val Http4sVersion = "0.18.1"
val Http4sVersion = "0.18.4"
val LogbackVersion = "1.2.3"
val ScalaCheckVersion = "1.13.5"
val ScalaCheckVersion = "1.14.0"
val ScalaTestVersion = "3.0.4"
val FlywayVersion = "4.2.0"
val PureConfigVersion = "0.9.0"
val TsecVersion = "0.0.1-M9"
val PureConfigVersion = "0.9.1"
val TsecVersion = "0.0.1-M11"

libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % CatsVersion,
Expand All @@ -45,10 +42,8 @@ libraryDependencies ++= Seq(
// Authentication dependencies
"io.github.jmcardon" %% "tsec-common" % TsecVersion,
"io.github.jmcardon" %% "tsec-password" % TsecVersion,
"io.github.jmcardon" %% "tsec-symmetric-cipher" % TsecVersion,
"io.github.jmcardon" %% "tsec-mac" % TsecVersion,
"io.github.jmcardon" %% "tsec-signatures" % TsecVersion,
"io.github.jmcardon" %% "tsec-md" % TsecVersion,
"io.github.jmcardon" %% "tsec-jwt-mac" % TsecVersion,
"io.github.jmcardon" %% "tsec-jwt-sig" % TsecVersion,
"io.github.jmcardon" %% "tsec-http4s" % TsecVersion
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
@@ -1 +1 @@
sbt.version=1.1.1
sbt.version=1.1.4
8 changes: 4 additions & 4 deletions project/plugins.sbt
@@ -1,19 +1,19 @@
// Makes our code tidy
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.3.0")
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1")

// Revolver allows us to use re-start and work a lot faster!
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.0")

// Native Packager allows us to create standalone jar
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.2.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.4")

// Database migrations
addSbtPlugin("org.flywaydb" % "flyway-sbt" % "4.2.0")

// Documentation plugins
addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.6.2")
addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.6.4")

addSbtPlugin("com.47deg" % "sbt-microsites" % "0.7.15")
addSbtPlugin("com.47deg" % "sbt-microsites" % "0.7.18")

addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.2")

Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/io/github/pauljamescleary/petstore/Server.scala
Expand Up @@ -10,22 +10,22 @@ import cats.effect._
import fs2.StreamApp.ExitCode
import fs2.{Stream, StreamApp}
import org.http4s.server.blaze.BlazeBuilder
import tsec.mac.imports._
import tsec.passwordhashers.imports.BCrypt
import tsec.mac.jca.HMACSHA256
import tsec.passwordhashers.jca.BCrypt

object Server extends StreamApp[IO] {
import scala.concurrent.ExecutionContext.Implicits.global

override def stream(args: List[String], shutdown: IO[Unit]): Stream[IO, ExitCode] =
createStream[IO](args, shutdown)

val keyGen = HMACSHA256
private val keyGen = HMACSHA256

def createStream[F[_]](args: List[String], shutdown: F[Unit])(
implicit E: Effect[F]): Stream[F, ExitCode] =
for {
conf <- Stream.eval(PetStoreConfig.load[F])
signingKey <- Stream.eval(keyGen.generateLift[F])
signingKey <- Stream.eval(keyGen.generateKey[F])
xa <- Stream.eval(DatabaseConfig.dbTransactor(conf.db))
_ <- Stream.eval(DatabaseConfig.initializeDb(conf.db, xa))
petRepo = DoobiePetRepositoryInterpreter[F](xa)
Expand All @@ -40,7 +40,7 @@ object Server extends StreamApp[IO] {
.bindHttp(8080, "localhost")
.mountService(PetEndpoints.endpoints[F](petService), "/")
.mountService(OrderEndpoints.endpoints[F](orderService), "/")
.mountService(UserEndpoints.endpoints(userService, BCrypt), "/")
.mountService(UserEndpoints.endpoints(userService, BCrypt.syncPasswordHasher[F]), "/")
.serve
} yield exitCode
}
Expand Up @@ -14,8 +14,8 @@ import scala.language.higherKinds
import domain._
import domain.users._
import domain.authentication._
import tsec.passwordhashers.PasswordHash
import tsec.passwordhashers.core.PasswordHasher
import tsec.common.Verified
import tsec.passwordhashers.{PasswordHash, PasswordHasher}

class UserEndpoints[F[_]: Effect, A, K] extends Http4sDsl[F] {
import Pagination._
Expand All @@ -26,28 +26,26 @@ class UserEndpoints[F[_]: Effect, A, K] extends Http4sDsl[F] {

implicit val signupReqDecoder: EntityDecoder[F, SignupRequest] = jsonOf

private def loginEndpoint(userService: UserService[F], cryptService: PasswordHasher[A]): HttpService[F] =
private def loginEndpoint(userService: UserService[F], cryptService: PasswordHasher[F, A]): HttpService[F] =
HttpService[F] {
case req @ POST -> Root / "login" =>
val action: EitherT[F, UserAuthenticationFailedError, User] = for {
login <- EitherT.liftF(req.as[LoginRequest])
name = login.userName
user <- userService.getUserByName(name).leftMap(_ => UserAuthenticationFailedError(name))
valid <- EitherT.liftF(cryptService.checkpw(login.password, PasswordHash[A](user.hash)))
checkResult <- EitherT.liftF(cryptService.checkpw(login.password, PasswordHash[A](user.hash)))
resp <-
if(valid) EitherT.rightT[F, UserAuthenticationFailedError](user)
if(checkResult == Verified) EitherT.rightT[F, UserAuthenticationFailedError](user)
else EitherT.leftT[F, User](UserAuthenticationFailedError(name))
} yield resp

action
.fold(
{ case UserAuthenticationFailedError(name) => BadRequest(s"Authentication failed for user $name") },
u => Ok(u.asJson)
)
.flatten
action.value.flatMap {
case Right(user) => Ok(user.asJson)
case Left(UserAuthenticationFailedError(name)) => BadRequest(s"Authentication failed for user $name")
}
}

private def signupEndpoint(userService: UserService[F], crypt: PasswordHasher[A]): HttpService[F] =
private def signupEndpoint(userService: UserService[F], crypt: PasswordHasher[F, A]): HttpService[F] =
HttpService[F] {
case req @ POST -> Root / "users" =>
val action = for {
Expand Down Expand Up @@ -107,7 +105,7 @@ class UserEndpoints[F[_]: Effect, A, K] extends Http4sDsl[F] {
}


def endpoints(userService: UserService[F], cryptService: PasswordHasher[A]): HttpService[F] =
def endpoints(userService: UserService[F], cryptService: PasswordHasher[F, A]): HttpService[F] =
loginEndpoint(userService, cryptService) <+>
signupEndpoint(userService, cryptService) <+>
updateEndpoint(userService) <+>
Expand All @@ -119,7 +117,7 @@ class UserEndpoints[F[_]: Effect, A, K] extends Http4sDsl[F] {
object UserEndpoints {
def endpoints[F[_]: Effect, A, K](
userService: UserService[F],
cryptService: PasswordHasher[A]
cryptService: PasswordHasher[F, A]
): HttpService[F] =
new UserEndpoints[F, A, K].endpoints(userService, cryptService)
}
Expand Up @@ -12,11 +12,11 @@ import orders.{OrderRepositoryAlgebra, OrderStatus, Order}

private object OrderSQL {
/* We require type StatusMeta to handle our ADT Status */
private implicit val StatusMeta: Meta[OrderStatus] =
implicit val StatusMeta: Meta[OrderStatus] =
Meta[String].xmap(OrderStatus.apply, OrderStatus.nameOf)

/* We require conversion for date time */
private implicit val DateTimeMeta: Meta[Instant] =
implicit val DateTimeMeta: Meta[Instant] =
Meta[java.sql.Timestamp].xmap(
ts => ts.toInstant,
dt => java.sql.Timestamp.from(dt)
Expand Down
Expand Up @@ -10,7 +10,7 @@ import org.http4s._
import org.http4s.dsl._
import org.http4s.circe._

import tsec.passwordhashers.imports.BCrypt
import tsec.passwordhashers.jca.BCrypt

import domain.users._
import infrastructure.repository.inmemory.UserRepositoryInMemoryInterpreter
Expand All @@ -28,7 +28,7 @@ class UserEndpointsSpec
val userRepo = UserRepositoryInMemoryInterpreter[IO]()
val userValidation = UserValidationInterpreter[IO](userRepo)
val userService = UserService[IO](userRepo, userValidation)
val userHttpService = UserEndpoints.endpoints(userService, BCrypt)
val userHttpService = UserEndpoints.endpoints(userService, BCrypt.syncPasswordHasher[IO])

val user = User("username", "firstname", "lastname", "email", "password", "phone", None)

Expand All @@ -47,7 +47,7 @@ class UserEndpointsSpec
val userRepo = UserRepositoryInMemoryInterpreter[IO]()
val userValidation = UserValidationInterpreter[IO](userRepo)
val userService = UserService[IO](userRepo, userValidation)
val userHttpService: HttpService[IO] = UserEndpoints.endpoints(userService, BCrypt)
val userHttpService: HttpService[IO] = UserEndpoints.endpoints(userService, BCrypt.syncPasswordHasher[IO])

implicit val userDecoder: EntityDecoder[IO, User] = jsonOf[IO, User]

Expand Down Expand Up @@ -78,7 +78,7 @@ class UserEndpointsSpec
val userRepo = UserRepositoryInMemoryInterpreter[IO]()
val userValidation = UserValidationInterpreter[IO](userRepo)
val userService = UserService[IO](userRepo, userValidation)
val userHttpService: HttpService[IO] = UserEndpoints.endpoints(userService, BCrypt)
val userHttpService: HttpService[IO] = UserEndpoints.endpoints(userService, BCrypt.syncPasswordHasher[IO])

implicit val userDecoder: EntityDecoder[IO, User] = jsonOf[IO, User]

Expand Down Expand Up @@ -107,7 +107,7 @@ class UserEndpointsSpec
val userRepo = UserRepositoryInMemoryInterpreter[IO]()
val userValidation = UserValidationInterpreter[IO](userRepo)
val userService = UserService[IO](userRepo, userValidation)
val userHttpService: HttpService[IO] = UserEndpoints.endpoints(userService, BCrypt)
val userHttpService: HttpService[IO] = UserEndpoints.endpoints(userService, BCrypt.syncPasswordHasher[IO])

implicit val userDecoder: EntityDecoder[IO, User] = jsonOf[IO, User]

Expand Down

0 comments on commit 066489e

Please sign in to comment.