Skip to content

Commit

Permalink
Add accept_docker_risk boolean in info endpoint
Browse files Browse the repository at this point in the history
This is the backend part of
#5176, essentially adding a way
for the frontend to check if the user of the backend has set a
specific environment variable.
  • Loading branch information
LefterisJP committed Jan 7, 2023
1 parent e41b3cb commit 7b84e04
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
4 changes: 3 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10432,7 +10432,7 @@ Querying general information

.. http:get:: /api/(version)/info
Doing a GET on the info endpoint will return general information about rotki. Under the version key we get info on the current version of rotki. When ``check_for_updates`` is ``true`` if there is a newer version then ``"download_url"`` will be populated. If not then only ``"our_version"`` and ``"latest_version"`` will be. There is a possibility that latest version may not be populated due to github not being reachable. Also we return the data directory
Doing a GET on the info endpoint will return general information about rotki. Under the version key we get info on the current version of rotki. When ``check_for_updates`` is ``true`` if there is a newer version then ``"download_url"`` will be populated. If not then only ``"our_version"`` and ``"latest_version"`` will be. There is a possibility that latest version may not be populated due to github not being reachable. Also we return the data directory and other information.

.. note::
This endpoint also accepts parameters as query arguments.
Expand Down Expand Up @@ -10465,6 +10465,7 @@ Querying general information
},
"data_directory": "/home/username/.local/share/rotki/data"
"log_level": "DEBUG",
"accept_docker_risk: false
},
"message": ""
}
Expand All @@ -10474,6 +10475,7 @@ Querying general information
:resjson str download_url: URL link to download the latest version
:resjson str data_directory: The rotki data directory
:resjson str log_level: The log level used in the backend. Can be ``DEBUG``, ``INFO``, ``WARN``, ``ERROR`` or ``CRITICAL``.
:resjson bool accept_docker_risk: A boolean indicating if the user has passed an environment variable to the backend process acknowledging the security issues with the docker setup: https://github.com/rotki/rotki/issues/5176

:statuscode 200: Information queried successfully
:statuscode 500: Internal rotki error
Expand Down
2 changes: 2 additions & 0 deletions rotkehlchen/api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import hashlib
import json
import logging
import os
import sys
import tempfile
import traceback
Expand Down Expand Up @@ -2415,6 +2416,7 @@ def get_info(self, check_for_updates: bool) -> Response:
'version': process_result(version),
'data_directory': str(self.rotkehlchen.data_dir),
'log_level': logging.getLevelName(logging.getLogger().getEffectiveLevel()),
'accept_docker_risk': 'ROTKI_ACCEPT_DOCKER_RISK' in os.environ,
}
return api_response(_wrap_in_ok_result(result), status_code=HTTPStatus.OK)

Expand Down
4 changes: 2 additions & 2 deletions rotkehlchen/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@
('/assets/ignored', IgnoredAssetsResource),
('/assets/updates', AssetUpdatesResource),
('/assets/user', UserAssetsResource),
('/assets/custom', CustomAssetsResource),
('/assets/custom/types', CustomAssetsTypesResource),
('/actions/ignored', IgnoredActionsResource),
('/info', InfoResource),
('/ping', PingResource),
Expand All @@ -309,8 +311,6 @@
'per_timestamp_db_snapshots_resource',
),
('/notes', UserNotesResource),
('/assets/custom', CustomAssetsResource),
('/assets/custom/types', CustomAssetsTypesResource),
]

logger = logging.getLogger(__name__)
Expand Down
24 changes: 24 additions & 0 deletions rotkehlchen/tests/api/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from http import HTTPStatus
from typing import Any
from unittest.mock import patch
Expand Down Expand Up @@ -54,6 +55,7 @@ def patched_get_latest_release(_klass):
},
'data_directory': str(rotki.data_dir),
'log_level': 'DEBUG',
'accept_docker_risk': False,
}

with version_patch, release_patch:
Expand All @@ -76,6 +78,27 @@ def patched_get_latest_release(_klass):
},
'data_directory': str(rotki.data_dir),
'log_level': 'DEBUG',
'accept_docker_risk': False,
}

with version_patch, release_patch, patch.dict(os.environ, {'ROTKI_ACCEPT_DOCKER_RISK': 'whatever'}): # noqa: E501
response = requests.get(
url=api_url_for(
rotkehlchen_api_server,
'inforesource',
),
)

result = assert_proper_response_with_result(response)
assert result == {
'version': {
'our_version': expected_version,
'latest_version': None,
'download_url': None,
},
'data_directory': str(rotki.data_dir),
'log_level': 'DEBUG',
'accept_docker_risk': True,
}


Expand Down Expand Up @@ -128,6 +151,7 @@ def patched_get_latest_release(_klass):
},
'data_directory': str(rotki.data_dir),
'log_level': 'DEBUG',
'accept_docker_risk': False,
}


Expand Down

0 comments on commit 7b84e04

Please sign in to comment.