55import json
66import os
77from pathlib import Path
8- from typing import Dict , Optional , Tuple , List
9-
10- from dotenv import load_dotenv
11- from rich import print
12- from rich .prompt import Prompt
13-
14- from .exceptions import (
15- ConfigurationError ,
16- CredentialsError ,
17- SMTPConfigError ,
18- FileOperationError ,
19- )
8+ from typing import Any , Dict , List , Optional , Tuple
9+
10+ from .exceptions import SMTPConfigError
2011from .security import SecureConfig
2112
2213CONFIG_DIR = os .path .expanduser ("~/.config/openstack-toolbox" )
@@ -49,7 +40,7 @@ def get_language_preference() -> str:
4940 with open (CONFIG_FILE , "r" , encoding = "utf-8" ) as f :
5041 config = json .load (f )
5142 return config .get ("language" , "fr" )
52- except (OSError , IOError , json .JSONDecodeError ) as e :
43+ except (OSError , IOError , json .JSONDecodeError ):
5344 # Log error but return default
5445 pass
5546 return "fr"
@@ -85,7 +76,7 @@ def set_language_preference(lang: str) -> bool:
8576 with open (CONFIG_FILE , "w" , encoding = "utf-8" ) as f :
8677 json .dump (config , f , indent = 4 )
8778 return True
88- except (OSError , IOError , json .JSONDecodeError ) as e :
79+ except (OSError , IOError , json .JSONDecodeError ):
8980 return False
9081
9182
@@ -122,16 +113,16 @@ def create_smtp_config_interactive() -> bool:
122113 True
123114 """
124115 config = configparser .ConfigParser ()
125-
116+
126117 server = input ("Serveur SMTP [smtp.gmail.com]: " ).strip () or "smtp.gmail.com"
127118 port = input ("Port SMTP [587]: " ).strip () or "587"
128119 username = input ("Utilisateur SMTP: " ).strip ()
129120 password = getpass .getpass ("Mot de passe SMTP: " ).strip ()
130-
121+
131122 # Encrypt password for security
132123 secure = SecureConfig (Path (CONFIG_DIR ))
133124 encrypted_password = secure .encrypt (password )
134-
125+
135126 config ["SMTP" ] = {
136127 "server" : server ,
137128 "port" : port ,
@@ -142,7 +133,7 @@ def create_smtp_config_interactive() -> bool:
142133
143134 from_email = input (f"Email expéditeur [{ username } ]: " ).strip () or username
144135 to_email = input ("Email destinataire: " ).strip ()
145-
136+
146137 config ["Email" ] = {
147138 "from" : from_email ,
148139 "to" : to_email ,
@@ -158,7 +149,7 @@ def create_smtp_config_interactive() -> bool:
158149 raise SMTPConfigError (f"Failed to save SMTP configuration: { e } " ) from e
159150
160151
161- def load_smtp_config () -> Optional [Dict [str , any ]]:
152+ def load_smtp_config () -> Optional [Dict [str , Any ]]:
162153 """
163154 Charge la configuration SMTP depuis le fichier de configuration.
164155
@@ -192,7 +183,7 @@ def load_smtp_config() -> Optional[Dict[str, any]]:
192183
193184 password = config ["SMTP" ]["password" ]
194185 is_encrypted = config ["SMTP" ].get ("encrypted" , "false" ) == "true"
195-
186+
196187 # Decrypt password if it's encrypted
197188 if is_encrypted :
198189 secure = SecureConfig (Path (CONFIG_DIR ))
@@ -207,27 +198,23 @@ def load_smtp_config() -> Optional[Dict[str, any]]:
207198 "to_email" : config ["Email" ]["to" ],
208199 }
209200 except (KeyError , ValueError , configparser .Error ) as e :
210- raise SMTPConfigError (
211- f"Invalid SMTP configuration file: { e } "
212- ) from e
201+ raise SMTPConfigError (f"Invalid SMTP configuration file: { e } " ) from e
213202 except Exception as e :
214- raise SMTPConfigError (
215- f"Failed to load SMTP configuration: { e } "
216- ) from e
203+ raise SMTPConfigError (f"Failed to load SMTP configuration: { e } " ) from e
217204
218205
219206def load_openstack_credentials () -> Tuple [Optional [Dict [str , str ]], List [str ]]:
220207 """
221208 Charge les identifiants OpenStack depuis les variables d'environnement.
222-
209+
223210 Returns:
224211 Tuple contenant:
225212 - Dict des credentials si toutes les variables sont présentes, None sinon
226213 - Liste des variables manquantes
227-
214+
228215 Raises:
229216 CredentialsError: Si les variables critiques sont manquantes
230-
217+
231218 Examples:
232219 >>> creds, missing = load_openstack_credentials()
233220 >>> if creds:
0 commit comments