mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Merge pull request #1538 from bigchaindb/feat/1441/remove-host-and-port
Feat/1441/remove host and port
This commit is contained in:
commit
ced4058e68
@ -13,5 +13,6 @@ WORKDIR /data
|
||||
ENV BIGCHAINDB_CONFIG_PATH /data/.bigchaindb
|
||||
ENV BIGCHAINDB_SERVER_BIND 0.0.0.0:9984
|
||||
ENV BIGCHAINDB_WSSERVER_HOST 0.0.0.0
|
||||
ENV BIGCHAINDB_WSSERVER_SCHEME ws
|
||||
ENTRYPOINT ["bigchaindb"]
|
||||
CMD ["start"]
|
||||
|
@ -9,6 +9,7 @@ RUN apt-get update \
|
||||
|
||||
ENV BIGCHAINDB_SERVER_BIND 0.0.0.0:9984
|
||||
ENV BIGCHAINDB_WSSERVER_HOST 0.0.0.0
|
||||
ENV BIGCHAINDB_WSSERVER_SCHEME ws
|
||||
|
||||
ARG backend
|
||||
|
||||
|
@ -69,6 +69,7 @@ config = {
|
||||
'workers': None, # if none, the value will be cpu_count * 2 + 1
|
||||
},
|
||||
'wsserver': {
|
||||
'scheme': os.environ.get('BIGCHAINDB_WSSERVER_SCHEME') or 'ws',
|
||||
'host': os.environ.get('BIGCHAINDB_WSSERVER_HOST') or 'localhost',
|
||||
'port': int(os.environ.get('BIGCHAINDB_WSSERVER_PORT', 9985)),
|
||||
},
|
||||
|
@ -96,7 +96,7 @@ def run_configure(args, skip_if_exists=False):
|
||||
val = conf['server'][key]
|
||||
conf['server'][key] = input_on_stderr('API Server {}? (default `{}`): '.format(key, val), val)
|
||||
|
||||
for key in ('host', 'port'):
|
||||
for key in ('scheme', 'host', 'port'):
|
||||
val = conf['wsserver'][key]
|
||||
conf['wsserver'][key] = input_on_stderr('WebSocket Server {}? (default `{}`): '.format(key, val), val)
|
||||
|
||||
|
@ -3,7 +3,7 @@ Common classes and methods for API handlers
|
||||
"""
|
||||
import logging
|
||||
|
||||
from flask import jsonify, request
|
||||
from flask import jsonify
|
||||
|
||||
from bigchaindb import config
|
||||
|
||||
@ -21,14 +21,9 @@ def make_error(status_code, message=None):
|
||||
return response
|
||||
|
||||
|
||||
def base_url():
|
||||
return '%s://%s/' % (request.environ['wsgi.url_scheme'],
|
||||
request.environ['HTTP_HOST'])
|
||||
|
||||
|
||||
def base_ws_uri():
|
||||
"""Base websocket uri."""
|
||||
# TODO Revisit as this is a workaround to address issue
|
||||
# https://github.com/bigchaindb/bigchaindb/issues/1465.
|
||||
host = request.environ['HTTP_HOST'].split(':')[0]
|
||||
return 'ws://{}:{}'.format(host, config['wsserver']['port'])
|
||||
scheme = config['wsserver']['scheme']
|
||||
host = config['wsserver']['host']
|
||||
port = config['wsserver']['port']
|
||||
return '{}://{}:{}'.format(scheme, host, port)
|
||||
|
@ -4,7 +4,7 @@ import flask
|
||||
from flask_restful import Resource
|
||||
|
||||
import bigchaindb
|
||||
from bigchaindb.web.views.base import base_url, base_ws_uri
|
||||
from bigchaindb.web.views.base import base_ws_uri
|
||||
from bigchaindb import version
|
||||
from bigchaindb.web.websocket_server import EVENTS_ENDPOINT
|
||||
|
||||
@ -17,7 +17,7 @@ class RootIndex(Resource):
|
||||
]
|
||||
return flask.jsonify({
|
||||
'api': {
|
||||
'v1': get_api_v1_info()
|
||||
'v1': get_api_v1_info('/api/v1/')
|
||||
},
|
||||
'docs': ''.join(docs_url),
|
||||
'software': 'BigchainDB',
|
||||
@ -29,15 +29,14 @@ class RootIndex(Resource):
|
||||
|
||||
class ApiV1Index(Resource):
|
||||
def get(self):
|
||||
return flask.jsonify(get_api_v1_info())
|
||||
return flask.jsonify(get_api_v1_info('/'))
|
||||
|
||||
|
||||
def get_api_v1_info():
|
||||
def get_api_v1_info(api_prefix):
|
||||
"""
|
||||
Return a dict with all the information specific for the v1 of the
|
||||
api.
|
||||
"""
|
||||
api_root = base_url() + 'api/v1/'
|
||||
websocket_root = base_ws_uri() + EVENTS_ENDPOINT
|
||||
docs_url = [
|
||||
'https://docs.bigchaindb.com/projects/server/en/v',
|
||||
@ -47,9 +46,9 @@ def get_api_v1_info():
|
||||
|
||||
return {
|
||||
'docs': ''.join(docs_url),
|
||||
'transactions': api_root + 'transactions/',
|
||||
'statuses': api_root + 'statuses/',
|
||||
'assets': api_root + 'assets/',
|
||||
'outputs': api_root + 'outputs/',
|
||||
'transactions': '{}transactions/'.format(api_prefix),
|
||||
'statuses': '{}statuses/'.format(api_prefix),
|
||||
'assets': '{}assets/'.format(api_prefix),
|
||||
'outputs': '{}outputs/'.format(api_prefix),
|
||||
'streams': websocket_root
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ For convenience, here's a list of all the relevant environment variables (docume
|
||||
`BIGCHAINDB_SERVER_LOGLEVEL`<br>
|
||||
`BIGCHAINDB_SERVER_WORKERS`<br>
|
||||
`BIGCHAINDB_SERVER_THREADS`<br>
|
||||
`BIGCHAINDB_WSSERVER_SCHEME`<br>
|
||||
`BIGCHAINDB_WSSERVER_HOST`<br>
|
||||
`BIGCHAINDB_WSSERVER_PORT`<br>
|
||||
`BIGCHAINDB_CONFIG_PATH`<br>
|
||||
|
@ -147,6 +147,7 @@ def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request, certs_d
|
||||
DATABASE_PORT = 4242
|
||||
DATABASE_BACKEND = request.config.getoption('--database-backend')
|
||||
SERVER_BIND = '1.2.3.4:56'
|
||||
WSSERVER_SCHEME = 'ws'
|
||||
WSSERVER_HOST = '1.2.3.4'
|
||||
WSSERVER_PORT = 57
|
||||
KEYRING = 'pubkey_0:pubkey_1:pubkey_2'
|
||||
@ -169,6 +170,7 @@ def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request, certs_d
|
||||
'BIGCHAINDB_DATABASE_PORT': str(DATABASE_PORT),
|
||||
'BIGCHAINDB_DATABASE_BACKEND': 'mongodb',
|
||||
'BIGCHAINDB_SERVER_BIND': SERVER_BIND,
|
||||
'BIGCHAINDB_WSSERVER_SCHEME': WSSERVER_SCHEME,
|
||||
'BIGCHAINDB_WSSERVER_HOST': WSSERVER_HOST,
|
||||
'BIGCHAINDB_WSSERVER_PORT': WSSERVER_PORT,
|
||||
'BIGCHAINDB_KEYRING': KEYRING,
|
||||
@ -183,6 +185,7 @@ def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request, certs_d
|
||||
'BIGCHAINDB_DATABASE_PORT': str(DATABASE_PORT),
|
||||
'BIGCHAINDB_DATABASE_BACKEND': DATABASE_BACKEND,
|
||||
'BIGCHAINDB_SERVER_BIND': SERVER_BIND,
|
||||
'BIGCHAINDB_WSSERVER_SCHEME': WSSERVER_SCHEME,
|
||||
'BIGCHAINDB_WSSERVER_HOST': WSSERVER_HOST,
|
||||
'BIGCHAINDB_WSSERVER_PORT': WSSERVER_PORT,
|
||||
'BIGCHAINDB_KEYRING': KEYRING,
|
||||
@ -255,6 +258,7 @@ def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request, certs_d
|
||||
'workers': None,
|
||||
},
|
||||
'wsserver': {
|
||||
'scheme': WSSERVER_SCHEME,
|
||||
'host': WSSERVER_HOST,
|
||||
'port': WSSERVER_PORT,
|
||||
},
|
||||
|
@ -1,31 +1,23 @@
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def api_v1_info():
|
||||
docs_url = ['https://docs.bigchaindb.com/projects/server/en/vtsttst',
|
||||
'/http-client-server-api.html',
|
||||
]
|
||||
return {
|
||||
'docs': ''.join(docs_url),
|
||||
'transactions': 'http://localhost/api/v1/transactions/',
|
||||
'statuses': 'http://localhost/api/v1/statuses/',
|
||||
'assets': 'http://localhost/api/v1/assets/',
|
||||
'outputs': 'http://localhost/api/v1/outputs/',
|
||||
'streams': 'ws://localhost:9985/api/v1/streams/valid_transactions',
|
||||
}
|
||||
|
||||
|
||||
@mock.patch('bigchaindb.version.__short_version__', 'tst')
|
||||
@mock.patch('bigchaindb.version.__version__', 'tsttst')
|
||||
@mock.patch('bigchaindb.config', {'keyring': ['abc'], 'keypair': {'public': 'def'}})
|
||||
def test_api_root_endpoint(client, api_v1_info):
|
||||
def test_api_root_endpoint(client):
|
||||
res = client.get('/')
|
||||
docs_url = ['https://docs.bigchaindb.com/projects/server/en/vtsttst',
|
||||
'/http-client-server-api.html']
|
||||
assert res.json == {
|
||||
'api': {
|
||||
'v1': api_v1_info
|
||||
'v1': {
|
||||
'docs': ''.join(docs_url),
|
||||
'transactions': '/api/v1/transactions/',
|
||||
'statuses': '/api/v1/statuses/',
|
||||
'assets': '/api/v1/assets/',
|
||||
'outputs': '/api/v1/outputs/',
|
||||
'streams': 'ws://localhost:9985/api/v1/streams/valid_transactions',
|
||||
}
|
||||
},
|
||||
'docs': 'https://docs.bigchaindb.com/projects/server/en/vtsttst/',
|
||||
'version': 'tsttst',
|
||||
@ -37,6 +29,16 @@ def test_api_root_endpoint(client, api_v1_info):
|
||||
|
||||
@mock.patch('bigchaindb.version.__short_version__', 'tst')
|
||||
@mock.patch('bigchaindb.version.__version__', 'tsttst')
|
||||
def test_api_v1_endpoint(client, api_v1_info):
|
||||
def test_api_v1_endpoint(client):
|
||||
docs_url = ['https://docs.bigchaindb.com/projects/server/en/vtsttst',
|
||||
'/http-client-server-api.html']
|
||||
api_v1_info = {
|
||||
'docs': ''.join(docs_url),
|
||||
'transactions': '/transactions/',
|
||||
'statuses': '/statuses/',
|
||||
'assets': '/assets/',
|
||||
'outputs': '/outputs/',
|
||||
'streams': 'ws://localhost:9985/api/v1/streams/valid_transactions',
|
||||
}
|
||||
res = client.get('/api/v1')
|
||||
assert res.json == api_v1_info
|
||||
|
Loading…
x
Reference in New Issue
Block a user