Cleanup and env file
This commit is contained in:
@@ -8,9 +8,6 @@ import server.Server
|
||||
|
||||
object Main extends IOApp {
|
||||
def run(args: List[String]): IO[ExitCode] = {
|
||||
// postgres://weather_tool:XID547uldXliJBa@weather-tool-db.flycast:5432/weather_tool?sslmode=disable
|
||||
// println(System.getenv("DATABASE_URL"))
|
||||
|
||||
for {
|
||||
transactor <- DBConnection.transactor[IO]
|
||||
postgresService <- PostgresService.of(transactor)
|
||||
|
||||
@@ -2,9 +2,6 @@ package db
|
||||
|
||||
import cats.effect.{Async, IO}
|
||||
import doobie.Transactor
|
||||
import pureconfig._
|
||||
import pureconfig.generic.auto._
|
||||
import pureconfig.error.ConfigReaderFailures
|
||||
|
||||
import java.net.URI
|
||||
import scala.util.Try
|
||||
@@ -12,8 +9,12 @@ import scala.util.Try
|
||||
case class PostgresConfig(url: String, username: String, password: String)
|
||||
|
||||
object DBConnection {
|
||||
private def getDbName = sys.env.getOrElse("POSTGRES_DB", "")
|
||||
private def getDbUser = sys.env.getOrElse("POSTGRES_USER", "")
|
||||
private def getDbPassword = sys.env.getOrElse("POSTGRES_PASSWORD", "")
|
||||
|
||||
private def getDatabaseUrl: String =
|
||||
sys.env.getOrElse("DATABASE_URL", "postgres://postgres:mysecretpassword@postgres:5432/weather-tool")
|
||||
sys.env.getOrElse("DATABASE_URL", s"postgres://${getDbUser}:${getDbPassword}@postgres:5432/${getDbName}")
|
||||
|
||||
private def parseUrl(url: String): Either[String, PostgresConfig] = {
|
||||
Try {
|
||||
@@ -24,8 +25,6 @@ object DBConnection {
|
||||
val username = raw.getUserInfo.split(":")(0)
|
||||
val password = raw.getUserInfo.split(":")(1)
|
||||
|
||||
println(s"n: $name u: $username, p: $password, url: $url")
|
||||
|
||||
PostgresConfig(dbUrl, username, password)
|
||||
}.toEither.left.map(_.getMessage)
|
||||
}
|
||||
@@ -41,24 +40,4 @@ object DBConnection {
|
||||
case Left(error) => IO.raiseError(new RuntimeException(s"Failed to parse DATABASE_URL: $error"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//case class PostgresConfig(url: String, username: String, password: String)
|
||||
|
||||
//object DBConnection {
|
||||
// private def loadPostgresConfig: Either[ConfigReaderFailures, PostgresConfig] = {
|
||||
// ConfigSource.resources("postgres.conf").load[PostgresConfig]
|
||||
// }
|
||||
//
|
||||
// def transactor[F[_] : Async]: IO[Transactor[F]] = {
|
||||
// loadPostgresConfig match {
|
||||
// case Right(config) => IO(Transactor.fromDriverManager[F](
|
||||
// "org.postgresql.Driver",
|
||||
// config.url,
|
||||
// config.username,
|
||||
// config.password
|
||||
// ))
|
||||
// case Left(errors) => IO.raiseError(new RuntimeException(s"Failed to load config: $errors"))
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
@@ -8,8 +8,6 @@ import org.http4s.headers.Authorization
|
||||
import org.http4s.ember.client.EmberClientBuilder
|
||||
import org.typelevel.log4cats.Logger
|
||||
import org.typelevel.log4cats.slf4j.Slf4jLogger
|
||||
import pureconfig._
|
||||
import pureconfig.generic.auto._
|
||||
|
||||
import java.time.{LocalDate, LocalDateTime}
|
||||
|
||||
@@ -25,11 +23,16 @@ object FetchService {
|
||||
}
|
||||
}
|
||||
|
||||
class FetchService(fileNameService: FileNameService, log: Logger[IO]) {
|
||||
private val weatherServerConfig: WeatherServerConfig = ConfigSource.default.load[WeatherServerConfig] match {
|
||||
case Right(config) => config
|
||||
case Left(errors) => throw new RuntimeException(s"Unable to load config: $errors")
|
||||
}
|
||||
class FetchService(fileNameService: FileNameService, log: Logger[IO]) {private val weatherServerConfig: WeatherServerConfig = (
|
||||
sys.env.get("METEO_USER"),
|
||||
sys.env.get("METEO_PASSWORD"),
|
||||
sys.env.get("METEO_URL")
|
||||
) match {
|
||||
case (Some(user), Some(password), Some(url)) =>
|
||||
WeatherServerConfig(user, password, url)
|
||||
case _ =>
|
||||
throw new RuntimeException("Unable to load meteo config: Missing required environment variables")
|
||||
}
|
||||
|
||||
private val basicCredentials: BasicCredentials =
|
||||
BasicCredentials(weatherServerConfig.username, weatherServerConfig.password)
|
||||
|
||||
Reference in New Issue
Block a user