@@ -543,11 +543,9 @@ def set_credentials(self, aws: 'AWSBoto'):
543
543
# Get the default credentials directory from the config file
544
544
default_credentials_dir = self .__get_configuration_entry (
545
545
'CREDENTIALS' , 'credentials_dir' )
546
- if default_credentials_dir is None :
547
- default_credentials_dir = os .path .join ('~' , '.aws' )
548
- if not os .path .exists (os .path .expanduser (default_credentials_dir )):
549
- os .makedirs (os .path .expanduser (default_credentials_dir ),
550
- exist_ok = True , mode = 0o775 )
546
+
547
+ if not os .path .exists (default_credentials_dir ):
548
+ default_credentials_dir = None
551
549
552
550
# Ask user to enter the path to a aws credentials directory
553
551
credentials_dir_question = [
@@ -912,10 +910,17 @@ def set_email(self):
912
910
try :
913
911
log (f'\n *** SET EMAIL ***\n ' )
914
912
913
+ default_email = self .__get_configuration_entry ('USER' , 'email' )
914
+
915
+ # Email pattern
916
+ pattern = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
917
+ if re .match (pattern , default_email ) is None :
918
+ default_email = None
919
+
915
920
# Ask the user for their email
916
921
email = inquirer .text (
917
922
message = "Enter your email" ,
918
- default = self . __get_configuration_entry ( 'USER' , 'email' ) ,
923
+ default = default_email ,
919
924
validate = self .__inquirer_check_email_format )
920
925
921
926
# Print for a new line when prompting
@@ -946,10 +951,16 @@ def set_endpoint(self):
946
951
elif self .provider == 'GCS' :
947
952
endpoint = 'https://storage.googleapis.com'
948
953
else :
954
+ default_endpoint = self .__get_configuration_entry (
955
+ 'S3' , 'endpoint' , fallback = None )
956
+
957
+ if default_endpoint == '' :
958
+ default_endpoint = None
959
+
949
960
# Get the user answer
950
961
endpoint = inquirer .text (
951
962
message = f'Enter the { self .provider } endpoint' ,
952
- default = self . __get_configuration_entry ( 'S3' , 'endpoint' ) ,
963
+ default = default_endpoint ,
953
964
validate = self .__inquirer_check_required )
954
965
955
966
# Ensure the endpoint starts with "https://" for IDrive
@@ -997,11 +1008,16 @@ def set_provider(self):
997
1008
list_of_providers = PROVIDERS_LIST
998
1009
list_of_providers .append ('+ Create new provider' )
999
1010
1011
+ default_provider = self .__get_configuration_entry (
1012
+ 'S3' , 'provider' , fallback = 'AWS' )
1013
+
1014
+ if default_provider == '' :
1015
+ default_provider = None
1016
+
1000
1017
# Get the user answer
1001
1018
provider = inquirer .list_input (
1002
1019
"Choose your s3 provider" ,
1003
- default = self .__get_configuration_entry (
1004
- 'S3' , 'provider' , fallback = 'AWS' ),
1020
+ default = default_provider ,
1005
1021
choices = list_of_providers )
1006
1022
1007
1023
if provider == '+ Create new provider' :
@@ -1061,10 +1077,15 @@ def set_s3(self, aws: "AWSBoto"):
1061
1077
# Store aws s3 bucket in the config object
1062
1078
self .__set_configuration_entry ('S3' , 'bucket_name' , s3_bucket )
1063
1079
1080
+ default_archive_dir = self .__get_configuration_entry ('S3' , 'archive_dir' , fallback = 'froster' )
1081
+
1082
+ if default_archive_dir == '' :
1083
+ default_archive_dir = 'froster'
1084
+
1064
1085
# Get user answer
1065
1086
archive_dir = inquirer .text (
1066
1087
message = 'Enter the directory name inside S3 bucket' ,
1067
- default = self . __get_configuration_entry ( 'S3' , 'archive_dir' , fallback = 'froster' ) ,
1088
+ default = default_archive_dir ,
1068
1089
validate = self .__inquirer_check_required )
1069
1090
1070
1091
# Print newline after this prompt
@@ -1076,6 +1097,9 @@ def set_s3(self, aws: "AWSBoto"):
1076
1097
default_storage_class = self .__get_configuration_entry (
1077
1098
'S3' , 'storage_class' , fallback = 'DEEP_ARCHIVE' )
1078
1099
1100
+ if default_storage_class == '' :
1101
+ default_storage_class = None
1102
+
1079
1103
if self .provider == 'AWS' :
1080
1104
storage_class = inquirer .list_input (
1081
1105
"Choose the AWS S3 storage class" ,
@@ -1146,13 +1170,18 @@ def set_shared(self):
1146
1170
# and check if we need to move cfg.archive_json_file_name and configuration to the shared directory
1147
1171
if is_shared :
1148
1172
1173
+ default_shared_dir = self .__get_configuration_entry (
1174
+ 'SHARED' , 'shared_dir' , fallback = None )
1175
+
1176
+ if default_shared_dir == '' :
1177
+ default_shared_dir = None
1178
+
1149
1179
# Ask user to enter the path to a shared config directory
1150
1180
# TODO: make this inquiring in shortchut mode once this PR is merged: https://github.com/magmax/python-inquirer/pull/543
1151
1181
shared_config_dir_question = [
1152
1182
inquirer .Path (
1153
1183
'shared_dir' , message = 'Enter the path to a shared config directory' ,
1154
- default = self .__get_configuration_entry (
1155
- 'SHARED' , 'shared_dir' , fallback = None ),
1184
+ default = default_shared_dir ,
1156
1185
validate = self .__inquirer_check_path_exists )
1157
1186
]
1158
1187
0 commit comments