diff --git a/anchor/app.py b/anchor/app.py index 17fd39f..00f9266 100644 --- a/anchor/app.py +++ b/anchor/app.py @@ -198,7 +198,8 @@ def load_config(): user_config_path = os.path.join( os.environ['HOME'], '.config', 'anchor', 'config.json') - sys_config_path = os.path.join(os.sep, 'etc', 'anchor', 'config.json') + prefix = os.environ.get('VIRTUAL_ENV', os.sep) + sys_config_path = os.path.join(prefix, 'etc', 'anchor', 'config.json') if 'registration_authority' not in jsonloader.conf.config: config_path = "" diff --git a/config.py b/anchor/config.py similarity index 97% rename from config.py rename to anchor/config.py index f9fe12a..e0dad12 100644 --- a/config.py +++ b/anchor/config.py @@ -1,6 +1,6 @@ server = { 'port': '5016', - 'host': '0.0.0.0' + 'host': '0.0.0.0' # nosec } # Pecan Application Configurations diff --git a/bin/anchor b/bin/anchor new file mode 100755 index 0000000..cb03733 --- /dev/null +++ b/bin/anchor @@ -0,0 +1,43 @@ +#!/bin/sh + +if [ "$1" = "-h" -o "$1" = "--help" ] ; then + echo "Usage: [PY=optional/path/python] $0" + echo + echo "Run Anchor with default uwsgi settings. It will spawn 4 workers" + echo "and use either the default reachable 'python' or one defined in the" + echo "\$PY variable." + echo + exit 0 +fi + +if ! which uwsgi > /dev/null ; then + echo "You need to install uwsgi to run anchor using this script." + exit 1 +fi + +PY=${PY:-python} + +if ! [ -x "$PY" ] ; then + if ! [ -x "$(which "$PY")" ] ; then + echo "Python interpreter not found (use PY variable to specify)." + exit 1 + fi +fi + +STR="import pkg_resources; print(pkg_resources.get_distribution('anchor').location)" +PKG_PATH=$("$PY" -c "$STR") + +if ! [ -d "$PKG_PATH" ] ; then + echo "Cannot find installed anchor package." + exit 1 +fi + +if [ -z "$VIRTUAL_ENV" ]; then + OPTS="-p 4" +else + OPTS="--venv ""${VIRTUAL_ENV}"" -p 4" +fi + +uwsgi --http-socket :5016 \ + --pecan "${PKG_PATH}/anchor/config.py" \ + ${OPTS} diff --git a/bin/anchor_production b/bin/anchor_production deleted file mode 100755 index b91abd4..0000000 --- a/bin/anchor_production +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -VENV=$1 - -[ -n "$VENV" ] || ( echo "provide virtual env path as parameter" && exit 1 ) - -"$VENV/bin/uwsgi" --http-socket :5000 --venv "$VENV" --pecan config.py -p 4 diff --git a/setup.cfg b/setup.cfg index 7d2a4c3..5fe1183 100644 --- a/setup.cfg +++ b/setup.cfg @@ -57,11 +57,10 @@ anchor.fixups = data_files = etc/anchor = config.json - config.py packages = anchor scripts = - bin/anchor_production + bin/anchor bin/anchor_debug [bdist_wheel] diff --git a/tests/controllers/test_app.py b/tests/controllers/test_app.py index 72ffdc1..6c5bab0 100644 --- a/tests/controllers/test_app.py +++ b/tests/controllers/test_app.py @@ -16,6 +16,7 @@ import json +import os import stat import unittest @@ -247,7 +248,9 @@ class TestApp(tests.DefaultConfigMixin, unittest.TestCase): @mock.patch('anchor.jsonloader.conf.load_file_data') def test_config_paths_system(self, conf): - ret = lambda x: True if x == '/etc/anchor/config.json' else False + path = os.path.join(os.environ.get('VIRTUAL_ENV', os.sep), + 'etc/anchor/config.json') + ret = lambda x: x == path with mock.patch('os.path.isfile', ret): app.load_config() - conf.assert_called_with('/etc/anchor/config.json') + conf.assert_called_with(path) diff --git a/tests/test_functional.py b/tests/test_functional.py index 011c0ff..b05b7f9 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -26,9 +26,9 @@ import pecan from pecan import testing as pecan_testing import stevedore +from anchor import config from anchor import jsonloader from anchor.X509 import certificate as X509_cert -import config import tests