Bassa icon indicating copy to clipboard operation
Bassa copied to clipboard

Shall we avoid editing DBCon.py?

Open xlight05 opened this issue 5 years ago • 9 comments

Context

When we are configuring the database, we are encouraging people to use hard-coded values in DBCon.py.

I don't really mind hard coding values in a config file for testing purposes however it really is a bad practice to edit the code. I've done this myself and I accidentally staged DBCon.py couple of times.

I think the solution is already implemented. In the default code, we are getting values from the environment variables. I believe its correct, I think we should encourage users to use the env variables and remove editing DBCon.py in the README and Wiki pages.

Maybe we can provide a template .env file for usability. What do you think? If you agree, I can start working on this.

xlight05 avatar Mar 25 '19 22:03 xlight05

@kmehant what you say? I think it's better to make a template .env file rather making env variables/directly populating credentials.. It becomes really easy for a developer to configure a database, and hence prevent accidental staging of DBCon.py file.

hv7214 avatar Jan 31 '20 16:01 hv7214

Can we create an inheritable config system. We have config.json and user.config.json. We will commit config.json and not commit user config. We can put default values there in config.json.

When loading the config we load both and merge in a way user.config.json overrides config.json data.

If we do .ini or .yml We can also have comments 😀

--

Then we create a config class to handle all this. Have every other class create and use configs or use a method like cfg["config"] (using __getitem__)

JaDogg avatar Jan 31 '20 20:01 JaDogg

@JaDogg it seems a great idea to go, though i have a lil'bit different approach. We can have a config.example.json, which should be treated as a template file. User has to duplicate this file as config.json (leading to two files: config.json and config.example.json). So data will be loaded directly from config.json file. No merging stuff. And config.json will be added to .gitignore, so no headache of staging.

hv7214 avatar Feb 01 '20 17:02 hv7214

We can simply use ChainMap for merging and some custom code to handle nested merging. We can use .yml and include comments and examples in the same config. Example config is OK as well for Bassa.

Currently I'm not sure if it is possible to just run Docker to get stuff working. If I remember correctly we need to set some environment variables. @kmehant knows I think

JaDogg avatar Feb 01 '20 20:02 JaDogg

as much i know env variables are used for database config.

hv7214 avatar Feb 02 '20 10:02 hv7214

We can simply use ChainMap for merging and some custom code to handle nested merging. We can use .yml and include comments and examples in the same config. Example config is OK as well for Bassa.

Currently I'm not sure if it is possible to just run Docker to get stuff working. If I remember correctly we need to set some environment variables. @kmehant knows I think

Yup no need to set environment variables in the case of container setup as we have mocked all of them using docker-compose tool

kmehant avatar Feb 02 '20 10:02 kmehant

@JaDogg so should i just go with your idea or mine one.

hv7214 avatar Feb 03 '20 13:02 hv7214

@hv7214 as far as i know using .env can create in problems in the travis builds too so a solution without the use of .env files seems more appropriate.Also I think your use of sample config.json is fine. 👍

carpecodeum avatar Feb 03 '20 15:02 carpecodeum

Either way is fine as long as we have good enough defaults for testing/dev somewhere. :)

JaDogg avatar Feb 03 '20 15:02 JaDogg