|
4 | 4 | import traceback |
5 | 5 | import zipfile |
6 | 6 | from typing import List |
7 | | -from urllib.request import urlopen |
8 | 7 |
|
9 | 8 | import yaml |
| 9 | +import requests |
10 | 10 |
|
11 | 11 | from slack_watchman.loggers import JSONLogger, StdoutLogger |
12 | 12 | from slack_watchman.models.signature import Signature, create_from_dict |
@@ -34,28 +34,29 @@ def download_signatures(self) -> List[Signature]: |
34 | 34 | List[Signature]: A list of processed Signature objects. |
35 | 35 | """ |
36 | 36 | try: |
37 | | - with urlopen(SIGNATURE_URL) as response: |
38 | | - with zipfile.ZipFile(io.BytesIO(response.read())) as signatures_zip_file: |
39 | | - signature_objects = [] |
| 37 | + response = requests.get(SIGNATURE_URL, stream=True, timeout=10) |
| 38 | + response.raise_for_status() |
| 39 | + with zipfile.ZipFile(io.BytesIO(response.content)) as signatures_zip_file: |
| 40 | + signature_objects = [] |
40 | 41 |
|
41 | | - for file_path in signatures_zip_file.namelist(): |
42 | | - if file_path.endswith('/'): # Skip directories |
43 | | - continue |
| 42 | + for file_path in signatures_zip_file.namelist(): |
| 43 | + if file_path.endswith('/'): # Skip directories |
| 44 | + continue |
44 | 45 |
|
45 | | - signature_name = os.path.basename(file_path) |
46 | | - self.logger.log('DEBUG', f'Processing {file_path}...') |
| 46 | + signature_name = os.path.basename(file_path) |
| 47 | + self.logger.log('DEBUG', f'Processing {file_path}...') |
47 | 48 |
|
48 | | - with signatures_zip_file.open(file_path) as source: |
49 | | - file_content = source.read() |
| 49 | + with signatures_zip_file.open(file_path) as source: |
| 50 | + file_content = source.read() |
50 | 51 |
|
51 | | - if file_path.endswith('.yaml'): |
52 | | - processed_signatures = self._process_signature(file_content) |
53 | | - signature_objects.extend(processed_signatures) |
54 | | - self.logger.log('INFO', f'Downloaded and processed signature file: {signature_name}') |
55 | | - else: |
56 | | - self.logger.log('DEBUG', f'Skipping unrecognized file: {file_path}') |
| 52 | + if file_path.endswith('.yaml'): |
| 53 | + processed_signatures = self._process_signature(file_content) |
| 54 | + signature_objects.extend(processed_signatures) |
| 55 | + self.logger.log('INFO', f'Downloaded and processed signature file: {signature_name}') |
| 56 | + else: |
| 57 | + self.logger.log('DEBUG', f'Skipping unrecognized file: {file_path}') |
57 | 58 |
|
58 | | - return signature_objects |
| 59 | + return signature_objects |
59 | 60 |
|
60 | 61 | except Exception as e: |
61 | 62 | self.logger.log('CRITICAL', f"Error processing signature files: {e}") |
|
0 commit comments