From 2ebc21045d5584e61e192bc545d24c8a8653c44c Mon Sep 17 00:00:00 2001 From: Holly Gong <39108850+hogo6002@users.noreply.github.com> Date: Thu, 29 Aug 2024 14:00:46 +1000 Subject: [PATCH] feat: support non-enumerated ecosystem version queries on prod instance (#2530) Issue: https://github.com/google/osv.dev/issues/2401 Enable API queries for specific versions in non-enumerated ecosystems (Rocky Linux, AlmaLinux, Chainguard, and Wolfi) on the production instance. This change will not affect queries for other ecosystems. --- gcp/api/server.py | 7 ++----- osv/ecosystems/alma_linux.py | 4 ++++ osv/ecosystems/chainguard.py | 4 ++++ osv/ecosystems/helper_base.py | 6 ++++++ osv/ecosystems/rocky_linux.py | 4 ++++ osv/ecosystems/wolfi.py | 4 ++++ 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/gcp/api/server.py b/gcp/api/server.py index 30418f905d7..8ace8bf97d5 100644 --- a/gcp/api/server.py +++ b/gcp/api/server.py @@ -1185,10 +1185,9 @@ def query_by_version(context: QueryContext, ecosystem_info = ecosystems.get(ecosystem) is_semver = ecosystem_info and ecosystem_info.is_semver - supports_ordering = ecosystem_info and ecosystem_info.supports_ordering + supports_comparing = ecosystem_info and ecosystem_info.supports_comparing bugs = [] - project = get_gcp_project() if ecosystem: if is_semver: # Ecosystem supports semver only. @@ -1202,10 +1201,8 @@ def query_by_version(context: QueryContext, for bug in new_bugs: if bug not in bugs: bugs.append(bug) - - elif project == 'oss-vdb-test' and supports_ordering: + elif supports_comparing: # Query for non-enumerated ecosystems. - bugs = yield _query_by_comparing_versions(context, query, ecosystem, version) else: diff --git a/osv/ecosystems/alma_linux.py b/osv/ecosystems/alma_linux.py index b1ae65ad338..2828e23acbb 100644 --- a/osv/ecosystems/alma_linux.py +++ b/osv/ecosystems/alma_linux.py @@ -31,3 +31,7 @@ def enumerate_versions(self, last_affected=None, limits=None): raise NotImplementedError('Ecosystem helper does not support enumeration') + + @property + def supports_comparing(self): + return True diff --git a/osv/ecosystems/chainguard.py b/osv/ecosystems/chainguard.py index a25ddbe9013..ab8a5150d1e 100644 --- a/osv/ecosystems/chainguard.py +++ b/osv/ecosystems/chainguard.py @@ -35,3 +35,7 @@ def enumerate_versions(self, last_affected=None, limits=None): raise NotImplementedError('Ecosystem helper does not support enumeration') + + @property + def supports_comparing(self): + return True diff --git a/osv/ecosystems/helper_base.py b/osv/ecosystems/helper_base.py index 248971e8184..7ede5fd8f0f 100644 --- a/osv/ecosystems/helper_base.py +++ b/osv/ecosystems/helper_base.py @@ -118,6 +118,12 @@ def is_semver(self): def supports_ordering(self): return True + @property + def supports_comparing(self): + """Determines whether to use affected version range comparison + for API queries.""" + return False + class OrderingUnsupportedEcosystem(Ecosystem): """Placeholder ecosystem helper for unimplemented ecosystems.""" diff --git a/osv/ecosystems/rocky_linux.py b/osv/ecosystems/rocky_linux.py index 956f151bae9..d283067b553 100644 --- a/osv/ecosystems/rocky_linux.py +++ b/osv/ecosystems/rocky_linux.py @@ -34,3 +34,7 @@ def enumerate_versions(self, last_affected=None, limits=None): raise NotImplementedError('Ecosystem helper does not support enumeration') + + @property + def supports_comparing(self): + return True diff --git a/osv/ecosystems/wolfi.py b/osv/ecosystems/wolfi.py index cf6d9835acb..6d64a9629b0 100644 --- a/osv/ecosystems/wolfi.py +++ b/osv/ecosystems/wolfi.py @@ -36,3 +36,7 @@ def enumerate_versions(self, last_affected=None, limits=None): raise NotImplementedError('Ecosystem helper does not support enumeration') + + @property + def supports_comparing(self): + return True