-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Node] improve node distribution UI #3521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GuillaumeDSM
wants to merge
1
commit into
dev
Choose a base branch
from
node_mode
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/tentacles/Services/Interfaces/web_interface/models/distributions/node/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Drakkar-Software OctoBot-Interfaces | ||
| # Copyright (c) Drakkar-Software, All rights reserved. | ||
| # | ||
| # This library is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU Lesser General Public | ||
| # License as published by the Free Software Foundation; either | ||
| # version 3.0 of the License, or (at your option) any later version. | ||
| # | ||
| # This library is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| # Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public | ||
| # License along with this library. | ||
|
|
||
| import tentacles.Services.Interfaces.web_interface.models.distributions.node.configuration | ||
|
|
||
| from tentacles.Services.Interfaces.web_interface.models.distributions.node.configuration import ( | ||
| get_node_local_endpoint, | ||
| get_node_web_ui_url, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "get_node_local_endpoint", | ||
| "get_node_web_ui_url", | ||
| ] |
42 changes: 42 additions & 0 deletions
42
...es/tentacles/Services/Interfaces/web_interface/models/distributions/node/configuration.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Drakkar-Software OctoBot-Interfaces | ||
| # Copyright (c) Drakkar-Software, All rights reserved. | ||
| # | ||
| # This library is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU Lesser General Public | ||
| # License as published by the Free Software Foundation; either | ||
| # version 3.0 of the License, or (at your option) any later version. | ||
| # | ||
| # This library is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| # Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public | ||
| # License along with this library. | ||
| import os | ||
| import socket | ||
| import typing | ||
|
|
||
| import octobot_services.constants as services_constants | ||
| import tentacles.Services.Services_bases as Service_bases | ||
|
|
||
|
|
||
| def get_node_web_ui_url() -> typing.Optional[str]: | ||
| node_api_service = Service_bases.NodeApiService.instance() | ||
| if not Service_bases.NodeApiService.get_is_enabled(node_api_service.config): | ||
| return None | ||
| return f"{node_api_service.get_node_api_url().rstrip('/')}/app" | ||
|
|
||
|
|
||
| def get_node_local_endpoint() -> tuple[str, int]: | ||
| node_api_service = Service_bases.NodeApiService.instance() | ||
| port = node_api_service.get_bind_port() | ||
| bind_address = os.getenv(services_constants.ENV_NODE_API_ADDRESS) | ||
| if bind_address and bind_address not in ("0.0.0.0", "127.0.0.1"): | ||
| local_ip = bind_address | ||
| else: | ||
| try: | ||
| local_ip = socket.gethostbyname(socket.gethostname()) | ||
| except OSError: | ||
| local_ip = "127.0.0.1" | ||
| return local_ip, port |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/tentacles/Services/Interfaces/web_interface/tests/distributions/test_node.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Drakkar-Software OctoBot-Tentacles | ||
| # Copyright (c) Drakkar-Software, All rights reserved. | ||
| # | ||
| # This library is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU Lesser General Public | ||
| # License as published by the Free Software Foundation; either | ||
| # version 3.0 of the License, or (at your option) any later version. | ||
| # | ||
| # This library is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| # Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public | ||
| # License along with this library. | ||
|
|
||
| import pytest | ||
|
|
||
| import tentacles.Services.Interfaces.web_interface.tests.distribution_tester as distribution_tester | ||
| import octobot.enums | ||
|
|
||
|
|
||
| # All test coroutines will be treated as marked. | ||
| pytestmark = pytest.mark.asyncio | ||
|
|
||
|
|
||
| _COMMUNITY_ACCOUNT_REQUIRED_PATHS = [ | ||
| "/api/tradingview_confirm_email_content", | ||
| ] | ||
|
|
||
|
|
||
| class TestNodeDistributionPlugin(distribution_tester.AbstractDistributionTester): | ||
| DISTRIBUTION = octobot.enums.OctoBotDistribution.NODE | ||
| # backlist endpoints expecting additional data | ||
| URL_BLACK_LIST = [ | ||
| "/tentacle_media", "/export_logs", "/api/first_exchange_details" | ||
| ] | ||
| DOTTED_URLS = ["/robots.txt"] | ||
| VERBOSE = False | ||
|
|
||
| async def test_browse_all_pages_no_required_password(self): | ||
| await self._inner_test_browse_all_pages_no_required_password(_COMMUNITY_ACCOUNT_REQUIRED_PATHS) | ||
|
|
||
| async def test_browse_all_pages_required_password_without_login(self): | ||
| await self._inner_test_browse_all_pages_required_password_without_login([]) | ||
|
|
||
| async def test_browse_all_pages_required_password_with_login(self): | ||
| await self.inner_test_browse_all_pages_required_password_with_login( | ||
| _COMMUNITY_ACCOUNT_REQUIRED_PATHS, [] | ||
| ) |
72 changes: 72 additions & 0 deletions
72
packages/tentacles/Services/Interfaces/web_interface/tests/test_node_configuration_models.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Drakkar-Software OctoBot-Tentacles | ||
| # Copyright (c) Drakkar-Software, All rights reserved. | ||
| # | ||
| # This library is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU Lesser General Public | ||
| # License as published by the Free Software Foundation; either | ||
| # version 3.0 of the License, or (at your option) any later version. | ||
| # | ||
| # This library is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| # Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public | ||
| # License along with this library. | ||
|
|
||
| import mock | ||
|
|
||
| import octobot_services.constants as services_constants | ||
| import tentacles.Services.Interfaces.web_interface.models.distributions.node.configuration as node_configuration_model | ||
|
|
||
|
|
||
| class TestGetNodeLocalEndpoint: | ||
| def test_uses_explicit_bind_address_when_not_loopback_or_any(self): | ||
| node_api_service = mock.Mock() | ||
| node_api_service.get_bind_port.return_value = 8000 | ||
|
|
||
| with mock.patch.object( | ||
| node_configuration_model.Service_bases.NodeApiService, | ||
| "instance", | ||
| mock.Mock(return_value=node_api_service), | ||
| ), mock.patch.dict("os.environ", {services_constants.ENV_NODE_API_ADDRESS: "192.168.1.42"}, clear=False): | ||
| local_ip, port = node_configuration_model.get_node_local_endpoint() | ||
|
|
||
| assert local_ip == "192.168.1.42" | ||
| assert port == 8000 | ||
|
|
||
| def test_resolves_hostname_when_bind_address_is_any(self): | ||
| node_api_service = mock.Mock() | ||
| node_api_service.get_bind_port.return_value = 9001 | ||
|
|
||
| with mock.patch.object( | ||
| node_configuration_model.Service_bases.NodeApiService, | ||
| "instance", | ||
| mock.Mock(return_value=node_api_service), | ||
| ), mock.patch.dict("os.environ", {services_constants.ENV_NODE_API_ADDRESS: "0.0.0.0"}, clear=False), mock.patch.object( | ||
| node_configuration_model.socket, | ||
| "gethostbyname", | ||
| mock.Mock(return_value="10.0.0.5"), | ||
| ): | ||
| local_ip, port = node_configuration_model.get_node_local_endpoint() | ||
|
|
||
| assert local_ip == "10.0.0.5" | ||
| assert port == 9001 | ||
|
|
||
| def test_falls_back_to_loopback_when_hostname_resolution_fails(self): | ||
| node_api_service = mock.Mock() | ||
| node_api_service.get_bind_port.return_value = 8000 | ||
|
|
||
| with mock.patch.object( | ||
| node_configuration_model.Service_bases.NodeApiService, | ||
| "instance", | ||
| mock.Mock(return_value=node_api_service), | ||
| ), mock.patch.dict("os.environ", {}, clear=True), mock.patch.object( | ||
| node_configuration_model.socket, | ||
| "gethostbyname", | ||
| mock.Mock(side_effect=OSError("hostname resolution failed")), | ||
| ): | ||
| local_ip, port = node_configuration_model.get_node_local_endpoint() | ||
|
|
||
| assert local_ip == "127.0.0.1" | ||
| assert port == 8000 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😮