Merge "Anchor can now be installed and invoked as simply "anchor""

This commit is contained in:
Jenkins 2017-02-20 14:24:49 +00:00 committed by Gerrit Code Review
commit b050019661
7 changed files with 53 additions and 13 deletions

View File

@ -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 = ""

View File

@ -1,6 +1,6 @@
server = {
'port': '5016',
'host': '0.0.0.0'
'host': '0.0.0.0' # nosec
}
# Pecan Application Configurations

43
bin/anchor Executable file
View File

@ -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}

View File

@ -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

View File

@ -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]

View File

@ -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)

View File

@ -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