Skip to content

Commit

Permalink
Make config configurable (#91)
Browse files Browse the repository at this point in the history
* make config configurable

* move print to more fitting place
  • Loading branch information
mmacata authored May 20, 2021
1 parent 5e59233 commit c3144b4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 8 deletions.
5 changes: 5 additions & 0 deletions config/sample.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[ACTINIA]
HOST = https://actinia-dev.mundialis.de
PORT = 443
USER = openeo
PASSWORD = EeMob0la
70 changes: 62 additions & 8 deletions src/openeo_grass_gis_driver/actinia_processing/config.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
# -*- coding: utf-8 -*-
import os
import configparser
from pathlib import Path

__license__ = "Apache License, Version 2.0"
__author__ = "Sören Gebbert"
__copyright__ = "Copyright 2018, Sören Gebbert, mundialis"
__maintainer__ = "Soeren Gebbert"
__email__ = "[email protected]"
__author__ = "Sören Gebbert, Carmen Tawalika"
__copyright__ = "Copyright 2018-2021, Sören Gebbert, mundialis"
__maintainer__ = "mundialis"


class Config:
# Settings for docker swarm image
# config can be overwritten by mounting *.ini files into folders inside
# the config folder.
DEFAULT_CONFIG_PATH = "config"
CONFIG_FILES = [str(f) for f in Path(
DEFAULT_CONFIG_PATH).glob('**/*.ini') if f.is_file()]
GENERATED_CONFIG = DEFAULT_CONFIG_PATH + '/openeo-grassgis-driver.cfg'


class ACTINIA:
HOST = "https://actinia-dev.mundialis.de"
PORT = 443
LOCATIONS = ["nc_spm_08", "utm32n", "latlong_wgs84"]
# USER = "demouser"
# PASSWORD = "gu3st!pa55w0rd"
USER = "openeo"
PASSWORD = "EeMob0la"
# The database file that stores the graphs
Expand All @@ -25,3 +31,51 @@ class Config:
# The database file that stores the actinia jobs
ACTINIA_JOB_DB = "%s/.actinia_job_db_file.sqlite" % os.environ["HOME"]
SECRET_KEY = "jaNguzeef4seiv5shahchimoo8teiLah"


class Configfile:

def __init__(self):
"""
This class will overwrite the config classes above when config files
named DEFAULT_CONFIG_PATH/**/*.ini exist.
On first import of the module it is initialized.
"""

config = configparser.ConfigParser()
print("Loading config files: " + str(CONFIG_FILES) + " ...")
config.read(CONFIG_FILES)

if len(config) <= 1:
print("Could not find any config file, using default values.")
return

with open(GENERATED_CONFIG, 'w') as configfile:
config.write(configfile)
print("Configuration written to " + GENERATED_CONFIG)

# CONFIG
if config.has_section("ACTINIA"):
if config.has_option("ACTINIA", "HOST"):
ACTINIA.HOST = config.get("ACTINIA", "HOST")
if config.has_option("ACTINIA", "PORT"):
ACTINIA.PORT = config.get("ACTINIA", "PORT")
if config.has_option("ACTINIA", "LOCATIONS"):
ACTINIA.LOCATIONS = config.get("ACTINIA", "LOCATIONS")
if config.has_option("ACTINIA", "USER"):
ACTINIA.USER = config.get("ACTINIA", "USER")
if config.has_option("ACTINIA", "PASSWORD"):
ACTINIA.PASSWORD = config.get("ACTINIA", "PASSWORD")
if config.has_option("ACTINIA", "GRAPH_DB"):
ACTINIA.GRAPH_DB = config.get("ACTINIA", "GRAPH_DB")
if config.has_option("ACTINIA", "TOKEN_DB"):
ACTINIA.TOKEN_DB = config.get("ACTINIA", "TOKEN_DB")
if config.has_option("ACTINIA", "ACTINIA_JOB_DB"):
ACTINIA.ACTINIA_JOB_DB = config.get(
"ACTINIA", "ACTINIA_JOB_DB")
if config.has_option("ACTINIA", "SECRET_KEY"):
ACTINIA.SECRET_KEY = config.get("ACTINIA", "SECRET_KEY")


init = Configfile()
Config = ACTINIA

0 comments on commit c3144b4

Please sign in to comment.