Skip to content

Commit

Permalink
Use Ember for Server Backend (#115)
Browse files Browse the repository at this point in the history
* Use Ember for Server Backend

* pretty

* Update test.conf
  • Loading branch information
etspaceman authored Jun 20, 2021
1 parent b0b432d commit 28388a1
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 65 deletions.
3 changes: 0 additions & 3 deletions .scala-steward.conf

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ these ports to a local one).
| Variable | Data Type | Default Value | Notes |
| -------- | --------- | ------------- | ----- |
| INITIALIZE_STREAMS | String | | A comma-delimited string of stream names and its corresponding shard count to initialize during startup. For example: "my-first-stream:1,my-other-stream:2,my-last-stream:1"|
| KINESIS_MOCK_HTTP2_PORT | Int | 4567 | Https Only |
| KINESIS_MOCK_HTTP1_PLAIN_PORT | Int | 4568 | Http Only |
| KINESIS_MOCK_TLS_PORT | Int | 4567 | Https Only |
| KINESIS_MOCK_PLAIN_PORT | Int | 4568 | Http Only |
| CREATE_STREAM_DURATION | Duration | 500ms | |
| DELETE_STREAM_DURATION | Duration | 500ms | |
| REGISTER_STREAM_CONSUMER_DURATION | Duration | 500ms | |
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ lazy val kinesisMock = project
Enumeratum.cats,
Enumeratum.core,
Enumeratum.circe,
Http4s.blazeServer,
Http4s.emberServer,
Http4s.circe,
Http4s.dsl,
JaxbApi,
Expand Down
4 changes: 2 additions & 2 deletions project/LibraryDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ object LibraryDependencies {
}

object Http4s {
val http4sVersion = "0.21.22"
val blazeServer = "org.http4s" %% "http4s-blaze-server" % http4sVersion
val http4sVersion = "0.21.24"
val circe = "org.http4s" %% "http4s-circe" % http4sVersion
val dsl = "org.http4s" %% "http4s-dsl" % http4sVersion
val emberServer = "org.http4s" %% "http4s-ember-server" % http4sVersion
}

object Circe {
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/service.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
http-2-port = 4567
http-1-plain-port = 4568
tls-port = 4567
plain-port = 4568
key-store-password = kinesisMock
key-manager-password = kinesisMock

http-2-port = ${?KINESIS_MOCK_HTTP2_PORT}
http-1-plain-port = ${?KINESIS_MOCK_HTTP1_PLAIN_PORT}
tls-port = ${?KINESIS_MOCK_TLS_PORT}
plain-port = ${?KINESIS_MOCK_PLAIN_PORT}
key-store-password = ${?KINESIS_MOCK_KEYSTORE_PASSWORD}
key-manager-password = ${?KINESIS_MOCK_KEYMANAGER_PASSWORD}
2 changes: 1 addition & 1 deletion src/main/resources/test.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
service-port=4567

service-port=${?SERVICE_PORT}
service-port=${?SERVICE_PORT}
41 changes: 22 additions & 19 deletions src/main/scala/kinesis/mock/KinesisMockService.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package kinesis.mock

import scala.concurrent.ExecutionContext
import scala.concurrent.duration._

import cats.effect.concurrent.Semaphore
import cats.effect.{Blocker, ExitCode, IO, IOApp}
import cats.implicits._
import fs2.io.tls.TLSContext
import io.circe.syntax._
import org.http4s.server.blaze.BlazeServerBuilder
import org.http4s.ember.server.EmberServerBuilder
import org.http4s.syntax.kleisli._
import org.typelevel.log4cats.SelfAwareStructuredLogger
import org.typelevel.log4cats.slf4j.Slf4jLogger
Expand Down Expand Up @@ -46,30 +46,33 @@ object KinesisMockService extends IOApp {
)
serviceConfig <- KinesisMockServiceConfig.read(blocker)
app = new KinesisMockRoutes(cache).routes.orNotFound
context <- ssl.loadContextFromClasspath[IO](
serviceConfig.keyStorePassword,
serviceConfig.keyManagerPassword
tlsContext <- TLSContext.fromKeyStoreResource[IO](
"server.jks",
serviceConfig.keyStorePassword.toCharArray(),
serviceConfig.keyManagerPassword.toCharArray(),
blocker
)
http2Server = BlazeServerBuilder[IO](ExecutionContext.global)
.bindHttp(serviceConfig.http2Port, "0.0.0.0")
tlsServer = EmberServerBuilder
.default[IO]
.withPort(serviceConfig.tlsPort)
.withHost("0.0.0.0")
.withTLS(tlsContext)
.withHttpApp(app)
.withSslContext(context)
.enableHttp2(
true
) // This is bugged and HTTP2 unfortunately does not work correctly right now
.resource
http1PlainServer = BlazeServerBuilder[IO](ExecutionContext.global)
.bindHttp(serviceConfig.http1PlainPort, "0.0.0.0")
.build
plainServer = EmberServerBuilder
.default[IO]
.withPort(serviceConfig.plainPort)
.withHost("0.0.0.0")
.withHttpApp(app)
.resource
.build
_ <- logger.info(
s"Starting Kinesis Http2 Mock Service on port ${serviceConfig.http2Port}"
s"Starting Kinesis TLS Mock Service on port ${serviceConfig.tlsPort}"
)
_ <- logger.info(
s"Starting Kinesis Http1 Plain Mock Service on port ${serviceConfig.http1PlainPort}"
s"Starting Kinesis Plain Mock Service on port ${serviceConfig.plainPort}"
)
res <- http2Server
.parZip(http1PlainServer)
res <- tlsServer
.parZip(plainServer)
.parZip(
persistDataLoop(
cacheConfig.persistConfig.shouldPersist,
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/kinesis/mock/KinesisMockServiceConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import pureconfig.module.catseffect.syntax._
import pureconfig.{ConfigReader, ConfigSource}

final case class KinesisMockServiceConfig(
http2Port: Int,
http1PlainPort: Int,
tlsPort: Int,
plainPort: Int,
keyStorePassword: String,
keyManagerPassword: String
)
Expand Down
31 changes: 0 additions & 31 deletions src/main/scala/kinesis/mock/ssl.scala

This file was deleted.

0 comments on commit 28388a1

Please sign in to comment.