Beispiel #1
0
def get_app_config(app_name: str) -> dict:
    """Load the configuration of an app"""
    app_config_path = os.path.join(
        Configuration.get_config_path(),
        Configuration.get_config_app_folder(),
        f"{app_name}.yaml",
    )
    if not io.exists(app_config_path):
        raise AppConfigurationNotFoundError(app_name)

    app_config = io.from_yaml(app_config_path)
    environment_config = get_project_config()

    config = dict_utils.deep_merge(environment_config, app_config)

    # Awaiting for implementation
    # validate configuration using nestor-config-validator

    return _resolve_variables_deep(config)
Beispiel #2
0
def list_apps_config(config_path: str = Configuration.get_config_path()
                     ) -> dict:
    """Retrieves all of the apps configurations keyed by app names."""
    apps_path = os.path.join(config_path,
                             Configuration.get_config_app_folder())

    if not os.path.isdir(apps_path):
        raise ValueError(apps_path)

    apps_config_hashmap = {}
    for file_path in os.listdir(apps_path):
        basename = os.path.basename(file_path)
        filename = PurePath(basename)
        file_extension = "".join(filename.suffixes)
        app_name = filename.name.replace(file_extension, "")

        # Prevent parsing other files than configuration ones (directories, incorrect extension)
        if file_extension not in [".yml", ".yaml"]:
            continue

        apps_config_hashmap[app_name] = get_app_config(app_name)
    return apps_config_hashmap
 def test_get_config_app_folder_default(self):
     self.assertEqual(Configuration.get_config_app_folder(), "apps")
 def test_get_config_app_folder_configured(self):
     self.assertEqual(Configuration.get_config_app_folder(),
                      "/a-custom-apps-folder")