Skip to content
Snippets Groups Projects
Commit a64ecefd authored by Benjamin Becker's avatar Benjamin Becker
Browse files

moves icap configuration to ckan configuration file

parent 14066431
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,6 @@ from ckan.controllers.package import PackageController
from ckan.controllers.feed import FeedController, ITEMS_LIMIT, _package_search, _create_atom_id
import ckan.lib.helpers as h
import ckan.authz as authz
from ckan.common import c
import logging
import matomo
import ckan.logic as logic
......
[DEFAULT]
# the IP of the ICAP-Server
host = 10.61.127.77
# The port of the ICAP-Server
port = 1344
# the IP of the client-machine
clientip = 127.0.0.1
import socket
import sys
import time
import ConfigParser
import logging
from ckan.common import config
import ckan.plugins.toolkit as toolkit
log = logging.getLogger(__name__)
def _read_from_config(key):
value = config.get(key, None)
if value is None:
_raise_KeyError_if_not_in_config(key)
return value
def _raise_KeyError_if_not_in_config(key):
raise KeyError('key {} is not defined in ckan config file.'.format(key))
class ODSHICAPRequest(object):
def __init__(self, FILENAME, FILEBUFF, cfg_file='odsh_icap_client.cfg'):
config = ConfigParser.ConfigParser()
config.read(cfg_file)
self.HOST = '10.61.127.77'
self.PORT = 1344
self.CLIENTIP = '127.0.0.1'
try:
self.HOST = _read_from_config('ckanext.odsh.icap.host')
self.PORT = toolkit.asint(_read_from_config('ckanext.odsh.icap.port'))
self.CLIENTIP = _read_from_config('ckanext.odsh.icap.clientip')
except KeyError, e:
log.error(e)
self.FILENAME = FILENAME
self.FILEBUFF = FILEBUFF
@staticmethod
def send(self):
print("----- Starting ICAP-Request via RESPMOD -----")
......
import nose.tools as nt
from ckan.common import config
from ckanext.odsh.lib.odsh_icap_client import ODSHICAPRequest, _read_from_config
class Test_ODSHICAPRequest(object):
def setUp(self):
config.update({
'ckanext.odsh.icap.host': 'some_host',
'ckanext.odsh.icap.port': '123',
'ckanext.odsh.icap.clientip': 'some_ip',
})
def tearDown(self):
config.clear()
def test_it_initializes_with_parameters_set_in_config(self):
request = ODSHICAPRequest('some_filename', 'some_filebuffer')
nt.assert_equal(request.HOST, 'some_host')
nt.assert_equal(request.PORT, 123)
nt.assert_equal(request.CLIENTIP, 'some_ip')
def test_read_from_config_raises_KeyError_if_host_not_defined_in_config(self):
del config['ckanext.odsh.icap.host']
with nt.assert_raises(KeyError):
_read_from_config('ckanext.odsh.icap.host')
def test_read_from_config_raises_KeyError_if_port_not_defined_in_config(self):
del config['ckanext.odsh.icap.port']
with nt.assert_raises(KeyError):
_read_from_config('ckanext.odsh.icap.port')
def test_read_from_config_raises_KeyError_if_clientip_not_defined_in_config(self):
del config['ckanext.odsh.icap.clientip']
with nt.assert_raises(KeyError):
_read_from_config('ckanext.odsh.icap.clientip')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment