Code Monkey home page Code Monkey logo

confizzo's Introduction

FOSSA Status codecov

confizzo

confizzo is a configuration management library. It is designed to contain many versions of configuration managed approaches into a single API.

Multi-file Configurations

Multifile configurations, in confizzo terms, are configurations which are partitioned into multiple files. One assumption is that when one configuration contains configuration information of another entity, that that configuration is then stored in a separate configuration file and referenced by type corresponds to filename and the name of the configuration in the file.

Specifications

Here the configuration is parsed into one or more files. When a configuration has a dependency on another object - via composition - the configuration for such objects will be stored in separate files. ALl objects of similar type - save the entry point objects, will be stored in files denoted by name the kind of class (via vase class) for which they will configure. In the 'main.yml' - the entrypoint configuration - the configurations will be

object:
  type: class_type
  conf: SOME CONFIGURATION DICTIONARY
  _dependencies_:
    - List of dependency descriptions

The list of dependency descriptions will have objects as follows

  var_name: NAME OF THE VARIABLE (COMPOSED OBJECT) THIS CONFIGURATION WILL BELONG TO
  name: NAME OF CONFIGURATION FROM THE CONF_TYPE LOCATION
  conf_type: IDENTIFIES THE KIND OF CONFIGURATION - WHERE THEY WILL BE STORED.

The _dependencies_ section is used to

  1. Help populate the configuration repository
  2. Used to identify the references to the Class that can be dynamically injected and to reference the right configuration

The pattern aimed to be used here is to

  1. Create an object from it's configuration (non-injectable objects)
  2. From _dependencies_ find the Class that will be constructed and the name (as a passable conf value) of the key used to reference that objects configuration.

Examples

Assume that we have an application called data_mover. Then for this application, running in local mode, the configuration will be stored at .data_mover at the $HOME path.

main.yml

version: 1

system_1:
  type: ClassA
  conf:
    param_1: something
    param_2: other
  _dependencies_:
    - var_name: db_conn
      name: dev_pg
      conf_type: database

database.yaml

version: 1

dev_pg:
  obj_type: PostgresDB
  user: user
  password: password
  host: 10.0.0.7
  database: root

The usage patter would be something like this: main.py

from providah.factories.package_factory import PackageFactory
from confizzo.multifile.config_manager import ConfigManager
from confizzo.multifile.parser import Parser

def main():
    ConfigManager.config_root = '~/.data_mover/config.yml'
    
    conf_key = 'ClassA' 
    config = Parser.get(conf_key)
    obj_type = config.pop('type')

    system_1 = PackageFactory.create(key=obj_type, **{'conf_key': conf_key})
    system_1.run()

system_1.py

from providah.factories.package_factory import PackageFactory
from confizzo.multifile.parser import Parser


class System1:
    def __init__(self, conf_key: str):
        self.__config = Parser.get(conf_key)
        
        dependencies = self.__config['_dependencies_']
        conf_for_db_conn_ref = [dep for dep in dependencies if dep['var_name'] == 'db_conn']
        self.__db_conn = PackageFactory.create(key=Parser.get(conf_for_db_conn_ref['type']), 
                                               **{'conf_key': conf_for_db_conn_ref['name']})

    def run(self):
        self.__db_conn.execute('SELECT 1')

postgres_db.py

from confizzo.multifile.parser import Parser


class PostgresDB:
    
    def __init__(self, conf_key: str):
        # Configuration contains secrets, so we don't want to expose this except when executing a query.
        self.__config_name = conf_key 

    def execute(self, query: str) -> None:
        conf = Parser.get(self.__config_name)['conf']
        conn = self.__get_connection(conf)

        conn.cursor.execute(query)
        conn.close()

    def __get_connection(self, conf: str) -> Connection:
        pass

TODO

There are a number of feature that could be added

  1. Simpler reference of dependencies from configuration using library and avoiding bespoke solution and
  2. Additional filtering when referencing configurations
  3. Additional configuration that ties to providah package (maybe)

confizzo's People

Contributors

snoodleboot avatar

Watchers

James Cloos avatar  avatar Rama Balam avatar Srini Jamched avatar

Forkers

snoodleboot

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.