33# tags changes 
44
55# - remove/comment out main (only uses start_tagging_terraform_resources function) 
6+ # - removed Settings class and related methods 
67# - add "from cloudshell.iac.terraform.models.exceptions import TerraformAutoTagsError" 
78# - verify imports are the same (need to add to dependencies file if different and require specific version) 
89# - modify logger to use logger from module 
@@ -53,25 +54,6 @@ def get_exclude_from_tagging_file_path(main_folder: str):
5354# ===================================================================================================================== 
5455
5556
56- class  Settings :
57-     def  __init__ (self ,
58-                  tf_exe_path : str  =  "" ,
59-                  tf_version : str  =  "" ,
60-                  tf_module_dir_path : str  =  "" ,
61-                  tf_vars_file_path : str  =  "" ,
62-                  tags_file_path : str  =  "" ,
63-                  exclude_from_tagging_file_path : str  =  "" ):
64-         self .tf_exe_path  =  tf_exe_path 
65-         self .tf_version  =  tf_version 
66-         self .tf_module_dir_path  =  tf_module_dir_path 
67-         self .tf_vars_file_path  =  tf_vars_file_path 
68-         self .tags_file_path  =  tags_file_path 
69-         self .exclude_from_tagging_file_path  =  exclude_from_tagging_file_path 
70- 
71- 
72- # ===================================================================================================================== 
73- 
74- 
7557class  ExceptionWrapper :
7658    @staticmethod  
7759    def  wrap_class (cls ):
@@ -135,9 +117,9 @@ def write_error(msg: str, code_line: int = None):
135117        LoggerHelper .log_instance .error (f" Line { code_line }  ]:  { msg }  " )
136118
137119
138- 
139120# ===================================================================================================================== 
140121
122+ 
141123class  FileInfo :
142124    def  __init__ (self , file_path : str ):
143125        self .file_path  =  file_path 
@@ -191,13 +173,6 @@ def __init__(self, tags_dict: dict, terraform_version: str):
191173        if  not  self .torque_tags_dict :
192174            LoggerHelper .write_error (f"Didn't get tags dict, exiting the tagging process" )
193175            return 
194-         # if os.path.exists(self.torque_tags_file_path): 
195-         #     LoggerHelper.write_info(f"Reading torque tags from \"{self.torque_tags_file_path}\"") 
196-         #     self._read_and_save_tags_from_file() 
197-         # else: 
198-         #     LoggerHelper.write_error(f"\"{self.torque_tags_file_path}\" does not exists") 
199-         #     LoggerHelper.write_error(f"Could not find torque tags file, exit the tagging process") 
200-         #     exit(1) 
201176
202177        LoggerHelper .write_info (f"Initiate default tags templates" )
203178        self ._init_torque_tags_flat_map ()
@@ -628,11 +603,7 @@ def start_tagging_terraform_resources(main_dir_path: str, logger, tags_dict: dic
628603    if  not  os .path .exists (main_dir_path ):
629604        raise  TerraformAutoTagsError (f"Path { main_dir_path }   does not exist" )
630605    tfs_folder_path  =  main_dir_path 
631-     # log_path = Constants.get_override_log_path(settings.tf_module_dir_path) 
632-     # torque_tags_file_path = settings.tags_file_path 
633606    exclude_from_tagging_file_path  =  Constants .get_exclude_from_tagging_file_path (main_dir_path )
634-     # tf_exe_path = settings.tf_exe_path 
635-     # tf_vars_file_path = settings.tf_vars_file_path 
636607
637608    # modified 
638609    LoggerHelper .init_logging (logger )
@@ -735,55 +706,4 @@ def _validate_terraform_version_arg(terraform_version_arg: str) -> bool:
735706    if  len (version_arr ) !=  3 :
736707        return  False 
737708
738-     return  version_arr [0 ].isdigit () and  version_arr [1 ].isdigit ()
739- 
740- 
741- # def _try_get_settings() -> Settings: 
742- #     parser = argparse.ArgumentParser() 
743- # 
744- #     # mandatory positional arguments 
745- #     parser.add_argument('tf_version', 
746- #                         help="TF version, e.g. 0.10.0, 0.12.0, 0.15.0, ...") 
747- #     parser.add_argument('tf_module_dir_path', 
748- #                         help="path to the folder with the tf files") 
749- #     parser.add_argument('tags_file_path', 
750- #                         help="path to the json file with the tags to be applied to the module") 
751- # 
752- #     # optional named arguments 
753- #     parser.add_argument('--tf_exe_path', default="", 
754- #                         help="path to the TF executable, e.g. /usr/bin/terraform. " 
755- #                              "if not specified, PATH locations will be searched for 'terraform' exe") 
756- #     parser.add_argument('--tf_vars_file_path', default="", 
757- #                         help="path to the vars file for the module") 
758- #     parser.add_argument('--exclude_from_tagging_file_path', default="", 
759- #                         help="path to the json file with the resources to be excluded from tagging") 
760- # 
761- #     settings = Settings() 
762- #     # if invalid, will print error + usage and exit 
763- #     parser.parse_args(namespace=settings) 
764- # 
765- #     # additional validations 
766- #     if settings.tf_exe_path and not os.path.isfile(settings.tf_exe_path): 
767- #         parser.print_usage() 
768- #         print("error: tf_exe_path value is invalid") 
769- #         exit(1) 
770- # 
771- #     if not _validate_terraform_version_arg(settings.tf_version): 
772- #         parser.print_usage() 
773- #         print("error: tf_version value is invalid") 
774- #         exit(1) 
775- # 
776- #     if not os.path.isdir(settings.tf_module_dir_path): 
777- #         parser.print_usage() 
778- #         print("error: tf_module_dir_path value is invalid") 
779- #         exit(1) 
780- # 
781- #     return settings 
782- # 
783- # 
784- # modified 
785- # if __name__ == '__main__': 
786- # 
787- #     parsed_settings = _try_get_settings() 
788- # 
789- #     start_tagging_terraform_resources(settings=parsed_settings) 
709+     return  version_arr [0 ].isdigit () and  version_arr [1 ].isdigit ()
0 commit comments