www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why don't we write configuration files in D instead of JSON?

reply Guido <guido mailinator.org> writes:
It would seem that by running the file through mixin, you can 
simply create the vars you want in scope. The drawback being 
random code execution. Is there any way to sanitize mixin code 
from user-configurable file?

Once that's shot down, does anyone know a .json to .sdl converter 
program
Jun 15 2016
next sibling parent reply Seb <seb wilzba.ch> writes:
On Thursday, 16 June 2016 at 05:31:26 UTC, Guido wrote:
 It would seem that by running the file through mixin, you can 
 simply create the vars you want in scope. The drawback being 
 random code execution. Is there any way to sanitize mixin code 
 from user-configurable file?
Well it's a configuration file that e.g. the registry has to parse too, hence (as for all config files) random code execution is pretty bad. Apart from that it's just about a small configuration file for the name, title etc. - you don't need a full-blown D interpreter for this. Imho SDL does a good job at keeping the syntax rather minimal :) Of course do one stops you to use D to generate a configuration file.
 Once that's shot down, does anyone know a .json to .sdl 
 converter program
have a look at `dub convert` - in your case e.g. `dub convert -f sdl`
Jun 15 2016
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2016-06-16 08:07, Seb wrote:

 Well it's a configuration file that e.g. the registry has to parse too,
 hence (as for all config files) random code execution is pretty bad.
If one had to explicitly upload Dub packages via a Dub command instead of pushing a tag to the git repository, the D code could be compiled to a JSON format on the client side when building the package. I like that approach for other reasons as well: * No dependency on a code repository * Maybe I don't want all my tags to be accessible in the registry * Not requirement to use Git (not really a problem for me) -- /Jacob Carlborg
Jun 15 2016
prev sibling next sibling parent reply Guido <guido mailinator.org> writes:
On Thursday, 16 June 2016 at 06:07:55 UTC, Seb wrote:
 On Thursday, 16 June 2016 at 05:31:26 UTC, Guido wrote:
 It would seem that by running the file through mixin, you can 
 simply create the vars you want in scope. The drawback being 
 random code execution. Is there any way to sanitize mixin code 
 from user-configurable file?
Well it's a configuration file that e.g. the registry has to parse too, hence (as for all config files) random code execution is pretty bad. Apart from that it's just about a small configuration file for the name, title etc. - you don't need a full-blown D interpreter for this. Imho SDL does a good job at keeping the syntax rather minimal :) Of course do one stops you to use D to generate a configuration file.
 Once that's shot down, does anyone know a .json to .sdl 
 converter program
have a look at `dub convert` - in your case e.g. `dub convert -f sdl`
Thanks for the answer. I conceptually like SDL better than JSON. We'll see how I like it in practice. I went looking for examples of SDL online and found that even the SDlang-D project is using a dub.json configuration file. How weird is that? Also, LOL Ketmar.
Jun 16 2016
parent Seb <seb wilzba.ch> writes:
On Thursday, 16 June 2016 at 13:20:06 UTC, Guido wrote:
 On Thursday, 16 June 2016 at 06:07:55 UTC, Seb wrote:
 On Thursday, 16 June 2016 at 05:31:26 UTC, Guido wrote:
 It would seem that by running the file through mixin, you can 
 simply create the vars you want in scope. The drawback being 
 random code execution. Is there any way to sanitize mixin 
 code from user-configurable file?
Well it's a configuration file that e.g. the registry has to parse too, hence (as for all config files) random code execution is pretty bad. Apart from that it's just about a small configuration file for the name, title etc. - you don't need a full-blown D interpreter for this. Imho SDL does a good job at keeping the syntax rather minimal :) Of course do one stops you to use D to generate a configuration file.
 Once that's shot down, does anyone know a .json to .sdl 
 converter program
have a look at `dub convert` - in your case e.g. `dub convert -f sdl`
Thanks for the answer. I conceptually like SDL better than JSON. We'll see how I like it in practice. I went looking for examples of SDL online and found that even the SDlang-D project is using a dub.json configuration file. How weird is that? Also, LOL Ketmar.
Well fib initially started with Json, then wanted to switch to sdl, but never made the move. See this issue for some details: https://github.com/dlang/dub/issues/789 I think the only problem with sdl is that it's rather unknown and a _popular_ human-readable format like toml or yaml would have been a better choice.
Jun 16 2016
prev sibling parent Guido <guido mailinator.org> writes:
 have a look at  `dub convert` - in your case e.g. `dub convert 
 -f sdl`
This dub convert command is weird. It works as `cat dub.json | dub convert -sdl' and makes a nice SDL file called dub.sdl, but it blows away the source file, which I've never seen before with piped output from cat. I don't like deleting the source file being the default behavior. Also, commands like `dub convert -f sdl dub.json' and variations of that sort don't seem to work as a command. They have errors. What's the weirdness here?
Jun 16 2016
prev sibling parent ketmar <ketmar ketmar.no-ip.org> writes:
On Thursday, 16 June 2016 at 05:31:26 UTC, Guido wrote:
 Is there any way to sanitize mixin code from user-configurable 
 file?
yes. read json file and convert it to anything you want. ;-)
Jun 16 2016