Skip to content

Commit

Permalink
feat(ecosystems): support Red Hat fully (#2667)
Browse files Browse the repository at this point in the history
Red Hat records are not importing as intended, I believe this will
correct that.
  • Loading branch information
andrewpollock authored Sep 25, 2024
1 parent d4aed31 commit c6d9ca5
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 3 deletions.
5 changes: 4 additions & 1 deletion osv/ecosystems/_ecosystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .pub import Pub
from .pypi import PyPI
from .rocky_linux import RockyLinux
from .redhat import RedHat
from .rubygems import RubyGems
from .semver_ecosystem_helper import SemverEcosystem
from .ubuntu import Ubuntu
Expand Down Expand Up @@ -64,7 +65,6 @@
'Linux': OrderingUnsupportedEcosystem(),
'OSS-Fuzz': OrderingUnsupportedEcosystem(),
'Photon OS': OrderingUnsupportedEcosystem(),
'Red Hat': OrderingUnsupportedEcosystem(),
}

# Semver-based ecosystems, should correspond to _ecosystems above.
Expand Down Expand Up @@ -118,6 +118,9 @@ def get(name: str) -> Ecosystem:
if name.startswith('AlmaLinux'):
return AlmaLinux()

if name.startswith('Red Hat'):
return RedHat()

if name.startswith('Rocky Linux'):
return RockyLinux()

Expand Down
40 changes: 40 additions & 0 deletions osv/ecosystems/redhat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Red Hat Linux ecosystem helper."""

from ..third_party.univers.rpm import RpmVersion
from .helper_base import Ecosystem


class RedHat(Ecosystem):
"""Red Hat Linux ecosystem"""

@property
def name(self):
return 'Red Hat'

def sort_key(self, version):
return RpmVersion.from_string(version)

def enumerate_versions(self,
package,
introduced,
fixed=None,
last_affected=None,
limits=None):
raise NotImplementedError('Ecosystem helper does not support enumeration')

@property
def supports_comparing(self):
return True
36 changes: 36 additions & 0 deletions osv/ecosystems/redhat_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Red Hat Linux ecosystem helper tests."""

import unittest
from .. import ecosystems


class RedHatEcosystemTest(unittest.TestCase):
"""Red Hat Linux ecosystem helper tests."""

def test_redhat(self):
"""Test sort_key"""
ecosystem = ecosystems.get('Red Hat')
self.assertEqual('Red Hat', ecosystem.name)
self.assertGreater(
ecosystem.sort_key('0:0.2.6-20.module+el8.9.0+1420+91577025'),
ecosystem.sort_key('0:0.0.99.4-5.module+el8.9.0+1445+07728297'))
self.assertGreater(
ecosystem.sort_key('0:0.2.6-20.module+el8.9.0+1420+91577025'),
ecosystem.sort_key('0'))
self.assertGreater(
ecosystem.sort_key('2:1.14.3-2.module+el8.10.0+1815+5fe7415e'),
ecosystem.sort_key('2:1.10.3-1.module+el8.10.0+1815+5fe7415e'))
self.assertLess(ecosystem.sort_key('invalid'), ecosystem.sort_key('0'))
4 changes: 2 additions & 2 deletions osv/ecosystems/rocky_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@


class RockyLinux(Ecosystem):
""""Rocky Linux ecosystem"""
"""Rocky Linux ecosystem"""

@property
def name(self):
return "Rocky Linux"
return 'Rocky Linux'

def sort_key(self, version):
return RpmVersion.from_string(version)
Expand Down

0 comments on commit c6d9ca5

Please sign in to comment.