Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: SUSE - update OSType constants and references for compatibi… #8202

Open
wants to merge 1 commit into
base: release/v0.58
Choose a base branch
from

Conversation

santhosh1729
Copy link
Contributor

  1. Renamed deprecated SUE OSType constants to maintain backward compatibility.
  2. Modified all occurrences where the old constants were used to ensure consistency

@knqyf263
Copy link
Collaborator

knqyf263 commented Jan 7, 2025

Can we just replace the legacy names with the new names in a single place? For example:

diff --git a/pkg/fanal/types/artifact.go b/pkg/fanal/types/artifact.go
index b25aaa954..18f026653 100644
--- a/pkg/fanal/types/artifact.go
+++ b/pkg/fanal/types/artifact.go
@@ -45,6 +45,14 @@ func (o *OS) Merge(newOS OS) {
                        o.Extended = true
                }
        }
+       o.Normalize()
+}
+
+// Normalize normalizes OS family names for backward compatibility
+func (o *OS) Normalize() {
+       if alias, ok := OSTypeAliases[o.Family]; ok {
+               o.Family = alias
+       }
 }

 type Repository struct {
diff --git a/pkg/fanal/types/const.go b/pkg/fanal/types/const.go
index 42f248ba1..2e07709ad 100644
--- a/pkg/fanal/types/const.go
+++ b/pkg/fanal/types/const.go
@@ -41,14 +41,17 @@ const (
        SLES               OSType = "sles"
        Ubuntu             OSType = "ubuntu"
        Wolfi              OSType = "wolfi"
-
-       // These below constants are retained for backward compatibility with older versions of Aqua
-       OpenSUSELeapLegacy       OSType = "opensuse.leap"
-       OpenSUSETumbleweedLegacy OSType = "opensuse.tumbleweed"
-       SLEMicroLegacy           OSType = "suse linux enterprise micro"
-       SLESLegacy               OSType = "suse linux enterprise server"
 )

+// OSTypeAliases is a map of aliases for operating systems.
+// This is used to map the old family names to the new ones for backward compatibility.
+var OSTypeAliases = map[OSType]OSType{
+       "opensuse.leap":                OpenSUSELeap,
+       "opensuse.tumbleweed":          OpenSUSETumbleweed,
+       "suse linux enterprise micro":  SLEMicro,
+       "suse linux enterprise server": SLES,
+}
+
 // Programming language dependencies
 const (
        Bundler        LangType = "bundler"

@santhosh1729 santhosh1729 force-pushed the sant-suse-comp branch 4 times, most recently from 2f52db6 to 2aca44f Compare January 7, 2025 12:57
@santhosh1729
Copy link
Contributor Author

Can we just replace the legacy names with the new names in a single place? For example:

diff --git a/pkg/fanal/types/artifact.go b/pkg/fanal/types/artifact.go
index b25aaa954..18f026653 100644
--- a/pkg/fanal/types/artifact.go
+++ b/pkg/fanal/types/artifact.go
@@ -45,6 +45,14 @@ func (o *OS) Merge(newOS OS) {
                        o.Extended = true
                }
        }
+       o.Normalize()
+}
+
+// Normalize normalizes OS family names for backward compatibility
+func (o *OS) Normalize() {
+       if alias, ok := OSTypeAliases[o.Family]; ok {
+               o.Family = alias
+       }
 }

 type Repository struct {
diff --git a/pkg/fanal/types/const.go b/pkg/fanal/types/const.go
index 42f248ba1..2e07709ad 100644
--- a/pkg/fanal/types/const.go
+++ b/pkg/fanal/types/const.go
@@ -41,14 +41,17 @@ const (
        SLES               OSType = "sles"
        Ubuntu             OSType = "ubuntu"
        Wolfi              OSType = "wolfi"
-
-       // These below constants are retained for backward compatibility with older versions of Aqua
-       OpenSUSELeapLegacy       OSType = "opensuse.leap"
-       OpenSUSETumbleweedLegacy OSType = "opensuse.tumbleweed"
-       SLEMicroLegacy           OSType = "suse linux enterprise micro"
-       SLESLegacy               OSType = "suse linux enterprise server"
 )

+// OSTypeAliases is a map of aliases for operating systems.
+// This is used to map the old family names to the new ones for backward compatibility.
+var OSTypeAliases = map[OSType]OSType{
+       "opensuse.leap":                OpenSUSELeap,
+       "opensuse.tumbleweed":          OpenSUSETumbleweed,
+       "suse linux enterprise micro":  SLEMicro,
+       "suse linux enterprise server": SLES,
+}
+
 // Programming language dependencies
 const (
        Bundler        LangType = "bundler"

@santhosh1729
Copy link
Contributor Author

@knqyf263 I have updated the pr with suggested changes, Thank you!!

@santhosh1729 santhosh1729 reopened this Jan 8, 2025
Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic looks good, but we need to add a test.

@santhosh1729
Copy link
Contributor Author

The logic looks good, but we need to add a test.

Sure, I will add it. Thank you!!

…lity

1. Renamed deprecated OSType constants to maintain backward compatibility.
2. Modified all occurrences where the old constants were used to ensure consistency

(cherry picked from commit 3d21d19)
@santhosh1729
Copy link
Contributor Author

The logic looks good, but we need to add a test.

@knqyf263 I have added test for the change, can you please review it once?

@santhosh1729 santhosh1729 requested a review from knqyf263 January 9, 2025 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants