small adjustments after first feedback
This commit is contained in:
parent
79cac36b34
commit
e6ae890def
@ -15,7 +15,7 @@ Sample configuration:
|
||||
```
|
||||
|
||||
!!! Danger: Security warning
|
||||
By default, the configuration listens on localhost only (so it's not reachable from other systems). We strongly recommend to not expose this API to the internet, since others will be able to control your bot.
|
||||
By default, the configuration listens on localhost only (so it's not reachable from other systems). We strongly recommend to not expose this API to the internet, since others will potentially be able to control your bot.
|
||||
|
||||
You can then access the API by going to `http://127.0.0.1:8080/api/v1/version` to check if the API is running correctly.
|
||||
|
||||
@ -50,7 +50,7 @@ docker run -d \
|
||||
```
|
||||
|
||||
!!! Danger "Security warning"
|
||||
By using `-p 8080:8080` the API is available to everyone connecting to the server under the correct port, so others will be able to control your bot.
|
||||
By using `-p 8080:8080` the API is available to everyone connecting to the server under the correct port, so others may be able to control your bot.
|
||||
|
||||
## Consuming the API
|
||||
|
||||
|
@ -66,7 +66,6 @@ class ApiServer(RPC):
|
||||
self.app.json_encoder = ArrowJSONEncoder
|
||||
|
||||
# Register application handling
|
||||
self.register_rest_other()
|
||||
self.register_rest_rpc_urls()
|
||||
|
||||
thread = threading.Thread(target=self.run, daemon=True)
|
||||
@ -92,13 +91,13 @@ class ApiServer(RPC):
|
||||
"e.g 127.0.0.1 in config.json")
|
||||
|
||||
# Run the Server
|
||||
logger.info('Starting Local Rest Server')
|
||||
logger.info('Starting Local Rest Server.')
|
||||
try:
|
||||
self.srv = make_server(rest_ip, rest_port, self.app)
|
||||
self.srv.serve_forever()
|
||||
except Exception:
|
||||
logger.exception("Api server failed to start, exception message is:")
|
||||
logger.info('Starting Local Rest Server_end')
|
||||
logger.exception("Api server failed to start.")
|
||||
logger.info('Local Rest Server started.')
|
||||
|
||||
def send_msg(self, msg: Dict[str, str]) -> None:
|
||||
"""
|
||||
@ -114,13 +113,6 @@ class ApiServer(RPC):
|
||||
def rest_error(self, error_msg):
|
||||
return jsonify({"error": error_msg}), 502
|
||||
|
||||
def register_rest_other(self):
|
||||
"""
|
||||
Registers flask app URLs that are not calls to functionality in rpc.rpc.
|
||||
:return:
|
||||
"""
|
||||
self.app.register_error_handler(404, self.page_not_found)
|
||||
|
||||
def register_rest_rpc_urls(self):
|
||||
"""
|
||||
Registers flask app URLs that are calls to functonality in rpc.rpc.
|
||||
@ -129,6 +121,8 @@ class ApiServer(RPC):
|
||||
Label can be used as a shortcut when refactoring
|
||||
:return:
|
||||
"""
|
||||
self.app.register_error_handler(404, self.page_not_found)
|
||||
|
||||
# Actions to control the bot
|
||||
self.app.add_url_rule(f'{BASE_URI}/start', 'start',
|
||||
view_func=self._start, methods=['POST'])
|
||||
|
@ -101,7 +101,7 @@ def test_api_run(default_conf, mocker, caplog):
|
||||
assert hasattr(apiserver, "srv")
|
||||
|
||||
assert log_has("Starting HTTP Server at 127.0.0.1:8080", caplog.record_tuples)
|
||||
assert log_has("Starting Local Rest Server", caplog.record_tuples)
|
||||
assert log_has("Starting Local Rest Server.", caplog.record_tuples)
|
||||
|
||||
# Test binding to public
|
||||
caplog.clear()
|
||||
@ -116,7 +116,7 @@ def test_api_run(default_conf, mocker, caplog):
|
||||
assert server_mock.call_args_list[0][0][1] == "8089"
|
||||
assert isinstance(server_mock.call_args_list[0][0][2], Flask)
|
||||
assert log_has("Starting HTTP Server at 0.0.0.0:8089", caplog.record_tuples)
|
||||
assert log_has("Starting Local Rest Server", caplog.record_tuples)
|
||||
assert log_has("Starting Local Rest Server.", caplog.record_tuples)
|
||||
assert log_has("SECURITY WARNING - Local Rest Server listening to external connections",
|
||||
caplog.record_tuples)
|
||||
assert log_has("SECURITY WARNING - This is insecure please set to your loopback,"
|
||||
@ -127,7 +127,7 @@ def test_api_run(default_conf, mocker, caplog):
|
||||
caplog.clear()
|
||||
mocker.patch('freqtrade.rpc.api_server.make_server', MagicMock(side_effect=Exception))
|
||||
apiserver.run()
|
||||
assert log_has("Api server failed to start, exception message is:",
|
||||
assert log_has("Api server failed to start.",
|
||||
caplog.record_tuples)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user