Skip to content

Commit d51d94e

Browse files
committed
Some tidy up and extend use cases for new encrpytion checker.
1 parent 3b0d6ee commit d51d94e

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

datashuttle/configs/rclone_configs.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import yaml
1313

1414
from datashuttle.configs import canonical_folders
15-
from datashuttle.utils import utils
15+
from datashuttle.utils import rclone_encryption, utils
1616

1717

1818
class RCloneConfigs:
@@ -51,11 +51,9 @@ def load_rclone_config_is_encrypted(self) -> dict:
5151
called a lot, we track this explicitly when a rclone config is
5252
encrypted / unencrypted and store to disk between sessions.
5353
"""
54-
assert self.datashuttle_configs["connection_method"] in [
55-
"ssh",
56-
"aws",
57-
"gdrive",
58-
]
54+
assert rclone_encryption.connection_method_requires_encryption(
55+
self.datashuttle_configs["connection_method"]
56+
)
5957

6058
if self.rclone_encryption_state_file_path.is_file():
6159
with open(self.rclone_encryption_state_file_path, "r") as file:
@@ -78,11 +76,9 @@ def set_rclone_config_encryption_state(self, value: bool) -> None:
7876
Note that this is stored to disk each call (rather than tracked locally) to ensure
7977
it is updated live if updated through the Python API while the TUI is also running.
8078
"""
81-
assert self.datashuttle_configs["connection_method"] in [
82-
"ssh",
83-
"aws",
84-
"gdrive",
85-
]
79+
assert rclone_encryption.connection_method_requires_encryption(
80+
self.datashuttle_configs["connection_method"]
81+
)
8682

8783
rclone_config_is_encrypted = self.load_rclone_config_is_encrypted()
8884

@@ -97,11 +93,9 @@ def get_rclone_config_encryption_state(
9793
self,
9894
) -> dict:
9995
"""Return whether the config file associated with the current `connection_method`."""
100-
assert self.datashuttle_configs["connection_method"] in [
101-
"ssh",
102-
"aws",
103-
"gdrive",
104-
]
96+
assert rclone_encryption.connection_method_requires_encryption(
97+
self.datashuttle_configs["connection_method"]
98+
)
10599

106100
rclone_config_is_encrypted = self.load_rclone_config_is_encrypted()
107101

datashuttle/utils/rclone.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ def call_rclone_through_script_for_central_connection(
115115
shell=False,
116116
)
117117

118-
if cfg["connection_method"] in ["ssh", "gdrive", "aws"]:
118+
if rclone_encryption.connection_method_requires_encryption(
119+
cfg["connection_method"]
120+
):
119121
output = run_function_that_requires_encrypted_rclone_config_access(
120122
cfg, lambda_func
121123
)
@@ -553,7 +555,9 @@ def check_successful_connection_and_raise_error_on_fail(cfg: Configs) -> None:
553555

554556
def get_rclone_config_filepath(cfg: Configs) -> Path:
555557
"""Get the path to the central Rclone config for the current `connection_method`."""
556-
if cfg["connection_method"] in ["aws", "ssh", "gdrive"]:
558+
if rclone_encryption.connection_method_requires_encryption(
559+
cfg["connection_method"]
560+
):
557561
config_filepath = (
558562
cfg.rclone.get_rclone_central_connection_config_filepath()
559563
)
@@ -656,23 +660,17 @@ def transfer_data(
656660
cfg,
657661
f"{rclone_args('copy')} "
658662
f'"{local_filepath}" "{cfg.rclone.get_rclone_config_name()}:'
659-
f'{central_filepath}" {extra_arguments} {get_config_arg(cfg)} --ask-password=false', # TODO: handle the error
663+
f'{central_filepath}" {extra_arguments} {get_config_arg(cfg)} --ask-password=false',
660664
)
661665

662666
elif upload_or_download == "download":
663667
output = call_rclone_through_script_for_central_connection(
664668
cfg,
665669
f"{rclone_args('copy')} "
666670
f'"{cfg.rclone.get_rclone_config_name()}:'
667-
f'{central_filepath}" "{local_filepath}" {extra_arguments} {get_config_arg(cfg)} --ask-password=false', # TODO: handle the error
671+
f'{central_filepath}" "{local_filepath}" {extra_arguments} {get_config_arg(cfg)} --ask-password=false',
668672
)
669673

670-
if (
671-
cfg["connection_method"] in ["ssh", "aws", "gdrive"]
672-
and cfg.rclone.get_rclone_config_encryption_state()
673-
): # TODO: this is a quick and dirty fix but this MUST be handled better
674-
rclone_encryption.remove_credentials_as_password_command()
675-
676674
# 1) now 'for central connection' terminology is confused, one is for all and the other checks internally if it is aws or not. This is okay but must be consistent
677675
# 2) make a utils function to do the connection method check, this is still kind of weird / error prone
678676

0 commit comments

Comments
 (0)