-
Notifications
You must be signed in to change notification settings - Fork 0
Add managed server hostname setting #46
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
Merged
Merged
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Cloud Backup Setup Service Refactor | ||
|
|
||
| ## Context | ||
|
|
||
| The cloud backup management page already uses `CloudBackupService`, but the setup wizard still | ||
| implemented MEGA password obscuring, temporary rclone config generation, folder listing, folder | ||
| creation, and credential persistence inside the route module. | ||
|
|
||
| ## Decision | ||
|
|
||
| Keep the existing setup wizard endpoint URLs and request field names as onboarding compatibility | ||
| wrappers. Delegate the actual cloud-backup behavior to `CloudBackupService` so onboarding and | ||
| post-setup management use the same rclone and configuration rules. | ||
|
|
||
| ## Follow-up Checks | ||
|
|
||
| - Setup wizard tests should verify the legacy setup payloads are mapped to the shared service. | ||
| - Cloud backup service tests remain the behavior source for rclone command shape, timeouts, | ||
| credential write ordering, and advanced rclone persistence. |
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 @@ | ||
| # Server Identity Hostname | ||
|
|
||
| ## Context | ||
|
|
||
| The setup wizard collected `system.server_name`, but that value was only stored in | ||
| SimpleSaferServer config and used by alert email scripts. Operators expected the | ||
| same name to also be the server name they connect to on the network. | ||
|
|
||
| ## Decision | ||
|
|
||
| Server-name changes now go through a shared server-identity service. The service | ||
| validates one simple hostname format, updates `/etc/hosts`, applies the OS | ||
| hostname, persists SimpleSaferServer config, and restarts Samba discovery/services | ||
| when changed after setup. | ||
|
|
||
| The original hostname is recorded once so uninstall can warn operators that the | ||
| host-level name was changed by SimpleSaferServer. Uninstall intentionally leaves | ||
| the current hostname and `/etc/hosts` in place because they are host identity, not | ||
| app-owned files. | ||
|
|
||
| ## Follow-up Checks | ||
|
|
||
| - Setup and File Sharing should keep using the shared validation and helper text. | ||
| - If hostname policy changes, update the Python service, setup JavaScript, and | ||
| File Sharing JavaScript together. | ||
| - `uninstall.sh` should continue warning about managed hostname metadata before | ||
| deleting `/etc/SimpleSaferServer`. |
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,36 @@ | ||
| from typing import Optional | ||
|
|
||
| from simple_safer_server.adapters.command_runner import CommandRunner | ||
|
|
||
| SERVER_IDENTITY_TIMEOUT_SECONDS = 30 | ||
|
|
||
|
|
||
| class ServerIdentityCommandAdapter: | ||
| """Wrap host identity commands behind one injectable boundary.""" | ||
|
|
||
| def __init__(self, command_runner: Optional[CommandRunner] = None) -> None: | ||
| self._command_runner = command_runner or CommandRunner() | ||
|
|
||
| def current_hostname(self) -> str: | ||
| result = self._command_runner.run( | ||
| ["hostname"], | ||
| capture_output=True, | ||
| text=True, | ||
| check=True, | ||
| timeout=SERVER_IDENTITY_TIMEOUT_SECONDS, | ||
| ) | ||
| return result.stdout.strip() | ||
|
|
||
| def set_hostname(self, hostname: str) -> None: | ||
| self._command_runner.run( | ||
| ["hostnamectl", "set-hostname", hostname], | ||
| check=True, | ||
| timeout=SERVER_IDENTITY_TIMEOUT_SECONDS, | ||
| ) | ||
|
|
||
| def restart_unit(self, unit_name: str) -> None: | ||
| self._command_runner.run( | ||
| ["systemctl", "restart", unit_name], | ||
| check=True, | ||
| timeout=SERVER_IDENTITY_TIMEOUT_SECONDS, | ||
| ) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| from typing import Any | ||
|
|
||
| from flask import Blueprint, current_app | ||
|
|
||
| from simple_safer_server.services.server_identity import ServerIdentityError | ||
| from simple_safer_server.services.user_manager import api_admin_required | ||
| from simple_safer_server.web.api import json_data, json_problem, json_request_data | ||
| from simple_safer_server.web.problems import OperationProblem, ValidationProblem | ||
|
|
||
| server_identity = Blueprint("server_identity_routes", __name__) | ||
|
|
||
|
|
||
| def _get_services() -> Any: | ||
| """Return app-level services registered during Flask startup.""" | ||
| return current_app.extensions["simple_safer_server"] | ||
|
|
||
|
|
||
| @server_identity.route("/api/server_identity", methods=["GET"]) | ||
| @api_admin_required | ||
| def api_get_server_identity(): | ||
| try: | ||
| return json_data(_get_services().server_identity_service.current_identity()) | ||
| except Exception: | ||
| current_app.logger.exception("Failed to read server identity") | ||
| return json_problem(OperationProblem("Failed to read server name.")) | ||
|
|
||
|
|
||
| @server_identity.route("/api/server_identity", methods=["PUT"]) | ||
| @api_admin_required | ||
| def api_update_server_identity(): | ||
| data = json_request_data() | ||
| try: | ||
| result = _get_services().server_identity_service.update_server_name( | ||
| data.get("server_name"), | ||
| restart_samba=True, | ||
| ) | ||
| message = "Server name updated." | ||
| if result.warning: | ||
| message = f"{message} {result.warning}" | ||
| return json_data(result, message=message) | ||
| except ServerIdentityError as exc: | ||
| return json_problem(ValidationProblem(str(exc), slug="server-identity-validation-error")) | ||
| except Exception: | ||
| current_app.logger.exception("Failed to update server identity") | ||
| return json_problem( | ||
| OperationProblem( | ||
| "Failed to update server name.", | ||
| slug="server-identity-operation-failed", | ||
| ) | ||
| ) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.