1 # -------------------------------------------------------------------------
2 # Copyright (c) 2015-2017 AT&T Intellectual Property
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # -------------------------------------------------------------------------
24 def load_config_file(config_file: str, child_name="dockerConfiguration") -> dict:
26 Load OSDF configuration from a file -- currently only yaml/json are supported
27 :param config_file: path to config file (.yaml or .json).
28 :param child_name: if present, return only that child node
29 :return: config (all or specific child node)
31 with open(config_file, 'r') as fid:
33 if config_file.endswith(".yaml"):
35 elif config_file.endswith(".json") or config_file.endswith("json"):
37 return res.get(child_name, res) if child_name else res
40 def dcae_config(config_file: str) -> dict:
41 return load_config_file(config_file, child_name="dockerConfiguration")
44 def all_configs(**kwargs: dict) -> dict:
46 Load all specified configurations
47 :param config_file_spec: key-value pairs
48 (e.g. { "core": "common_config.yaml", "deployment": "/tmp/1452523532json" })
49 :return: merged config as a nested dictionary
51 return {k: load_config_file(fname) for k, fname in kwargs.items()}