Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 05 12:59
    mikehearn commented #771
  • Aug 02 06:36
    mkurz commented #769
  • Jul 19 06:03
    tangjiafu commented #769
  • Jul 13 22:35
    brandoncimino edited #772
  • Jul 13 22:35
    brandoncimino opened #772
  • Jul 11 14:30
    havocp commented #729
  • Jul 11 14:22
    aalleexxeeii commented #729
  • Jul 05 07:49
    Jonatha1983 commented #108
  • Jul 04 12:54
    havocp commented #108
  • Jul 04 07:48
    Jonatha1983 commented #108
  • Jul 01 09:37
    aumann commented #587
  • Jun 27 13:30
    k3rnL edited #771
  • Jun 27 13:29
    k3rnL opened #771
  • Jun 19 21:00
    Thermi commented #689
  • Jun 14 10:15
    baltiyskiy edited #770
  • Jun 14 09:33
    baltiyskiy edited #770
  • Jun 14 09:32
    baltiyskiy edited #770
  • Jun 14 09:32
    baltiyskiy opened #770
  • Jun 11 03:28
    jroper reopened #760
  • Jun 11 03:28
    jroper closed #760
TwoClocks
@TwoClocks
Is there a way to search for all the unresolved values, and examine them somehow before resolving them?
TwoClocks
@TwoClocks
nvm. I think I figured out something better.
TwoClocks
@TwoClocks
I'm loading a config, resolving it, and writing it back out to a file.But the resulting file has a TON of other stuff in it. It's wrapped in SimpleConfigObject which I have no idea how to unwrap. Also, the parser blows up on the resulting file. How do I just write out a config as a valid hocon file?
Havoc Pennington
@havocp
config.render, though it will not preserve or offer much control over formatting
TwoClocks
@TwoClocks
yeah. That's what I'm using. But it pre-pend this SimpleConfigObject and post-pends most of the enviroment.
Havoc Pennington
@havocp
SimpleConfigObject( etc. sounds like toString, not render
Claude Brisson
@arkanovicz
Hi. I'm sorry if this question has already been asked a zillion times, but why not have the key-value separator be also optional when it's followed by '[', as it is for '{' ? Is there an underlying technical reason?
Havoc Pennington
@havocp
I’m not actually sure it has been asked! I think it would work… in general if something is a syntax error now, it can be changed to have a valid meaning. But we’d have to try it to see what complexities arise. For that matter I wonder whether it could work to allow this for all value types or whether it creates ambiguity.
I can’t say offhand what implications it would have.
Claude Brisson
@arkanovicz
Well, I tried and the tests do pass. I can submit a PR.
Eric K Richardson
@ekrich
Do you have a before and after example so I can see? I have a port of this library for Scala Native so I like to follow the threads here. I am not an expert like @havocp
Havoc Pennington
@havocp
do you think it would work with all value types, not only arrays and objects?
also important to establish that it was previously a syntax error
would be good to look at examples and see how we all think it reads
DavidRomaoCTW
@DavidRomaoCTW
Hello everyone, I have a property that is a very long line, it is a comma separated list and I am trying to split it on multiple lines which are then concatenated , similar to what can be done in a .properties file. Is there a proper way to achieve this in HOCON ? Setting as a triple quote string does not work properly because it causes the new line characters and tabs to be part of the property key.
Havoc Pennington
@havocp
as far as I remember, no there isn’t a syntax for that.
DavidRomaoCTW
@DavidRomaoCTW

Ok thank you

as far as I remember, no there isn’t a syntax for that.

dabbibi
@dabbibi
Hi a quick question: Is it possible to resolve in Environment Variables in include headers? For example is it possible to to do something like : include required(file("${TEST_SYS_PROP}/sample.conf"))?
where TEST_SYS_PROP is an environment variable..
Havoc Pennington
@havocp
not at the moment, there are some things in the issue tracker talking about it I think that might have some ideas
raj.gollapalli
@raj.gollapalli:matrix.org
[m]

Hi, is there a recommended way to convert variables from lower case to upper and vice-versa on a HOCON configuration?

country="NL"
country_uppercase=${country/...??}

TwoClocks
@TwoClocks
I really like that a missing config value is an error. But I'm wondering if there is a way to discover the inverse: A config value that is not used by the code. In my experience, this can be just as bad as a missing config w/ a bad default. An operator set something expecting a behavior that does not exist in the code. The only way I can figure out how to do this is to wrap Config and remember which fields are accessed. Then "at the end" diff that vs all the fields that exist in the file. Does anyone have any advice on another way to do this?
bbaldino
@bbaldino
@TwoClocks I was interested in the same thing. A while back I threw something together that did this via the reflections library: it found all subclasses of a parent class (I had written a common parent class to model the config values) and I grabbed all the config path strings from those classes and compared it against the parsed root config. I later ended up getting rid of it because I changed the modeling of the config params, but it did work, and I do kinda miss having it now.
TwoClocks
@TwoClocks
@bbaldino you reflected on the code using Config or you reflected on Config to auto-generate stubs that capture path params? Sound like it cuts down on boilerplate.
bbaldino
@bbaldino
Trying to see if I can dig up that old code, but can't find it. I'm pretty sure what I did was create a ConfigValue base class, that modeled a retrieved value and also contained the path of the key used to look it up. Using reflections, I could find all the instances of those, extract the keys, and then compare it against the keys in the parsed config to see if there were any params in the config file that were never used.
bbaldino
@bbaldino
Ah, I found it. You can see the validation code here. Another feature of this I did was allowing the code to mark a property as 'deprecated' (i.e. when a key was removed or renamed) and the validation code would also log warnings if any deprecated keys were used in the config file.
I eventually ditched that model and ended up with this lib, but never re-implemented those validation features.
Graeme Ludwig
@ludwiggj

Hi, is there any way to declare a value that takes the value of the encompassing "node" e.g. if I have:

cars {
toyota {
model = "toyota"
colour = "green"
}
ford {
model = "ford"
colour = "white"
}
}

is there any way I can assign a variable for model's value, so that I don't have to repeat the values for toyota and ford?

Eric K Richardson
@ekrich
They could be car {?
cars: [] as an array it is just like json
So however you want the schema
Graeme Ludwig
@ludwiggj

Sorry, not sure I understand. I was aiming for something like:
cars {
toyota {
model = "$parent" // automatically set to "toyota"
colour = "green"
}
ford {
model = "$parent" // automatically set to "ford"
colour = "white"
}
}

I read the github page and don't think this kind of substitution exists, but thought I'd ask in case I'd missed something.

bbaldino
@bbaldino
what about omitting the model entirely and using the key name, or change the structure to something like:
cars : [
    {
        model = "toyota"
        colour = "green"
    },
    {
        model = "ford"
        colour = "white"
    }
]
Graeme Ludwig
@ludwiggj
I don't think that would work, as each car is referenced elsewhere in the config e.g.
person {
  name = "Graeme"
  favouriteCar = ${cars.toyota}
}
bbaldino
@bbaldino
ah. i think you may be stuck with repeating the model then. i've had situations with this in the past, but have been able to use the key name instead (i.e. omitting 'model' here), but i wasn't referring to them within the config itself.
(btw "toyota" and "ford" are referred to as the make of the car :) model would be "corolla" or "mustang")
Graeme Ludwig
@ludwiggj
ok, cool, thanks for the help all!
btw, what do you mean by the key name?
bbaldino
@bbaldino

If you have:

cars {
  toyota {
    model = "$parent" // automatically set to "toyota"
    colour = "green"
  }
  ford {
    model = "$parent" // automatically set to "ford"
    colour = "white"
  }
}

then you could parse cars as a ConfigObject (i think it is) and get the keys within it (toyota, ford), then parse the objects associated with the keys

as a way to get those values without redundantly putting them inside the object
Matthew de Detrich
@mdedetrich

Quick question, is it possible to override entire maps with the usage of environment variables? i.e. lets say I have the following

{
  test = {
    a = apple
    b = bob
  }
  test = ${?TEST}
}

Is it possible to do something like

env "TEST.a=another" in order to override the test.a field

Havoc Pennington
@havocp
No, the env vars are not parsed as JSON, because then they’d need quoting to set simple string values.
I can’t remember whether we implemented it already but there was an idea at one point to allow an env var with json in it. Otherwise, need to create a file and merge it in.
Matthew de Detrich
@mdedetrich
Cool thanks, I might implement such a feature in the future which would work similar to how config works with lists (where you can override with . syntax)
TwoClocks
@TwoClocks

I don't think I understand how resolve works. I feel like this should work? but it doesn't :

    val cfg1 =
        ConfigFactory.parseString("path: ${'$'}{?java.io.tmpdir}")

    val cfg2 = ConfigFactory.load(cfg1)
    val thing = cfg2.getObject("path")
    thing.keys.forEach {
        println("--")
        println("$it - ${thing[it]}")
    }

outputs :
separator - Quoted(":")

so the first question is, why did it decide to make it an object, and not a string? the second is, where is /tmp ?
TwoClocks
@TwoClocks
Yes. I was correct. I did (do?) not understand how resolve works. This works fine though :
val cfg1 = ConfigFactory.parseString("fofo: ${'$'}{?java.io.tmpdir}")
val cfg2 = cfg1.resolveWith(ConfigFactory.systemProperties())
val thing = cfg2.getString("fofo")
println(thing)
prasanthKK1996
@prasanthKK1996

Hi,

We are using light bend config to get the hocon configurations. We have multiple files with configurations for several entities. Parsing all these configuration files takes time in minutes. Consequently, the configuration load time is also high.

We are looking for opportunities to improve the configuration load time. As one possible strategy, we are looking into parsing the configurations once and serializing the constructed config object.

Are there any existing approaches to achieve this? Also, any other suggestions to improve the config load time are welcome. Thanks in advance!

Pepijn Knetsch
@PepijnK

Hi I'm trying to load a Map of String -> Config without loosing type information so that I can iterate the key values and configure the map like this:

clients {
  CLIENTA = {
    org = "foobar"
  },
  CLIENTB = {
    org = "catdog"
  }
}

However, Config.root() yields a Iterable Map.Entry with ConfigValue as value.
So far I've tried to work with ConfigValue but I'm unable to fetch the Config interface for type-safe reading the org value.
Things I've tried so far:

configValue.atPath(".").getString("org") // Exception
configValue.atPath("/").getString("org") // Exception
configValue.atPath("").getString("org") // Exception
configValue.atKey(".").getString("org") // Exception

I wish I could do configValue.toConfig and obtain the Config interface..
Ideas are welcome!

Pepijn Knetsch
@PepijnK
OK I totally overlooked that ConfigObject is a public sub-type of ConfigValue and that root() constructs a Map with ConfigObjects. ConfigObject has a toConfig method so there we go...