@@ -123,8 +123,7 @@ def create_sbom_output(self, diff: Diff) -> dict:
123
123
log .error (result .get ("message" , "No error message provided" ))
124
124
return {}
125
125
126
- @staticmethod
127
- def find_files (path : str ) -> List [str ]:
126
+ def find_files (self , path : str ) -> List [str ]:
128
127
"""
129
128
Finds supported manifest files in the given path.
130
129
@@ -138,10 +137,19 @@ def find_files(path: str) -> List[str]:
138
137
start_time = time .time ()
139
138
files = set ()
140
139
141
- for ecosystem in socket_globs :
142
- patterns = socket_globs [ecosystem ]
143
- for file_name in patterns :
144
- pattern = Core .to_case_insensitive_regex (patterns [file_name ]["pattern" ])
140
+ # Get supported patterns from the API
141
+ try :
142
+ patterns = self .get_supported_patterns ()
143
+ except Exception as e :
144
+ log .error (f"Error getting supported patterns from API: { e } " )
145
+ log .warning ("Falling back to local patterns" )
146
+ from .utils import socket_globs as fallback_patterns
147
+ patterns = fallback_patterns
148
+
149
+ for ecosystem in patterns :
150
+ ecosystem_patterns = patterns [ecosystem ]
151
+ for file_name in ecosystem_patterns :
152
+ pattern = Core .to_case_insensitive_regex (ecosystem_patterns [file_name ]["pattern" ])
145
153
file_path = f"{ path } /**/{ pattern } "
146
154
#log.debug(f"Globbing {file_path}")
147
155
glob_start = time .time ()
@@ -164,6 +172,57 @@ def find_files(path: str) -> List[str]:
164
172
log .debug (f"{ len (files_list )} Files found ({ total_time :.2f} s): { ', ' .join (files_list )} " )
165
173
return list (files )
166
174
175
+ def get_supported_patterns (self ) -> Dict :
176
+ """
177
+ Gets supported file patterns from the Socket API.
178
+
179
+ Returns:
180
+ Dictionary of supported file patterns with 'general' key removed
181
+ """
182
+ response = self .sdk .report .supported ()
183
+ if not response :
184
+ log .error ("Failed to get supported patterns from API" )
185
+ # Import the old patterns as fallback
186
+ from .utils import socket_globs
187
+ return socket_globs
188
+
189
+ # Remove the 'general' key if it exists
190
+ if 'general' in response :
191
+ response .pop ('general' )
192
+
193
+ # The response is already in the format we need
194
+ return response
195
+
196
+ def has_manifest_files (self , files : list ) -> bool :
197
+ """
198
+ Checks if any files in the list are supported manifest files.
199
+
200
+ Args:
201
+ files: List of file paths to check
202
+
203
+ Returns:
204
+ True if any files match manifest patterns, False otherwise
205
+ """
206
+ # Get supported patterns
207
+ try :
208
+ patterns = self .get_supported_patterns ()
209
+ except Exception as e :
210
+ log .error (f"Error getting supported patterns from API: { e } " )
211
+ log .warning ("Falling back to local patterns" )
212
+ from .utils import socket_globs as fallback_patterns
213
+ patterns = fallback_patterns
214
+
215
+ for ecosystem in patterns :
216
+ ecosystem_patterns = patterns [ecosystem ]
217
+ for file_name in ecosystem_patterns :
218
+ pattern_str = ecosystem_patterns [file_name ]["pattern" ]
219
+ for file in files :
220
+ if "\\ " in file :
221
+ file = file .replace ("\\ " , "/" )
222
+ if PurePath (file ).match (pattern_str ):
223
+ return True
224
+ return False
225
+
167
226
@staticmethod
168
227
def to_case_insensitive_regex (input_string : str ) -> str :
169
228
"""
@@ -740,28 +799,6 @@ def save_file(file_name: str, content: str) -> None:
740
799
log .error (f"Failed to save file { file_name } : { e } " )
741
800
raise
742
801
743
- @staticmethod
744
- def has_manifest_files (files : list ) -> bool :
745
- """
746
- Checks if any files in the list are supported manifest files.
747
-
748
- Args:
749
- files: List of file paths to check
750
-
751
- Returns:
752
- True if any files match manifest patterns, False otherwise
753
- """
754
- for ecosystem in socket_globs :
755
- patterns = socket_globs [ecosystem ]
756
- for file_name in patterns :
757
- pattern = patterns [file_name ]["pattern" ]
758
- for file in files :
759
- if "\\ " in file :
760
- file = file .replace ("\\ " , "/" )
761
- if PurePath (file ).match (pattern ):
762
- return True
763
- return False
764
-
765
802
@staticmethod
766
803
def get_capabilities_for_added_packages (added_packages : Dict [str , Package ]) -> Dict [str , List [str ]]:
767
804
"""
0 commit comments