Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config report doesn't connect name-adjusted keys together #153

Open
Daenyth opened this issue Jul 25, 2023 · 0 comments
Open

Config report doesn't connect name-adjusted keys together #153

Daenyth opened this issue Jul 25, 2023 · 0 comments

Comments

@Daenyth
Copy link

Daenyth commented Jul 25, 2023

For example:

  val port = ConfigDef.getOrUse[Port]("server.port", port"8085")
  def configSources[F[_]: Applicative]: ConfigSources[F] = {
    // Allow property names like `foo.bar` to map to environment variables like `FOO_BAR`
    // Taken from https://github.com/japgolly/clear-config/issues/132
    def propertyToEnv(k: ConfigKey): List[ConfigKey] =
      k :: k.map(_.toUpperCase.replace('.', '_')) :: Nil

    ConfigSource.environment[F].mapKeyQueries(propertyToEnv) >
      ConfigSource.propFile[F]("deploy.properties", optional = true)
      ConfigSource.system[F]
  }
  
  def readConfig[F[_]: MonadThrow](log: Logger[F]): F[MainConfig] =
    config.withReport
      .run(configSources[F])
      .flatMap(_.toEither.leftMap(e => new Exception(e) with NoStackTrace {}).liftTo[F])
      .flatMap { case (cfg, report) =>
        // Don't bother reporting unused environment variables, or "system" settings
        val reportMessage = report
          .mapUnused(_.withoutSources(ConfigSourceName.environment, ConfigSourceName.system))
          .full

        log
          .info(reportMessage)
          .as(cfg)
      }

Results in a config report like this:

Used keys (5):
+-----------------+------+-----------------------------------------------------------------+---------+
| Key             | Env  | /Users/gavin/blahblah/blahblahblahblahblah/local-dev.properties | Default |
+-----------------+------+-----------------------------------------------------------------+---------+
| SERVER_PORT     | 8089 |                                                                 |         |
| server.port     |      |                                                                 | 8085    |
+-----------------+------+-----------------------------------------------------------------+---------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant