Add support for configuring the plugin using environment variables

This commit is contained in:
Álvaro Arranz 2018-07-12 00:57:36 +02:00
parent 1ab4484f66
commit d98a5e4831
No known key found for this signature in database
GPG Key ID: A9BA9AAE8CF561AB
3 changed files with 8 additions and 4 deletions

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2014 - 2017 CoNWeT Lab., Universidad Politécnica de Madrid
# Copyright (c) 2018 Future Internet Consulting and Development Solutions S.L.
# This file is part of CKAN Private Dataset Extension.
@ -21,6 +22,7 @@ from __future__ import absolute_import
import importlib
import logging
import os
import ckan.plugins as plugins
@ -151,7 +153,7 @@ def _process_package(context, request_data):
plugins.toolkit.check_access(method, context, request_data)
# Get the parser from the configuration
class_path = plugins.toolkit.config.get(PARSER_CONFIG_PROP, '')
class_path = os.environ.get(PARSER_CONFIG_PROP.upper().replace('.', '_'), plugins.toolkit.config.get(PARSER_CONFIG_PROP, ''))
if class_path != '':
try:

8
ckanext/privatedatasets/helpers.py Executable file → Normal file
View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2014-2015 CoNWeT Lab., Universidad Politécnica de Madrid
# Copyright (c) 2018 Future Internet Consulting and Development Solutions S.L.
# This file is part of CKAN Private Dataset Extension.
@ -20,6 +21,7 @@
from __future__ import absolute_import
import logging
import os
from ckan.common import request
import ckan.model as model
@ -64,9 +66,9 @@ def can_read(pkg_dict):
def get_config_bool_value(config_name, default_value=False):
value = tk.config.get(config_name, default_value)
value = value if type(value) == bool else value != 'False'
return value
env_name = config_name.upper().replace('.', '_')
value = os.environ.get(env_name, tk.config.get(config_name, default_value))
return value if type(value) == bool else value.strip().lower() in ('true', '1', 'on')
def show_acquire_url_on_create():

0
ckanext/privatedatasets/plugin.py Executable file → Normal file
View File