1+ # Copyright (c) 2017 nexB Inc. and others. All rights reserved.
2+ # http://nexb.com and https://github.com/nexB/vulnerablecode/
3+ # The VulnerableCode software is licensed under the Apache License version 2.0.
4+ # Data generated with VulnerableCode require an acknowledgment.
5+ #
6+ # You may not use this software except in compliance with the License.
7+ # You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
8+ # Unless required by applicable law or agreed to in writing, software distributed
9+ # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10+ # CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+ # specific language governing permissions and limitations under the License.
12+ #
13+ # When you publish or redistribute any data created with VulnerableCode or any VulnerableCode
14+ # derivative work, you must accompany this data with the following acknowledgment:
15+ #
16+ # Generated with VulnerableCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
17+ # OR CONDITIONS OF ANY KIND, either express or implied. No content created from
18+ # VulnerableCode should be considered or used as legal advice. Consult an Attorney
19+ # for any legal advice.
20+ # VulnerableCode is a free software code scanning tool from nexB Inc. and others.
21+ # Visit https://github.com/nexB/vulnerablecode/ for support and download.
22+
123from json import JSONDecodeError
224from typing import Set
325from typing import List
1234from vulnerabilities .data_source import GitDataSource
1335
1436
15- class rubyDataSource (GitDataSource ):
37+ class RubyDataSource (GitDataSource ):
1638
1739 def __enter__ (self ):
18- super (rubyDataSource , self ).__enter__ ()
40+ super (RubyDataSource , self ).__enter__ ()
1941
2042 if not getattr (self , '_added_files' , None ):
2143 self ._added_files , self ._updated_files = self .file_changes (
2244 recursive = True , file_ext = 'yml' , subdir = './gems' )
2345
2446 def updated_advisories (self ) -> Set [Advisory ]:
25- files = self ._updated_files .union (self ._added_files )
47+ files = self ._updated_files
48+ advisories = []
49+ for f in files :
50+ processed_data = self .process_file (f )
51+ if processed_data :
52+ advisories .append (processed_data )
53+ return self .batch_advisories (advisories )
54+
55+ def added_advisories (self ) -> Set [Advisory ]:
56+ files = self ._added_files
2657 advisories = []
2758 for f in files :
2859 processed_data = self .process_file (f )
@@ -77,7 +108,7 @@ def process_file(self, path) -> List[Advisory]:
77108 summary = record .get ('description' , '' ),
78109 impacted_package_urls = impacted_purls ,
79110 resolved_package_urls = resolved_purls ,
80- reference_urls = record .get ('url' , '' ),
111+ reference_urls = [ record .get ('url' , '' )] ,
81112 cve_id = cve_id
82113 )
83114
@@ -108,6 +139,7 @@ class rubyAPI:
108139
109140 def __init__ (self ):
110141 self .client = requests .Session ()
142+ self .cache = {}
111143
112144 def call_api (self , pkg_name ) -> List :
113145 end_pt = self .base_endpt .format (pkg_name )
@@ -120,7 +152,11 @@ def call_api(self, pkg_name) -> List:
120152
121153 def get_all_version_of_package (self , pkg_name ) -> Set [str ]:
122154 all_versions = set ()
155+ if self .cache .get (pkg_name ):
156+ return self .cache .get (pkg_name )
157+
123158 json_resp = self .call_api (pkg_name )
124159 for release in json_resp :
125160 all_versions .add (release ['number' ])
161+ self .cache [pkg_name ] = all_versions
126162 return all_versions
0 commit comments