Skip to content

Commit f539fdc

Browse files
committed
Added default config file
1 parent 0724b95 commit f539fdc

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import os
2-
31
from pyms.flask.app import Microservice
42

5-
os.environ["CONFIGMAP_FILE"] = "config.yml"
6-
ms = Microservice(service="my-ms", path=__file__)
3+
ms = Microservice(service="my-ms", path=__file__)

examples/microservice_swagger/main.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import os
2-
31
from pyms.flask.app import Microservice
42

5-
os.environ["CONFIGMAP_FILE"] = "config.yml"
63
ms = Microservice(service="my-ms", path=__file__)
74
app = ms.create_app()
85

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import os
21
from flask import jsonify
2+
33
from pyms.flask.app import Microservice
44

5-
os.environ["CONFIGMAP_FILE"] = "config.yml"
65
ms = Microservice(service="my-minimal-microservice", path=__file__)
76
app = ms.create_app()
87

8+
99
@app.route("/")
1010
def example():
1111
return jsonify({"main": "hello world"})
1212

13+
1314
if __name__ == '__main__':
1415
app.run()

pyms/config/confile.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
class ConfFile(dict):
1515
empty_init = False
16+
default_file = "config.yml"
1617

1718
def __init__(self, *args, **kwargs):
1819
"""
@@ -63,9 +64,9 @@ def __getattr__(self, name, *args, **kwargs):
6364
raise AttrDoesNotExistException("Variable {} not exist in the config file".format(name))
6465

6566
def _get_conf_from_env(self):
66-
file = os.environ.get(CONFIGMAP_FILE_ENVIRONMENT)
67-
logger.info("[CONF] Searching file in ENV[{}]: {}...".format(CONFIGMAP_FILE_ENVIRONMENT, file))
68-
return self._get_conf_from_file(os.environ.get(CONFIGMAP_FILE_ENVIRONMENT))
67+
config_file = os.environ.get(CONFIGMAP_FILE_ENVIRONMENT, self.default_file)
68+
logger.info("[CONF] Searching file in ENV[{}]: {}...".format(CONFIGMAP_FILE_ENVIRONMENT, config_file))
69+
return self._get_conf_from_file(config_file)
6970

7071
def _get_conf_from_file(self, path: Text) -> dict:
7172
if not path or not os.path.isfile(path):

0 commit comments

Comments
 (0)