MCPcopy Create free account
hub / github.com/aboutcode-org/vulnerablecode / parse_ruby_advisory

Function parse_ruby_advisory

vulnerabilities/importers/ruby.py:76–112  ·  view source on GitHub ↗

Parse a ruby advisory file and return an AdvisoryData or None. Each advisory file contains the advisory information in YAML format. Schema: https://github.com/rubysec/ruby-advisory-db/tree/master/spec/schemas

(record, schema_type, advisory_url)

Source from the content-addressed store, hash-verified

74
75
76def parse_ruby_advisory(record, schema_type, advisory_url):
77 """
78 Parse a ruby advisory file and return an AdvisoryData or None.
79 Each advisory file contains the advisory information in YAML format.
80 Schema: https://github.com/rubysec/ruby-advisory-db/tree/master/spec/schemas
81 """
82 if schema_type == "gems":
83 package_name = record.get("gem")
84
85 if not package_name:
86 logger.error("Invalid package name")
87 else:
88 purl = PackageURL(type="gem", name=package_name)
89
90 return AdvisoryData(
91 aliases=get_aliases(record),
92 summary=get_summary(record),
93 affected_packages=get_affected_packages(record, purl),
94 references=get_references(record),
95 date_published=get_publish_time(record),
96 url=advisory_url,
97 )
98
99 elif schema_type == "rubies":
100 engine = record.get("engine") # engine enum: [jruby, rbx, ruby]
101 if not engine:
102 logger.error("Invalid engine name")
103 else:
104 purl = PackageURL(type="ruby", name=engine)
105 return AdvisoryData(
106 aliases=get_aliases(record),
107 summary=get_summary(record),
108 affected_packages=get_affected_packages(record, purl),
109 references=get_references(record),
110 date_published=get_publish_time(record),
111 url=advisory_url,
112 )
113
114
115def get_affected_packages(record, purl):

Callers 2

test_advisoriesFunction · 0.90
advisory_dataMethod · 0.70

Calls 7

AdvisoryDataClass · 0.90
get_aliasesFunction · 0.70
get_summaryFunction · 0.70
get_affected_packagesFunction · 0.70
get_referencesFunction · 0.70
get_publish_timeFunction · 0.70
getMethod · 0.45

Tested by 1

test_advisoriesFunction · 0.72