44
55from typing import Text
66
7- import yaml
7+ import anyconfig
88
99from pyms .constants import CONFIGMAP_FILE_ENVIRONMENT , LOGGER_NAME
1010from pyms .exceptions import AttrDoesNotExistException , ConfigDoesNotFoundException
@@ -19,7 +19,7 @@ def __init__(self, *args, **kwargs):
1919 environment with the constant `CONFIGMAP_FILE_ENVIRONMENT`
2020 """
2121
22- config = kwargs .get ("config" ) or self ._get_conf_from_yaml_file (kwargs .get ("path" )) or self ._get_conf_from_env ()
22+ config = kwargs .get ("config" ) or self ._get_conf_from_file (kwargs .get ("path" )) or self ._get_conf_from_env ()
2323
2424 if not config :
2525 raise ConfigDoesNotFoundException ("Configuration file not found" )
@@ -56,19 +56,14 @@ def __getattr__(self, name, *args, **kwargs):
5656 def _get_conf_from_env (self ):
5757 file = os .environ .get (CONFIGMAP_FILE_ENVIRONMENT )
5858 logger .info ("[CONF] Searching file in ENV[{}]: {}..." .format (CONFIGMAP_FILE_ENVIRONMENT , file ))
59- return self ._get_conf_from_yaml_file (os .environ .get (CONFIGMAP_FILE_ENVIRONMENT ))
59+ return self ._get_conf_from_file (os .environ .get (CONFIGMAP_FILE_ENVIRONMENT ))
6060
61- def _get_conf_from_yaml_file (self , path : Text ) -> dict :
61+ def _get_conf_from_file (self , path : Text ) -> dict :
6262 if not path or not os .path .isfile (path ):
6363 return {}
6464 logger .info ("[CONF] Configmap {} found" .format (path ))
65- f = open (path , "r" )
66- conf = self ._get_conf_from_yaml (f .read ())
67- f .close ()
65+ conf = anyconfig .load (path )
6866 return conf
6967
70- def _get_conf_from_yaml (self , config : Text ) -> dict :
71- return yaml .safe_load (config )
72-
7368 def __setattr__ (self , name , value , * args , ** kwargs ):
7469 super (ConfFile , self ).__setattr__ (name , value )
0 commit comments