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
Feature: config-directory.d/ pattern support #324
Comments
On one hand, I'm a fan of this design in Ubuntu and Debian. The ".d" pattern makes automation easier, because it's easier to automate adding or removing a file or directory then it is to automate opening a file, parsing it, and adding or removing a line or or some configuration from it. Also in favor of this, my own configuration file is getting huge and simply breaking it up logically would make it more manageable and error prone. On the other hand, A next step is considering the proposal can be write out a detailed spec for how the proposed change would be implemented in our config logic. It would clarify things like:
|
Here's a simple solution to managing complex configurations: In your config .js files:
This pattern of including configs from other configs is used by nginx and others, and allows arbitrary flexibility and complexity. Better yet, it's available today without modifications to node-config. |
@lorenwest that was the option I was planning to use. However, the I don't personally have a need to automate adding file to my I imagine the people managing OTP configs with automation like this is currently very small. This issue is the first I've we've heard a user mention the idea. |
This may be a candidate for supporting module. Something like this in your var thisConfig = module.exports = {
...
}
require('extended-config').extend(thisConfig, './conf.d') |
Interesting idea. Hand the config file parsing and merging over to another On Tue, May 24, 2016 at 2:16 PM, Loren West notifications@github.com
|
@markstos with regards to the spec, honestly, I would go for the 20% effort that generates 80% of the value. I would take the currently defined significant names, and if .d exists I would process all the files inside with a valid [ext] as currently defined in the spec. This would build on top of what is already there, would be easy to specify and easy to maintain going forward if/when new significant names appear. I would not implement recursive .d directories, without having thought much about first impression is that might be on the over-engineering side. May be I am wrong. That would be a great starting point. |
There have been no follow-ups here in two years, so I'm closing this in favor or #561 now. This is issue can be re-opened if there is sustained interest. |
sorry for the late reply. But the idea is to follow the config.d pattern that we see in linux. where all files in a directory are agreegated to form a configuration file, without any pre-requisite for naming appart of the extension. This allows for better scripting when using tools such as ansible or puppet. For example, a puppet script might add logging.yml to conf.d directory setting exclusively the configuration for wiston settings which all my node services use, however other services may serve http (but not all) and a file http.yml can be produced on many of those. The problem that I see with #561, is that it simply changes the config directory or adds more, but the filenames are predefined as hostname.yml, env.yml, etc. which does not really implement the conf.d pattnern. many that implement the conf.d pattnern use a configuration directive like the following: dnsmasq.conf making it more explicit. Whith the current implamentation tools like ansible and puppet are forced to handle "fragments" of configuration files which makes it difficlut to abstract in multiple modules. |
@rvalle how do you see the resolution order in case of a mix between the two methods?
Or are we talking only about this part:
I'm assuming that within the directory file order will be determined alpha-numerically and according to the existing extension resolution order.. |
As a user of Ubuntu and Ansible, I do appreciate the "conf.d" pattern for automation. I presume we would support it throughout all layers if we support, as @iMoses first option illustrates. I guess since we only |
I could see how that would work and be useful. It could be a (custom) parser for |
@lorenwest That's a great idea! We'll have to adjust If we'll embrace the parser mechanism more, we can add pre and post processors support. Pre-processors would handle reading directories or ignoring We can think of it as middleware, allowing multiple such handlers to be registered. |
@iMoses That sounds like a pattern that could be used to address various "secret storage" schemes. I like the idea of handling ".d" through a custom parser. |
@markstos I wonder if there's another medium in which we can discuss in more details some ideas I had in mind.. I've been playing with some code and have something that on one hand would definitely be a breaking change, and on the other it's the smallest breaking change that would only effect users who relay on mutability and access the config object without the By moving the config object itself into a separate property we can initialize and freeze the entire object only on first access, solving most if not all of the immutability related issues, simplify the library to 10th of it's current size and improve modulation to enable multiple instances, code initialization instead of relaying on env-vars and many more requested features.. |
@iMoses We could use a direct three-way email with myself and Loren if you prefer. I'll say I am someone who uses the feature that the object remains mutable until the first call to For example, you want test both states of a boolean configuration. If you want to test configurations that already expressed in alternate config files, there are config-reloading modules for that already: https://w ww.npmjs.com/package/config-reloadable |
@markstos My suggestion actively makes the object private until created and frozen, but the intention is to provide all the methods you require on top of the Config instance, so you'll be able to influence anything you require before it is created. With pre and post processors I believe you can do anything and in a organized and simple manner. Consider this: function Config(options) {
let autoload = true;
const config = {};
this.loadFiles = options => {
loadFiles(config, options);
autoload = false;
return this;
};
Object.defineProperty(this, 'config', {
configurable: true,
get: () => {
if (autoload) {
loadFiles(config, options);
}
resolveDeferred(config);
utils.freezeProperty(this, 'config', config);
return this.config;
},
});
} |
As long as there is still some option to mutate the config before it's frozen, I could potentially support a refactor. |
I have interest in this feature. I would like to use it as a way to add a directory containing security group descriptions. |
Hi!
As we have seeing with many Unix packages sometimes configuration files grow complex, long and difficult to handle.
Many projects out there support the following pattern: one big config file, or one directory with many configuration fragments.
For example, one can configure the popular APT tool by editing apt.conf, or by adding a configuration fragment as a file into the directory apt.conf.d
I think this pattern is very good on multiple scenarios. When files grow big and also when configuration is automated with tools like puppet, in which a configured role might handle only some configuration aspects of a package.
so, it would be great to be able to do something like:
Or similar...
I would like to suggest to add this or similar functionality to the conf roadmap.
The text was updated successfully, but these errors were encountered: