Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 2019 15:23
    ashabhasa starred pureconfig/pureconfig
  • Jan 30 2019 20:03

    ruippeixotog on master

    Update cats-effect, fs2 and htt… Merge pull request #448 from ba… (compare)

  • Jan 30 2019 20:03
    ruippeixotog closed #448
  • Jan 30 2019 08:05
    Mao1990 starred pureconfig/pureconfig
  • Jan 29 2019 13:08
    bardurdam opened #448
  • Jan 29 2019 10:20
    PatrykRudnicki starred pureconfig/pureconfig
  • Jan 28 2019 18:52

    ruippeixotog on master

    Create a FluentConfigCursor Merge branch 'master' into flue… Fix yaml module on Scala 2.11 and 3 more (compare)

  • Jan 28 2019 18:52
    ruippeixotog closed #443
  • Jan 28 2019 18:02
    ruippeixotog synchronize #443
  • Jan 28 2019 18:02

    ruippeixotog on fluent-cursor

    Create scalaz module for pureco… Merge branch 'master' into scal… Update module with latest Confi… and 19 more (compare)

  • Jan 27 2019 14:09
    esumitra starred pureconfig/pureconfig
  • Jan 27 2019 01:55

    ruippeixotog on master

    Create scalaz module for pureco… Merge branch 'master' into scal… Update module with latest Confi… and 6 more (compare)

  • Jan 27 2019 01:55
    ruippeixotog closed #444
  • Jan 27 2019 01:19
    ruippeixotog synchronize #444
  • Jan 27 2019 01:19

    ruippeixotog on master

    Add cron4s module - add cron4s… Merge pull request #446 from ba… (compare)

  • Jan 27 2019 01:19
    ruippeixotog closed #446
  • Jan 26 2019 22:51
    ChernikovP synchronize #444
  • Jan 26 2019 22:37
    bardurdam synchronize #446
  • Jan 26 2019 22:36
    bardurdam commented #446
  • Jan 26 2019 22:31
    bardurdam synchronize #446
Peter Storm
@peterstorm
This is what I'm trying to do:
package config

import cats.effect._
import cats.implicits._
import pureconfig._
import pureconfig.generic.auto._
import pureconfig.module.catseffect.syntax._
import com.typesafe.config.ConfigFactory

final case class Config(
    server: ServerConfig, 
    database: DatabaseConfig
)

object Config:
    def load[F[_]: Sync: ContextShift](configFile: String = "application.conf"): Resource[F, Config] =
        Blocker[F].flatMap { blocker =>
            Resource.liftF(ConfigSource.fromConfig(ConfigFactory.load(configFile)).loadF[F, Config](blocker))
        }
Peter Storm
@peterstorm
Ah, it's because of the missing macro support. Can I manually derive these things_
Peter Storm
@peterstorm
Ah, think I figured it out
Peter Storm
@peterstorm
Maybe not, it's still complaining about not being able to find an instance, even though I thought I gave it manually?
package config

import cats.effect._
import cats.implicits._
import pureconfig._
import pureconfig.module.catseffect.syntax._
import com.typesafe.config.ConfigFactory

final case class Config(
    server: ServerConfig, 
    database: DatabaseConfig
)

object Config:
    given configReader as ConfigReader[Config] = ConfigReader.forProduct2("server", "database")(Config(_, _))


object ConfigLoader:
    def load[F[_]: Sync: ContextShift](configFile: String = "application.conf"): Resource[F, Config] =
            Blocker[F].flatMap { blocker => 
                Resource.liftF(ConfigSource.fromConfig(ConfigFactory.load(configFile)).loadF[F, Config](blocker))
            }
Joao Azevedo
@jcazevedo
@peterstorm: Does it complain not finding an instance of ConfigReader[Config], or an instance of Derivation[ConfigReader[Config]]?
Peter Storm
@peterstorm

Cannot find an implicit instance of pureconfig.ConfigReader[config.Config].
If you are trying to read or write a case class or sealed trait consider using PureConfig's auto derivation by adding import pureconfig.generic.auto._.
I found:

pureconfig.Derivation.materializeDerivation[A]

But method materializeDerivation in object Derivation does not match type pureconfig.Derivation[pureconfig.ConfigReader[config.Config]].

It can find the instances for ConfigReader[ServerConfig] and ConfigReader[DatabaseConfig] because if I comnment out the instances for those, it complains about those too
Joao Azevedo
@jcazevedo
Can you try defining an implicit instance for Derivation[ConfigReader[Config]]? given configReader as Derivation[ConfigReader[Config]] = Derivation.Successful(ConfigReader.forProduct2("server", "database")(Config(_, _)))
This is not ideal, and will be fixed once we tackle #854, but creating Derivation instances is currently behind a Scala 2 macro.
Peter Storm
@peterstorm
That worked!
So why did taht work? :D
Joao Azevedo
@jcazevedo
We have a special type whenever we ask for ConfigReader instances internally (the Derivation[_]) so that we can show better errors when implicit instances are not found.
The problem is that creating a Derivation instance uses Scala 2 macros.
Peter Storm
@peterstorm
Ah ok, but the syntax works for my other classes though
object DatabaseConfig:
    given configReader as ConfigReader[DatabaseConfig] = ConfigReader.forProduct5("driver", "url", "user", "pass", "poolSize")(DatabaseConfig(_, _, _, _, _))
It finds that instance for example, as I said if I remove that it complains
Should I rewrite it using your method instead?
Joao Azevedo
@jcazevedo
That's because the forProductN helpers require instances of ConfigReader, and not Derivation[ConfigReader].
Peter Storm
@peterstorm
Aaah ok
Great, thanks alot for the help! Happy to be able to use pureconfig :D
Joao Azevedo
@jcazevedo
But you shouldn't need to manually define Derivation instances. That should be fixed after #854.
Peter Storm
@peterstorm
Awesome :)
Luis Miguel Mejía Suárez
@BalmungSan

Hello, hopefully, quick question.

Is there a simple way to extract multiple values from a single environment variable that is a JSON?

Like I have an env var like this:

SECRETS='{"USER": "Luis", "PASSWORD": "123" }'

And I would like to load in my app a case class like this:

final case class Config(user: String, password: String)
I tried with an application.conf like this:
secrets = ${SECRETS}
user = ${secrets.USER}
password = ${secrets.password}
But neither upper case, not lower case worked.

I found in the HOCO docs that env vars are always read as Strings, but that they can be casted to other types.

So I tried reading a case class like: final case class Config(secrets: com.typesafe.config.ConfigObject) to try to extract my values from that object, but I got:

Expected type OBJECT. Found STRING instead.

Luis Miguel Mejía Suárez
@BalmungSan
At this point, I am clueless about what to do.
If this is even possible or if I would need to parse that json outside of pureconfig.
Luis Miguel Mejía Suárez
@BalmungSan
Uhm it seems I can use the circe module to read that env var into a Json object and then decode that into my case class...
It works, but it is a bit ugly.
Not sure if there is a better way?
Rui Gonçalves
@ruippeixotog
You can't do that in PureConfig or Typesafe Config directly, JSON in env vars is far from standard. But you can always turn that env var manually into a ConfigSource using ConfigSource.string(...) and combine it with the default source. See https://pureconfig.github.io/docs/loading-a-config.html for more details on this
Luis Miguel Mejía Suárez
@BalmungSan

JSON in env vars is far from standard

Yeah I know, but I am stuck with AWS ECS not providing a good way to access Secrets Manager.
Rant over, sorry.

But you can always turn that env var manually into a ConfigSource

Aha!
Let me try that!
Thanks!

Luis Miguel Mejía Suárez
@BalmungSan
@ruippeixotog it worked like a charm! Thank you very much!
Rui Gonçalves
@ruippeixotog
np :)
Luis Miguel Mejía Suárez
@BalmungSan

Yeah I know, but I am stuck with AWS ECS not providing a good way to access Secrets Manager.

On a funny note, AWS released just today the ability to inject each individual secret as its own env variable.
Not sure if I should laugh or cry

Jason Pickens
@steinybot
What is the best way to read a config where there are 2 fields where exactly one must be given?
Jason Pickens
@steinybot
I could create a second case class with those fields as Option[String] then use emap to map it to the real case class where the field is Either[Foo, Bar]
Jason Pickens
@steinybot
Worked pretty well with https://github.com/scalalandio/chimney
Gunnar Lilleaasen
@heksesang
Is it possible to use environment variables in a YAML config when using pureconfig-yaml to parse it?
Leif Wickland
@leifwickland
@heksesang I believe it's possible. You'd combine the ConfigSource.systemProperties with a fallback to the ConfigSource for the YAML.
machinesleet
@machinesleet
Hi Everyone, is there a simple way of using Xlint and allowing the pureconfig. & pureconfig.generic.auto. imports to be allowed? I've had a dig through the build.sbt file and it seems like there's different options for test and compile, which I'm not sure I need...
Edmondo Porcu
@edmondo1984
Hello everyone, is there a way to parse a map as Map.empty if the field is not available in the hocon config?
Leif Wickland
@leifwickland

@edmondo1984
There are two approaches I'd consider:

  • Define the field as Option[Map[K,V]].
  • Provide a default argument of Map.empty in the case class that receives the config.

I think either would work. Please let me know how it goes.

Aditya Prasad
@monktastic
I'm having trouble getting Enumeratum working in HOCON. I followed the instructions to a tee, but am getting `Expected type OBJECT. Found STRING instead'. Known issue, or am I doing something stupid probably?
Leif Wickland
@leifwickland

@monktastic Are you using the pureconfig-enumeratum module to create the ConfigReader for your ADT?
I'd expect that if you were, the it should work automagically.

Have you taken a look at the unit tests for that module?
https://github.com/pureconfig/pureconfig/blob/master/modules/enumeratum/src/test/scala/pureconfig/module/enumeratum/EnumeratumConvertTest.scala
The only thing to remember when looking at that test is that it implicitly is importing pureconfig.module.enumeratum._

If those suggestions don't help you solve the problem, please create a minimal git repo to reproduce the problem and post it here.

Aditya Prasad
@monktastic
Oh hmm I don't think I saw that on the README. I'll give that a try later, as I've already backed out all enumeratum-related changes since I couldn't get them working. Thanks!
Ah yeah there it is, sorry I missed it. BTW the link from the julienrf enum page points at your old repo.
Leif Wickland
@leifwickland

@monktastic
You said "the link from the julienrf enum page points at your old repo."

Where specifically is the link that you're talking about?

Aditya Prasad
@monktastic