55import logging
66import os
77from pathlib import Path , PosixPath
8- from typing import Any , Dict
8+ from typing import Any , Dict , List
99
1010import yaml
1111
1717class CloudEndureConfig :
1818 """Define the CloudEndure Config object."""
1919
20+ BASE_CONFIG = {
21+ "host" : "https://console.cloudendure.com" ,
22+ "api_version" : "latest" ,
23+ "auth_ttl" : "3600" ,
24+ "username" : "" ,
25+ "password" : "" ,
26+ "token" : "" ,
27+ "user_api_token" : "" ,
28+ "session_cookie" : "" ,
29+ "project_name" : "" ,
30+ "project_id" : "" ,
31+ "max_lag_ttl" : "90" ,
32+ "machines" : "" ,
33+ "migration_wave" : "0" ,
34+ "clone_status" : "NOT_STARTED" ,
35+ "destination_account" : "" ,
36+ "disk_type" : "SSD" ,
37+ "public_ip" : "DONT_ALLOCATE" ,
38+ }
39+
2040 def __init__ (
2141 self , username : str = "" , password : str = "" , token : str = "" , * args , ** kwargs
2242 ) -> None :
@@ -37,33 +57,20 @@ def __init__(
3757 "No CloudEndure YAML configuration found! Creating it at: (%s)" ,
3858 self .config_path ,
3959 )
40- self .write_yaml_config (
41- config = {
42- "host" : "https://console.cloudendure.com" ,
43- "api_version" : "latest" ,
44- "auth_ttl" : "3600" ,
45- "username" : "" ,
46- "password" : "" ,
47- "token" : "" ,
48- "user_api_token" : "" ,
49- "session_cookie" : "" ,
50- "project_name" : "" ,
51- "project_id" : "" ,
52- "max_lag_ttl" : "90" ,
53- "machines" : "" ,
54- "migration_wave" : "0" ,
55- "clone_status" : "NOT_STARTED" ,
56- "destination_account" : "" ,
57- "disk_type" : "SSD" ,
58- "public_ip" : "DONT_ALLOCATE" ,
59- }
60- )
60+ self .write_yaml_config (config = self .BASE_CONFIG )
6161 self .update_config ()
6262
6363 def __str__ (self ) -> str :
6464 """Define the string representation of the CloudEndure API object."""
6565 return "<CloudEndureAPI>"
6666
67+ def merge_config_dicts (self , values : List [Any ]) -> Dict [str , str ]:
68+ """Merge a list of configuration dictionaries."""
69+ data : Dict [str , str ] = self .BASE_CONFIG
70+ for value in values :
71+ data .update ({k : v for k , v in value .items () if v })
72+ return data
73+
6774 def read_yaml_config (self ) -> Dict [str , Any ]:
6875 """Read the CloudEndure YAML configuration file."""
6976 logger .info ("Loading the CloudEndure YAML configuration file" )
@@ -118,11 +125,9 @@ def update_config(self) -> None:
118125 """Update the configuration."""
119126 self .yaml_config_contents : Dict [str , Any ] = self .read_yaml_config ()
120127 self .env_config = self .get_env_vars ()
121- self .active_config = {
122- ** self .yaml_config_contents ,
123- ** self .env_config ,
124- ** self .cli ,
125- }
128+ self .active_config = self .merge_config_dicts (
129+ [self .yaml_config_contents , self .env_config , self .cli ]
130+ )
126131
127132 def update_token (self , token : str ) -> bool :
128133 """Update the CloudEndure token.
0 commit comments