Skip to content

Commit 977552d

Browse files
committed
#22 - add get_env helper method to worker base
1 parent 561f7ff commit 977552d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

cortexutils/worker.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ def get_param(self, name, default=None, message=None):
160160

161161
return self.__get_param(self._input, name, default, message)
162162

163+
def get_env(self, key, default=None, message=None):
164+
"""Wrapper for getting configuration values from the environment.
165+
:param key: Key of the environment variable to get.
166+
:param default: Default value, if not found. Default: None
167+
:param message: Error message. If given and key not found, exit with error. Default: None"""
168+
169+
if key in os.environ:
170+
return os.environ[key]
171+
else:
172+
if message is not None:
173+
self.error(message)
174+
return default
175+
163176
def error(self, message, ensure_ascii=False):
164177
"""Stop analyzer with an error message. Changing ensure_ascii can be helpful when stucking
165178
with ascii <-> utf-8 issues. Additionally, the input as returned, too. Maybe helpful when dealing with errors.

0 commit comments

Comments
 (0)