@@ -122,3 +122,32 @@ def stage_code_to_s3(self, directory_path, bucket_name, s3_path):
122122 self .LOGGER .info ("Credentials not available" )
123123 return
124124 self .LOGGER .info (f"Uploaded { local_path } to { bucket_name } { s3_file_path } " )
125+
126+ def download_s3_file (self , rule_name , bucket_name ):
127+ """
128+ Downloads the rule code from the staging S3 bucket.
129+
130+ :param rule_name: Name of the rule
131+ :param bucket_name: Name of the S3 bucket
132+ """
133+ self .LOGGER .info (f"Downloading { rule_name } rule code from s3..." )
134+ s3_key_template = 'rules/{rule_name}/{rule_name}.zip'
135+ local_base_path = '/tmp/sra_staging_upload'
136+
137+ s3_key = s3_key_template .format (rule_name = rule_name )
138+ local_file_path = os .path .join (local_base_path , 'rules' , rule_name , f'{ rule_name } .zip' )
139+
140+ # Ensure local directories exist
141+ os .makedirs (os .path .dirname (local_file_path ), exist_ok = True )
142+
143+ try :
144+ # Download the file from S3
145+ self .S3_CLIENT .download_file (bucket_name , s3_key , local_file_path )
146+ except NoCredentialsError :
147+ self .LOGGER .info ("Credentials not available" )
148+ return
149+ # Handle other exceptions as needed
150+ except Exception as e :
151+ self .LOGGER .info (f"Error downloading file: { e } " )
152+
153+ self .LOGGER .info (f"File downloaded successfully to { local_file_path } " )
0 commit comments