Giter Club home page Giter Club logo

batconf's People

Contributors

lundybernard avatar tomato-gits avatar

Stargazers

 avatar

Watchers

 avatar  avatar

batconf's Issues

remove module/path args

Remove the path and mod arguments from the Configuration, and source .get methods. These should not be necessary, and we should be able to rely on the name argument to .get() being either a single key on that config object, or a dot-separated module path to the key.

sub-module config env_name path missing BAT_ prefix

When you have a sub_config

conf = get_config(GlobalConfig)
sub_config = conf.my_module
print(sub_config.item)

We expect the ENV path for an item to be BAT_MY_MODULE_ITEM
however, batconf.sources.env.py: EnvConfig currently looks for MY_MODULE_ITEM

We should also handle sub-modules recursively, for instance
conf.my_module.sub_module.item should lookup BAT_MY_MODULE_SUB_MODULE_ITEM
whether regardless of which config we look it up from:

conf = get_config(GlobalConfig)
print(conf.mod_config.sub_mod_config.item)
mod_config = conf.my_module
print(mod_config.sub_mod_config.item)
sub_mod_config = mod_config.sub_module
print(sub_mod_config.item)

should all lookup the same ENV variable

Add credential store source

Add a new source that can search a credential store, or config database.

Motivating Example:

  • An application may need to access multiple systems using similar credentials (authentication tokens), or one system using multiple users.
  • Users probably want to store credentials in a secure, encrypted, service built for the purpose, and pull creds from there, we need an example of this pattern.
  • we may want to store multiple configurations for a module in a database or flat-file, and use multiple variations of the same config at runtime.

Example:

the file source Already allows multiple configs at the top-level by setting its config_env parameter. We want a similar mechanism to select a sub-config at runtime.

Related to: lundybernard/project_template/issues/4

implement __str__ for manager.Configuration object

Provide a helpful concise representation of the configuration object

It should represent the attribute tree, the value that will be returned, and source of each value
ex:

GlobalConfig
├─ submodule1
│ └─ key1: ENV -> 'value-from-env'
│ └─ key2: config.yaml -> 'value from config file'
│ └─ key3: default -> None
├─ submodule2
│ └─ key4: ARGS -> 'value from ARGS' 

Handle falsey return values from sources

if value := source.get(key, path):

Currently, if a source returns a falsey value (False, None, 0, etc.) it will be ignored, and we will continue on to the next source. Falsey values can be valid configuration options, so we need to distinguish a valid None value in a config from a value Not Found None.

Test Cases:

  • Yaml File sources should be able to set boolean False and None values.
  • Default True values should be over-written by False values that are set in a higher priority source

missing config file causes exception

When a FileConfig source is included in the Configuration source_list, but a file is not provided by the user, or found during FileConfig.init, looking up an attribute throws the following error.

  File "/venv/lib/python3.9/site-packages/batconf/manager.py", line 42, in __getattr__
    return self._get_config_opt(name, self._mod_)
  File "/venv/lib/python3.9/site-packages/batconf/manager.py", line 45, in _get_config_opt
    if value := self._config_sources.get(key, path=path):
  File "/venv/lib/python3.9/site-packages/batconf/source.py", line 17, in get
    if value := source.get(key, path):
  File "/venv/lib/python3.9/site-packages/batconf/sources/file.py", line 38, in get
    if not (conf := conf.get(k)):
AttributeError: 'str' object has no attribute 'get'

FIX: missing keys in the config file should return None, not raise an AttributeError. If the file is missing all FileConfig.get should always return None

implement __repr__ for manager.Configuration object

provide a helpful string representation of the Configuration object

Since repr should be used for debugging and unambiguous, it should display all the sources, and all of the attribute: value pairs that we know of from those sources. This can probably be accomplished fairly easily by printing the dict values of the configuration and sources recursively

ex:

<batconf.manager.Configuration object at 0x7f2c3e68e8f0>: {
    _config_class: '__main__.GlobalConfig'
    _config_sources: [
         <batconf.sources.dataclass.DataclassConfig at 0x7f2c3e68cfa0>: {
             '_root': '__main__',
             '_data': {
                 'key': 'value', 
                 'key2': None
             }
        },
    ]
}


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.