77from configs .config_class import Configs
88
99from datashuttle .configs import canonical_folders
10+ from datashuttle .utils import utils
1011
1112
1213def get_password_filepath (
@@ -47,6 +48,7 @@ def save_credentials_password(cfg):
4748 )
4849
4950 # run it
51+ # TODO: HANDLE ERRORS
5052 subprocess .run ([shell , "-NoProfile" , "-Command" , ps_cmd ], check = True )
5153
5254 elif platform .system () == "Linux" :
@@ -58,6 +60,7 @@ def save_credentials_password(cfg):
5860 )
5961
6062 try :
63+ # TODO: HANDLE ERRORS
6164 result = subprocess .run (
6265 ["pass" , "ls" ], capture_output = True , text = True , check = True
6366 )
@@ -66,6 +69,7 @@ def save_credentials_password(cfg):
6669 raise Exception () # re-raise unexpected errors
6770
6871 breakpoint ()
72+ # TODO: HANDLE ERRORS
6973 subprocess .run (
7074 f"echo $(openssl rand -base64 40) | pass insert -m { cfg .get_rclone_config_name ()} " ,
7175 shell = True ,
@@ -74,6 +78,7 @@ def save_credentials_password(cfg):
7478
7579 # TODO: HANDLE ERRORS
7680 else :
81+ # TODO: HANDLE ERRORS
7782 subprocess .run (
7883 f"security add-generic-password -a datashuttle -s { cfg .get_rclone_config_name ()} -w $(openssl rand -base64 40) -U" ,
7984 shell = True ,
@@ -123,28 +128,48 @@ def set_credentials_as_password_command(cfg):
123128
124129def run_rclone_config_encrypt (cfg : Configs ):
125130 """"""
131+ rclone_config_path = cfg .get_rclone_config_filepath ()
132+
133+ if not rclone_config_path .exists ():
134+ connection_method = cfg ["connection_method" ]
135+
136+ raise RuntimeError (
137+ f"Rclone config file for: { connection_method } was not found. "
138+ f"Make sure you set up the connection first with `setup_{ connection_method } _connection()`"
139+ )
140+
141+ save_credentials_password (cfg )
142+
126143 set_credentials_as_password_command (cfg )
127144
145+ # TODO: HANDLE ERRORS
128146 subprocess .run (
129- f"rclone config encryption set --config { config_filepath .as_posix ()} " ,
147+ f"rclone config encryption set --config { rclone_config_path .as_posix ()} " ,
130148 shell = True ,
131149 )
132150
133151 remove_credentials_as_password_command ()
134152
135153
136154# TODO: HANDLE ERRORS
137- def remove_rclone_password (password_filepath : Path , config_filepath : Path ):
155+ def remove_rclone_password (cfg ):
138156 """"""
139- set_credentials_as_password_command (Path (password_filepath ))
157+ set_credentials_as_password_command (Path (cfg ))
158+
159+ config_filepath = cfg .get_rclone_config_filepath ()
160+
161+ # TODO: HANDLE ERRORS
140162 subprocess .run (
141163 rf"rclone config encryption remove --config { config_filepath .as_posix ()} " ,
142164 shell = True ,
143165 )
144166
145- # TODO: HANDLE ERRORS
146167 remove_credentials_as_password_command ()
147168
169+ utils .log_and_message (
170+ f"Password removed from rclone config file: { config_filepath } "
171+ )
172+
148173
149174def remove_credentials_as_password_command ():
150175 if "RCLONE_PASSWORD_COMMAND" in os .environ :
0 commit comments