@@ -4,7 +4,9 @@ import cats.data.EitherT
4
4
import cats .effect .std .Random
5
5
import cats .effect .{ExitCode , IO , IOApp }
6
6
import com .comcast .ip4s .{Host , Port }
7
+ import com .github .mmvpm .secret .{SecretService , SecretServiceImpl }
7
8
import com .github .mmvpm .service .api .{AuthHandler , OfferHandler , UserHandler }
9
+ import com .github .mmvpm .service .config .{Config , ConfigLoader }
8
10
import com .github .mmvpm .service .dao .offer .{OfferDao , OfferDaoPostgresql }
9
11
import com .github .mmvpm .service .dao .session .{SessionDao , SessionDaoRedis }
10
12
import com .github .mmvpm .service .dao .user .{UserDao , UserDaoPostgresql }
@@ -19,24 +21,27 @@ import doobie.Transactor
19
21
import org .http4s .HttpRoutes
20
22
import org .http4s .ember .server .EmberServerBuilder
21
23
import org .http4s .server .Router
22
- import pureconfig .ConfigSource
23
- import pureconfig .generic .auto ._
24
24
import sttp .tapir .server .ServerEndpoint
25
25
import sttp .tapir .server .http4s .Http4sServerInterpreter
26
26
import sttp .tapir .swagger .bundle .SwaggerInterpreter
27
27
28
28
object Main extends IOApp {
29
29
30
30
override def run (args : List [String ]): IO [ExitCode ] = {
31
- val config = ConfigSource .resources(configByStage(args)).loadOrThrow[Config ]
32
- makeTransactor[IO ](config.postgresql).use(runServer(config)(_))
31
+ val secrets = new SecretServiceImpl [IO ]
32
+ val configLoader = ConfigLoader .impl[IO ](secrets)
33
+ for {
34
+ config <- configLoader.load(configByStage(args))
35
+ exitCode <- makeTransactor[IO ](config.postgresql).use(runServer(config, secrets)(_))
36
+ } yield exitCode
33
37
}
34
38
35
- private def runServer (config : Config )(implicit xa : Transactor [IO ]): IO [ExitCode ] =
39
+ private def runServer (config : Config , secrets : SecretService [ IO ] )(implicit xa : Transactor [IO ]): IO [ExitCode ] =
36
40
for {
37
41
random <- Random .scalaUtilRandom[IO ]
38
42
39
- redis = new RedisClient (config.redis.host, config.redis.port, secret = config.redis.password)
43
+ redisPassword <- secrets.redisPassword
44
+ redis = new RedisClient (config.redis.host, config.redis.port, secret = redisPassword)
40
45
41
46
offerDao : OfferDao [IO ] = new OfferDaoPostgresql [IO ]
42
47
sessionDao : SessionDao [IO ] = new SessionDaoRedis [IO ](redis, config.session.expiration.toSeconds)
0 commit comments