-
Notifications
You must be signed in to change notification settings - Fork 28
Add password for SSH, AWS and GDrive config #600
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
JoeZiminski
wants to merge
102
commits into
main
Choose a base branch
from
add_password_to_rclone_config_for_aws_gdrive
base: main
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 89 commits
Commits
Show all changes
102 commits
Select commit
Hold shift + click to select a range
bb212ae
Add separate config files for all connection methods.
JoeZiminski f02d6f1
Add password machinery for windows.
JoeZiminski bcc5da4
Prototype input for set up ssh connection.
JoeZiminski 0c4017e
Refactor rclone call functions to handle password.
JoeZiminski 9581d5a
Adding to google drive.
JoeZiminski ba27591
Added password to google dirve.
JoeZiminski 18158b9
Working on aws.
JoeZiminski 0bbfeca
Done adding to Linux.
JoeZiminski 5329c58
Add to macOS.
JoeZiminski 4372550
Set different names for different projects.
JoeZiminski 366d67b
Refactoring.
JoeZiminski ebf073a
Refactoring more.
JoeZiminski 53dcc5c
Tidy up rclone_password.py
JoeZiminski 22a8db0
Editing setup_ssh.
JoeZiminski b32a979
Adding password to SSH GUI.
JoeZiminski d8364d3
Updating setup ssh.
JoeZiminski b9469d6
Playing with setup gdrive.
JoeZiminski e2d2bf7
Setup gdrive 2.
JoeZiminski 6ad0d6b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c2b6e19
Rough version working on all screens.
JoeZiminski 6a12c54
Rough version working on all screens2.
JoeZiminski 8f42d67
Start tidying up TUI.
JoeZiminski b7348ba
Refactoring Rclone Configs.
JoeZiminski b13a984
Finished refactor of configs.
JoeZiminski 190f324
Add doc to setup_gdrive.
JoeZiminski c9a8fb2
Handling TODOs.
JoeZiminski 71fed57
Refactor gdrive page.
JoeZiminski c743859
Fix variable.
JoeZiminski 37e78f7
Extend the gdrive setup message.
JoeZiminski 73995eb
Rework `_try_set_rclone_password`
JoeZiminski 18ffdd5
Add TODO fixes.
JoeZiminski 611a440
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5cf30aa
Fix message asking to use security, add try / except to async
JoeZiminski e53259b
Add backward compatability message.
JoeZiminski 89a6d3c
minor edit.
JoeZiminski 3b7915c
Add docstrings to datashuttle class.
JoeZiminski 46ed30e
Start renaming from password to encrpytion.
JoeZiminski 4d7d7ba
Rename from setting rclone password to setting rclone encrpytion.
JoeZiminski a2246c2
Begin adding docstrings and type hints.
JoeZiminski c7d3fb1
Add docstrings and type hints.
JoeZiminski 54cd2ee
Fix linting.
JoeZiminski eaa06b6
Add first rclone encryption test.
JoeZiminski 3b4ac9d
Update yaml for testing.
JoeZiminski f9d3dbf
install pass on linux.
JoeZiminski f54d863
Initialise pass on linux.
JoeZiminski c1d1c65
Try a different pass set up command.
JoeZiminski 6d1dcbd
Fix ssh and gdrive tests.
JoeZiminski 9a45284
Fixing aws tests.
JoeZiminski 7f1f077
Refactor ssh connection set up tests.
JoeZiminski bbadcec
Finalise aws and other tests, revert changes made to setup_aws during…
JoeZiminski f4b6d4c
Add note on docs.
JoeZiminski c4af1ac
Fix rebase error introduced.
JoeZiminski e0c91f1
Test AWS only because it is hanging in a weird way.
JoeZiminski 1502e1c
Fix purge.
JoeZiminski 342b5f5
Try in verbose mode :(
JoeZiminski 4834b7c
Remove suggest next test and see if this works.
JoeZiminski 2cf1ef4
Finally I think have the test fixes.
JoeZiminski 2b42a46
Remove tests again for checking.
JoeZiminski 210c57c
Try removing another test.
JoeZiminski 74310ef
Try again.
JoeZiminski e90077a
Revert CI changes.
JoeZiminski 2e0f793
Update documentation.
JoeZiminski f40bc33
Quick fix for running on local filesystem mode.
JoeZiminski 8f3e444
Extend Mock Configs class.
JoeZiminski b316947
Fixing tests.
JoeZiminski 60b30be
Fix validate_from_path.
JoeZiminski fd91242
Fix perform_rclone_check.
JoeZiminski 3b0d6ee
Fix linting.
JoeZiminski d51d94e
Some tidy up and extend use cases for new encrpytion checker.
JoeZiminski 4ed8a8a
Apply some fixes from self review 1.
JoeZiminski 2c644a2
Rename to rclone_file_is_encrypted.
JoeZiminski 31c80b0
Remove unecessary type hint ignore.
JoeZiminski ccb718b
Rename preliminary_setup_gdrive_config_for_without_browser.
JoeZiminski ee69564
Small tidy ups.
JoeZiminski 1700651
Revert change to create_folders conditional.
JoeZiminski 7cea970
Small refactor.
JoeZiminski 2e3a710
Remove --ask-password.
JoeZiminski ccbad2a
Update datashuttle/utils/rclone_encryption.py
JoeZiminski 94614fc
Update datashuttle/utils/rclone.py
JoeZiminski cec3c50
Improve a test docstring.
JoeZiminski 1991857
Remove debugging clause.
JoeZiminski 0f50c1b
Update datashuttle/configs/rclone_configs.py
JoeZiminski 611efb2
Fix typo in test docstring: 'ecrypted' → 'encrypted' (#637)
Copilot ed1a89d
Update datashuttle/configs/rclone_configs.py
JoeZiminski f5f44da
Update datashuttle/utils/rclone_encryption.py
JoeZiminski b1a5032
Fix broken try / except.
JoeZiminski ebcd89d
Merge branch 'add_password_to_rclone_config_for_aws_gdrive' of github…
JoeZiminski 06b4a93
Replace direct raise with utils function.
JoeZiminski 6fdb357
Fixes to rclone_encryption.py
JoeZiminski e873b76
Small fixes rclone encryption.
JoeZiminski 3d2cd66
Update datashuttle/datashuttle_class.py
JoeZiminski 531eb02
Update datashuttle/configs/canonical_folders.py
JoeZiminski 8f14c9e
Update datashuttle/datashuttle_class.py
JoeZiminski 07bef3d
Update datashuttle/configs/rclone_configs.py
JoeZiminski e49b526
Fix broken datashuttle version check.
JoeZiminski 4d5450e
Update datashuttle/utils/rclone_encryption.py
JoeZiminski 34981f5
Update docs/source/pages/get_started/set-up-a-project.md
JoeZiminski 33ce2d7
Update datashuttle/tui/screens/setup_aws.py
JoeZiminski bf84a44
Update datashuttle/tui/screens/setup_aws.py
JoeZiminski 651c7dd
Merge branch 'add_password_to_rclone_config_for_aws_gdrive' of github…
JoeZiminski 07a3c0e
Small fixes to sucess message.
JoeZiminski f42d7b2
Tidy up docs.
JoeZiminski 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,26 @@ jobs: | |
| python -m pip install --upgrade pip | ||
| pip install .[dev] | ||
|
|
||
| - name: Install pass on Linux | ||
| # this is required for Rclone config encryption | ||
| if: runner.os == 'Linux' | ||
| run: | | ||
| set -euo pipefail | ||
| sudo apt-get update | ||
| sudo apt-get install -y pass gnupg git | ||
|
|
||
| # Create a dedicated GPG home for this job | ||
| export GNUPGHOME="$(mktemp -d)" | ||
| echo "GNUPGHOME=$GNUPGHOME" >> "$GITHUB_ENV" # <-- make it available to later steps | ||
|
|
||
| # Generate a non-interactive key (no passphrase), no expiry | ||
| gpg --batch --yes --pinentry-mode loopback --passphrase '' \ | ||
| --quick-gen-key "CI Key <[email protected]>" default default 0 | ||
|
|
||
| # Initialize pass with the key fingerprint (more robust than UID) | ||
| FPR="$(gpg --list-secret-keys --with-colons | awk -F: '/^fpr:/ {print $10; exit}')" | ||
| pass init "$FPR" | ||
|
|
||
| # run SSH tests only on Linux because Windows and macOS | ||
| # are already run within a virtual container and so cannot | ||
| # run Linux containers because nested containerisation is disabled. | ||
|
|
@@ -97,7 +117,6 @@ jobs: | |
| run: | | ||
| pytest --ignore=tests/tests_transfers/ssh --ignore=tests/tests_transfers/gdrive --ignore=tests/tests_transfers/aws | ||
|
|
||
|
|
||
| build_sdist_wheels: | ||
| name: Build source distribution | ||
| needs: [test] | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -9,3 +9,7 @@ | |
| except PackageNotFoundError: | ||
| # package is not installed | ||
| pass | ||
|
|
||
|
|
||
| def get_datashuttle_version(): | ||
| return __version__ | ||
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,133 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING, Optional | ||
|
|
||
| if TYPE_CHECKING: | ||
| from pathlib import Path | ||
|
|
||
| from datashuttle.configs.configs_class import Configs | ||
|
|
||
| import yaml | ||
|
|
||
| from datashuttle.configs import canonical_folders | ||
| from datashuttle.utils import rclone_encryption | ||
|
|
||
|
|
||
| class RCloneConfigs: | ||
| """Class to manage the RClone configuration file. | ||
| This is a file that RClone creates to hold all information about local and | ||
| central transfer targets. For example, the SSH RClone config holds the private key, | ||
| the GDrive rclone config holds the access token, etc. | ||
| In datashuttle, local filesystem configs uses the Rclone default configuration file, | ||
| that RClone manages, for backwards compatibility reasons. However, SSH, AWS and GDrive | ||
| configs are stored in separate config files (set using RClone's --config argument). | ||
| Then being separate means these files can be separately encrypted. | ||
| This class tracks the state on whether a RClone config is encrypted, as well | ||
| as provides the default names for the rclone conf (e.g. central_<project_name>_<connection_method>). | ||
| Parameters | ||
| ---------- | ||
| datashuttle_configs | ||
| Parent Configs class. | ||
| config_base_class | ||
| Path to the datashuttle configs folder where all configs for the project are stored. | ||
| """ | ||
|
|
||
| def __init__(self, datashuttle_configs: Configs, config_base_path: Path): | ||
| """Construct the class.""" | ||
| self.datashuttle_configs = datashuttle_configs | ||
| self.rclone_encryption_state_file_path = ( | ||
| config_base_path / "rclone_ps_state.yaml" | ||
| ) | ||
|
|
||
| def load_rclone_config_is_encrypted(self) -> dict: | ||
| """Track whether the Rclone config file is encrypted. | ||
| This could be read directly from the RClone config file, but requires | ||
| a subprocess call which can be slow on Windows. As this function is | ||
| called a lot, we track this explicitly when a rclone config is | ||
| encrypted / unencrypted and store to disk between sessions. | ||
| """ | ||
| assert rclone_encryption.connection_method_requires_encryption( | ||
| self.datashuttle_configs["connection_method"] | ||
| ) | ||
|
|
||
| if self.rclone_encryption_state_file_path.is_file(): | ||
| with open(self.rclone_encryption_state_file_path, "r") as file: | ||
| rclone_config_is_encrypted = yaml.full_load(file) | ||
| else: | ||
| rclone_config_is_encrypted = { | ||
| "ssh": False, | ||
| "gdrive": False, | ||
| "aws": False, | ||
| } | ||
|
|
||
| with open(self.rclone_encryption_state_file_path, "w") as file: | ||
| yaml.dump(rclone_config_is_encrypted, file) | ||
|
|
||
| return rclone_config_is_encrypted | ||
|
|
||
| def set_rclone_config_encryption_state(self, value: bool) -> None: | ||
| """Store the current state of the rclone config encryption for the `connection_method`. | ||
| Note that this is stored to disk each call (rather than tracked in memory) | ||
| to ensure it is updated properly if changed through the Python API | ||
| while the TUI is also running. | ||
| """ | ||
| assert rclone_encryption.connection_method_requires_encryption( | ||
| self.datashuttle_configs["connection_method"] | ||
| ) | ||
|
|
||
| rclone_config_is_encrypted = self.load_rclone_config_is_encrypted() | ||
|
|
||
| rclone_config_is_encrypted[ | ||
| self.datashuttle_configs["connection_method"] | ||
| ] = value | ||
|
|
||
| with open(self.rclone_encryption_state_file_path, "w") as file: | ||
| yaml.dump(rclone_config_is_encrypted, file) | ||
|
|
||
| def rclone_file_is_encrypted( | ||
| self, | ||
| ) -> bool: | ||
| """Return whether the config file associated with the current `connection_method`.""" | ||
JoeZiminski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert rclone_encryption.connection_method_requires_encryption( | ||
| self.datashuttle_configs["connection_method"] | ||
| ) | ||
|
|
||
| rclone_config_is_encrypted = self.load_rclone_config_is_encrypted() | ||
|
|
||
| return rclone_config_is_encrypted[ | ||
| self.datashuttle_configs["connection_method"] | ||
| ] | ||
|
|
||
| def get_rclone_config_name( | ||
| self, connection_method: Optional[str] = None | ||
| ) -> str: | ||
| """Generate the rclone configuration name for the central project.""" | ||
| if connection_method is None: | ||
| connection_method = self.datashuttle_configs["connection_method"] | ||
|
|
||
| return f"central_{self.datashuttle_configs.project_name}_{connection_method}" | ||
|
|
||
| def get_rclone_central_connection_config_filepath(self) -> Path: | ||
| """Return the full filepath to the rclone `.conf` config file.""" | ||
| return ( | ||
| canonical_folders.get_rclone_config_base_path() | ||
| / f"{self.get_rclone_config_name()}.conf" | ||
| ) | ||
|
|
||
| def delete_existing_rclone_config_file(self) -> None: | ||
| """Delete the Rclone config file if it exists.""" | ||
| rclone_config_filepath = ( | ||
| self.get_rclone_central_connection_config_filepath() | ||
| ) | ||
|
|
||
| if rclone_config_filepath.exists(): | ||
| rclone_config_filepath.unlink() | ||
| self.set_rclone_config_encryption_state(False) | ||
Oops, something went wrong.
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.