Giter VIP home page Giter VIP logo

Comments (17)

afsalthaj avatar afsalthaj commented on August 30, 2024

@jdegoes
When it comes to nested structure, should write back functionality be considering it writing back to nested structure ?

On the append and zero usage to flatten it back to map, does that consider when the value is list?

from zio-config.

afsalthaj avatar afsalthaj commented on August 30, 2024

This looks really interesting, and hopefully we can have a PR soon to discuss further.

from zio-config.

afsalthaj avatar afsalthaj commented on August 30, 2024

@jdegoes
would you mind helping us on integrating it with ConfigSource?

from zio-config.

jdegoes avatar jdegoes commented on August 30, 2024

The simplest possible modification to ConfigSource:

def getConfigValue(path: String): IO[ReadError, PropertyTree[String, String]]

Runner-up:

def getConfigValue(paths: List[String]): IO[ReadError, String]

Both have enough structure to read nested configs. The latter is a little more "elemental".

We'll have to modify some other places to support nesting when defining properties, etc.

from zio-config.

afsalthaj avatar afsalthaj commented on August 30, 2024

The only immediate issue that I could find is:
Getting a map of entire system env may go through security management exception.
while system.env(path) returning Option may still be successful.

This means forming a sys env to Property[String, string] (or even map[String, String]) can be a bit of trouble?

As of now we use zio.system.env and that works well. it either give a ReadError (fatal error/ missing value) or the actual value , given a path.

from zio-config.

afsalthaj avatar afsalthaj commented on August 30, 2024

Or is it that, an instance of PropertyTree[String, String] is valid only for 1 path?

EDIT: I got it when I had a look at the proposal in detail today. Thanks @jdegoes

from zio-config.

afsalthaj avatar afsalthaj commented on August 30, 2024

What could be a proper user interface to describe a nested config ?

A very verbose user interface, but really flexible: (A less verbose is given in next comment)

    case class Database(port: Int, dbUrl: String)
    case class Prod(ldap: String, database: Database)
 
  val config  
     (nested("auth") >~> string("ldap") |@| 
      nested("database") >~> 
       (int("PORT") |@| string("DB_URL"))(Database.apply, Database.unapply)
   )(Prod.apply, Prod.unapply)
// Given a valid hoccon source.
// Ex: 
  {
   "auth" : { "ldap" : "sample1" } 
   "database": {
        "PORT" : "sample2",
        "DB_URL": "sample3"
     }
}

val result = read(config).provide(hocconSource) === Prod(...)
write(config, result) == 

List(
   PropertyTree.Record(
      "auth", 
       Map("ldap" -> PropertyType.Leaf("sample1")),
   PropertyTree.Record(
     "database",
      Map("PORT" -> PropertyType.Leaf("sample2"), "DB_URL" -> PropertyType.Lead("sample3")
   )
)

This allows user to write a valid hoccon, that could be read by some other application expecting the hoccon source.

from zio-config.

afsalthaj avatar afsalthaj commented on August 30, 2024

An alternative approach to describing such a config is:

  string(List("auth", "ldap")) |@| (int(List("database", "PORT")) |@| string(List("database", "DB_URL")))......

// Pretty much same as   string("auth.ldap") |@| (int("database.PORT")) |@| string("database.DB_URL"))).....

In this case, Writing it back to a PropertyTree (hoccon, for instance) can turn out to be a bit fragile?

from zio-config.

afsalthaj avatar afsalthaj commented on August 30, 2024

@jdegoes What I am trying to say with the above example is, the config descriptor itself clearly indicates, we are talking about reading from something like a hoccon, yaml etc. Or in other words, only those sources will be able to provide use with proper PropertyTree(mentioned in your comment) that can serve the config descriptor. Does it make sense? It's still initial thinking for me

from zio-config.

afsalthaj avatar afsalthaj commented on August 30, 2024

In both approaches, it will be PropertyTree that's our initial structure.

from zio-config.

jdegoes avatar jdegoes commented on August 30, 2024

You need something like:

nested("foo") { /* inside here is a ConfigDescriptor */ } |@| ...

The type will be:

def nested[A](path: String)(cd: ConfigDescriptor[A]): ConfigDescriptor[A]

It will require a new case in the ConfigDescriptor enumeration.

from zio-config.

jdegoes avatar jdegoes commented on August 30, 2024

By the way, we can do nested even with flat properties.

I used to see this format all the time with Java properties:

application.settings.connectionUrl = ...
application.settings.backupUrl = ...

With environmental variables you sometimes see JAVA_ENV, JAVA_HOME, etc.

Because ConfigDescriptor is just data, we can translate the nesting into any format we want.

from zio-config.

jdegoes avatar jdegoes commented on August 30, 2024

The only immediate issue that I could find is:
Getting a map of entire system env may go through security management exception.
while system.env(path) returning Option may still be successful.

This implies ConfigSource should not support enumeration, e.g. be like:

def getConfigValue(paths: List[String]): IO[ReadError, String]

from zio-config.

afsalthaj avatar afsalthaj commented on August 30, 2024

@jdegoes
Sure. In any case, it seems we need a new node Nested in ConfigDescriptor. Is that reasonable?

from zio-config.

jdegoes avatar jdegoes commented on August 30, 2024

@afsalthaj Yes, that's a great & safe start, since we know we'll need it and what the type should be.

from zio-config.

afsalthaj avatar afsalthaj commented on August 30, 2024

Whenever program encounters Nested, it accumulates the path which is then used to go to deep into the PropertyTree, to fetch the final Leaf.

Will need to start scratching with the code now.

from zio-config.

afsalthaj avatar afsalthaj commented on August 30, 2024

Fixed in #78

from zio-config.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.