aspnet / Configuration

[Archived] Interfaces and providers for accessing configuration files. Project moved to https://github.com/aspnet/Extensions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JsonConfigurationFileParser made public and extendable

timdoke opened this issue · comments

Hi.. I would like to make some changes to the JsonConfigurationFileParser class. In particular, making it more extendable. Currently, all the things that do logic here are private. I have a need to do a configuration parser that integrates with aws's KMS, and the only way I can currently do that is by making a new implementation. In particular, I would like the Parse and VisitPrimitive methods to be overridable so that I can provide a custom string decryption when I detect a string that has some magic text that I determine to be encrypted. By necessity, this type of change would also require that JsonConfigurationProvider be changeable. I wanted to make sure this type of change is acceptable before I submit a pull request.. Unless, it is already on the roadmap. Thanks!

Hey @danroth27, any thoughts on this?

@danroth27 any idea how long it'll take before I get a reply here? I'm trying to contribute....

@timdoke I don't think we should do this before we get around to doing #662 first. @HaoK Thoughts?

That's interesting that you want to abstract the source of the configuration first.. We are actually planning on using https://github.com/SteeltoeOSS/Configuration in addition to KMS decryption in a few months..

Yeah I figure #662 will result in something like a StreamConfigurationProvider base provider, which you can add via files or streams, and then hook up the appropriate processing for the stream to load the stream data... I haven't spent anytime thinking about this really, but maybe it would look something like:

   interface IConfigurationStreamReader {
       // Reads data from the stream and calls Set on the provider with config key/values
       void Read(IConfigurationProvider provider, Stream stream);
   }

   configBuilder.AddJsonStream("foo.json", reloadOnChange: true)
   // Which is really something like this:
   configBuilder.AddStream<JsonStreamReader>(OpenFileStream("foo.json"), reloadOnChange: true);

@HaoK I like the direction you are going with on the IConfigurationStreamReader.. Hopefully what I had to do will be easier in the future -- make a new implementation for the extension method, configuration source, configuration provider, configuration file parser just to be able to provide a decryption method for a json string or encrypted json file.

Basically, I'm hoping that we can plug in different implementations from the extension method to the configuration file parser without having to rewrite it all -- I think that would require more than just an IConfigurationStreamReader.

One suggestion I have to the above, would be some sort of pre (for encrypted config files) or post parse (for encrypted json strings) and pre binding to the actual configuration objects (parse the json object then set the value to unencrypted)..

Thanks!

So for something like an encrypted provider I think you'd just implement your own stream reader that derives from the Json one and wrap Read by decrypting the stream before calling base.

Yeah, I guess my point was it would be nice if that sort of injection/modification could happen in the startup class instead of four levels deep. But, if it's on the configuration builder, then that's great..

I can close this, @HaoK , if you think I'm just duplicating requests from elsewhere.. Thanks!

Cool yeah you can follow #662 for tracking this issue