Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 12:42
    lciolecki commented #122
  • 12:35
    lciolecki commented #122
  • Mar 28 19:33
    havocp commented #675
  • Mar 28 19:33

    havocp on master

    added go port to the README Merge pull request #675 from gu… (compare)

  • Mar 28 19:33
    havocp closed #675
  • Mar 28 18:37
    gurkankaymak opened #675
  • Mar 27 07:16
    AnirudhVyas closed #674
  • Mar 16 16:47
    AnirudhVyas edited #674
  • Mar 16 16:47
    AnirudhVyas opened #674
  • Mar 13 19:00
    hemantpandey17 edited #673
  • Mar 13 17:59
    hemantpandey17 opened #673
  • Feb 28 09:41
    joe-mojo commented #122
  • Feb 27 18:14
    davidmickev closed #672
  • Feb 27 18:14
    davidmickev commented #672
  • Feb 27 13:25
    davidmickev edited #672
  • Feb 27 13:25
    davidmickev opened #672
  • Feb 24 11:27
    hallyhaa commented #670
  • Feb 23 01:02
    yolii opened #671
  • Feb 21 16:25
    havocp commented #670
  • Feb 21 16:12
    hallyhaa opened #670
Havoc Pennington
@havocp
see examples app and library in the git repo
bbaldino
@bbaldino
ok, and for a lib that didn't have a central initialization point, say, we'd be left with calling load() on its own or some other technique to make the already-created config object available i assume
just wondering if there's something commonly done there
Havoc Pennington
@havocp
the ideal is that any object or function that uses config settings has an overload or variation that lets you pass a Config in, because that enables the application using the library to use something other than ConfigFactory.load(); but default to load() so if they stick to the defaults, they don't have to pass a Config around. The reasonConfigFactory.load() has no parameters (and returns a singleton) is so that it can be called many times from many places and always return the same result, so it's a safe default.
that's what the examples suggest. I'm not sure how many libraries "in the wild" actually do this.
there's deliberately not an init call like ConfigFactory.setDefault(something) because the problem is that you'd have to be sure it was called before anyone tried to use any config, which is sort of a nightmare.
bbaldino
@bbaldino
thanks...yeah i'm sort of running into that myself at the next layer up: trying to figure out how to instantiate config and then make it available to our libraries used as part of the application (which have no central entry point). we used to use osgi to provide config, but it's a pain having to retrieve that service everywhere so i went with a central class which can be accessed statically to get config, but that has the annoyance you mentioned: making sure it gets initialized in time. i currently do that statically as well, but that has its own issues.
bbaldino
@bbaldino
is there a way to parse only the system properties? (i.e. not any config files on the classpath)
bbaldino
@bbaldino
i hacked something to filter based on origin description, but wondering if maybe there's a cleaner way
Eric K Richardson
@ekrich
Looks like ConfigFactory.defaultOverrides() will give you system properties as a Config.
bbaldino
@bbaldino
ah, great!
Eric K Richardson
@ekrich
or ConfigFactory.systemProperties() is more direct. Hope this helps.
bbaldino
@bbaldino
ugh, how did i miss that. thanks @ekrich
Eric K Richardson
@ekrich
No worries, I just have the code open for the cross platform version and just took a peek knowing that it could be done - but not how :smile:
bbaldino
@bbaldino
For ease-of-use during development we've been deploying bundled jars so we only have to copy one file to a dev server instead of all of them. We've run into an issue with conflicting reference.conf files, as both a library we use has one and the application, but they're both in resources/reference.conf so only the last one ends up in the final fat jar. Is there a strategy we could use here to load both correctly? I tried nesting the lib's reference.conf but found that the class loader only looks for the file at one exact path when using ConfigFactory.load()
bbaldino
@bbaldino
Ah, I've just found that perhaps this is problem on the bundling side (just found https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#AppendingTransformer), so I'll look into that.
Edgar Orendain
@orendain
I remember reading a while back that optional environment variable defintions can not belong in reference.conf. Was there any validity to this? Will environment variables at runtime be picked up by configs that use them in reference.conf?
nafg
@nafg
@orendain where does it say that? I do it
Gerry Fletcher
@gerryfletch
I'm dealing with a pretty weird issue. I am using ConfigFactory.load() in a couple of places, and it works when running the application. but during a Scalatest run, it will work for usage within the context of a test (i.e a compiled test-class), but not for application code. The error is that com.typesafe.config.ConfigException$Missing: merge of system properties,reference.conf @ jar:file:ssl-config-core!/reference.conf doesn't hold the configuration setting I'm looking for. I'm not entirely sure why it is looking inside ssl-config-core...
Even weirder, it works fine running on JDK8, but has this issue on JDK11...
Havoc Pennington
@havocp
it loads all reference.conf and application.conf on the classpath, and for the two jdks and your test/prod setups the classpath contents must differ. Exactly why they differ I don’t know. Using the -Dconfig.trace option (described in readme) may help debug.
Gerry Fletcher
@gerryfletch
@havocp Thanks, I used the -Dconfig.trace=loads option last night and found that when the test-class loads the config, it uses an sbt.internal.LayeredClassLoader, and when the class under test loads the config, it uses java.net.URLClassLoader
That appears to be the only differences. I logged the classpath URLs in both instances and they are identical. It is impossible for them to be referencing a separate resource. There are some recent issues pointing to something similar, however: sbt/sbt#5410
So perhaps I have stumbled upon the same issue :/
Mikhail Nemenko
@eniqen
Hi there, how can I override exceptions log information with custom logback format ?
Mikhail Nemenko
@eniqen
How can I use typesafe config with my logback config
Yannick Schinko
@BrainStone
How can I set comments through code?
Havoc Pennington
@havocp
if you’re trying to edit files you’ll probably need to improve the API e.g. lightbend/config#300
Yannick Schinko
@BrainStone
Well I'm trying to make sure some config nodes have the appropriate comments
Through code
Havoc Pennington
@havocp
value.withOrigin(value.origin().withComments()) could be enough?
sjoshi-liveperson
@sjoshi-liveperson
Suppose I host config file on external url. Once I make updates to the configuration file hosted on that external url, do I need to invoke any api on this library for this to pick up the latest changes? or does this library keeps on syncing with the source url every fixed time interval.
Havoc Pennington
@havocp
no, there's no IO behind the scenes. Once you load a Config it's immutable
sjoshi-liveperson
@sjoshi-liveperson
Thank you @havocp
Then I will need to update the process which is loading the config for my application to re-load every few minutes, to pick up the latest changes?
Havoc Pennington
@havocp
yes and you have to pass a new Config object down to all code that needs it
sjoshi-liveperson
@sjoshi-liveperson
thank you for the confirmation
Yannick Schinko
@BrainStone
@havocp that worked. Thank you.#
Thinking about it. Why haven't I asked this before...
Is there a better way to achieve that? AuraDevelopmentTeam/BungeeChat2@9268c0a
David Mickevicius
@mythirdtry_twitter
Hello everyone! I was wondering, can you insert a key value at a string path at runtime, or replace it temporarily with some type of user input. For example, if my config contains conf {
classname = "DesignName"
interface = "InterfaceName"
combined = ${conf.classname} ${conf.interface} "string1"
} is there any way to say conf.classname = (something i want to set it to) during runtime?
David Mickevicius
@mythirdtry_twitter

To paraphrase better,. Does anyone contain knowledge about how to substitute a value at a key inside of a .conf file at run time.

For example, if i have a configuration file ( config.conf ) that specifies

foo{

default = "hello"

string = "world"

concat = ${foo.default} ${foo.string}

}

Config defaultConfig = Configs.ConfigType("config.conf")
defaultConfig.getString("foo.concat")
This would normally output "helloworld"

Is there any way to change this behavior at run time with some type of operation of,

defaultConfig.atKey("string"). [ Hypothetical code ] setKey("person");
Which would then output "helloperson"

I read through https://github.com/lightbend/config/blob/master/HOCON.md a couple times and don't see a good way to approach this.

If anyone has any tips they would be greatly appreciated.

Havoc Pennington
@havocp
so a Config can be resolved or not. If resolved, the ${foo.default} type of expressions are gone and no longer in the data structure. If not resolved, you can use config.withFallback(configWithTheValuesToResolveAgainst).resolve() to swap out ${foo.default}. the config must be resolved prior to use.
David Mickevicius
@mythirdtry_twitter
Thanks for the quick response! I saw that i could use fallback but i'm attempting to replace a specific key value pair upon user input which would be found within the fallback file lets say like a new name. or something like (append) a new name as a value for a given key. such that either in the example above the defaultconfig.atkey("my key string") could be replaced by Scanner in = new scanner(); and then send that scanned in string into the place of the key.
Havoc Pennington
@havocp
there's no way to ever modify a Config, it's immutable, but you can of course make a new Config with anything changed. If you want to use the ${} mechanism it has to be an unresolved config
David Mickevicius
@mythirdtry_twitter
Awesome, thanks so much for the quick responses.
Hemant Pandey
@hemantpandey17

Hello Lightbend community,

I have been trying to convert my config file into an object of a Java POJO class.
The config file is a HOCON file :

{
"records": [
{
firstName= "Hemant"
lastName="Pandey"
Age=25
},
{
firstName= "Vaashu"
lastName="Sharma"
Age=24
}
]
}

The POJO class too has same members as firstname, lastName and Age.
Any better way to do this ?

I tried getting a configList which creates a Java Object list.

Diego E. Alonso Blas
@diesalbla
Good morning. I have a question:
suppose I have an SBT project with two submodules, an executable fili and a library kili, such that fili is configured in SBT as .dependsOn(kili % compile -> compile; test -> test),
and kili defines some configs in the application.conf file.
Would those configs be available when running the fili application, or would I need to change that dependency?
Andrea Peruffo
@andreaTP
ideally kili should define configurations in a reference.conffile since that one get merged, the application.conf file get's overwritten if there is one in fili
Diego E. Alonso Blas
@diesalbla
Yes, kili has these configurations defined on a reference.conf file.
@andreaTP Can I infer from the response that: an application.conf file in fili would not just override the individual settings on the application.conf of kili, but suppress it altogether (as if it did not exist)
Andrea Peruffo
@andreaTP
AFAIR yep
actually all application.conf should be loaded ... https://github.com/lightbend/config#standard-behavior