This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into support-arch-linux
- Loading branch information
Showing
12 changed files
with
290 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package redhatbase | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"os" | ||
"strings" | ||
|
||
"github.com/aquasecurity/fanal/analyzer" | ||
|
||
aos "github.com/aquasecurity/fanal/analyzer/os" | ||
"github.com/aquasecurity/fanal/types" | ||
"github.com/aquasecurity/fanal/utils" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
const almaAnalyzerVersion = 1 | ||
|
||
func init() { | ||
analyzer.RegisterAnalyzer(&almaOSAnalyzer{}) | ||
} | ||
|
||
type almaOSAnalyzer struct{} | ||
|
||
func (a almaOSAnalyzer) Analyze(target analyzer.AnalysisTarget) (*analyzer.AnalysisResult, error) { | ||
scanner := bufio.NewScanner(bytes.NewBuffer(target.Content)) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
result := redhatRe.FindStringSubmatch(strings.TrimSpace(line)) | ||
if len(result) != 3 { | ||
return nil, xerrors.New("alma: invalid almalinux-release") | ||
} | ||
|
||
switch strings.ToLower(result[1]) { | ||
case "alma", "almalinux", "alma linux": | ||
return &analyzer.AnalysisResult{ | ||
OS: &types.OS{Family: aos.Alma, Name: result[2]}, | ||
}, nil | ||
} | ||
} | ||
|
||
return nil, xerrors.Errorf("alma: %w", aos.AnalyzeOSError) | ||
} | ||
|
||
func (a almaOSAnalyzer) Required(filePath string, _ os.FileInfo) bool { | ||
return utils.StringInSlice(filePath, a.requiredFiles()) | ||
} | ||
|
||
func (a almaOSAnalyzer) requiredFiles() []string { | ||
return []string{"etc/almalinux-release"} | ||
} | ||
|
||
func (a almaOSAnalyzer) Type() analyzer.Type { | ||
return analyzer.TypeAlma | ||
} | ||
|
||
func (a almaOSAnalyzer) Version() int { | ||
return almaAnalyzerVersion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package redhatbase | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/aquasecurity/fanal/analyzer" | ||
"github.com/aquasecurity/fanal/types" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_almaOSAnalyzer_Analyze(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
inputFile string | ||
want *analyzer.AnalysisResult | ||
wantErr string | ||
}{ | ||
{ | ||
name: "happy path", | ||
inputFile: "testdata/alma/almalinux-release", | ||
want: &analyzer.AnalysisResult{ | ||
OS: &types.OS{Family: "alma", Name: "8.4"}, | ||
}, | ||
}, | ||
{ | ||
name: "sad path", | ||
inputFile: "testdata/not_redhatbase/empty", | ||
wantErr: "alma: unable to analyze OS information", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
a := almaOSAnalyzer{} | ||
b, err := os.ReadFile(tt.inputFile) | ||
require.NoError(t, err) | ||
|
||
got, err := a.Analyze(analyzer.AnalysisTarget{ | ||
FilePath: "etc/almalinux-release", | ||
Content: b, | ||
}) | ||
if tt.wantErr != "" { | ||
require.Error(t, err) | ||
assert.Contains(t, err.Error(), tt.wantErr) | ||
return | ||
} | ||
require.NoError(t, err) | ||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package redhatbase | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"os" | ||
"strings" | ||
|
||
"github.com/aquasecurity/fanal/analyzer" | ||
|
||
aos "github.com/aquasecurity/fanal/analyzer/os" | ||
"github.com/aquasecurity/fanal/types" | ||
"github.com/aquasecurity/fanal/utils" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
const rockyAnalyzerVersion = 1 | ||
|
||
func init() { | ||
analyzer.RegisterAnalyzer(&rockyOSAnalyzer{}) | ||
} | ||
|
||
type rockyOSAnalyzer struct{} | ||
|
||
func (a rockyOSAnalyzer) Analyze(target analyzer.AnalysisTarget) (*analyzer.AnalysisResult, error) { | ||
scanner := bufio.NewScanner(bytes.NewBuffer(target.Content)) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
result := redhatRe.FindStringSubmatch(strings.TrimSpace(line)) | ||
if len(result) != 3 { | ||
return nil, xerrors.New("rocky: invalid rocky-release") | ||
} | ||
|
||
switch strings.ToLower(result[1]) { | ||
case "rocky", "rocky linux": | ||
return &analyzer.AnalysisResult{ | ||
OS: &types.OS{Family: aos.Rocky, Name: result[2]}, | ||
}, nil | ||
} | ||
} | ||
|
||
return nil, xerrors.Errorf("rocky: %w", aos.AnalyzeOSError) | ||
} | ||
|
||
func (a rockyOSAnalyzer) Required(filePath string, _ os.FileInfo) bool { | ||
return utils.StringInSlice(filePath, a.requiredFiles()) | ||
} | ||
|
||
func (a rockyOSAnalyzer) requiredFiles() []string { | ||
return []string{"etc/rocky-release"} | ||
} | ||
|
||
func (a rockyOSAnalyzer) Type() analyzer.Type { | ||
return analyzer.TypeRocky | ||
} | ||
|
||
func (a rockyOSAnalyzer) Version() int { | ||
return rockyAnalyzerVersion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package redhatbase | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/aquasecurity/fanal/analyzer" | ||
"github.com/aquasecurity/fanal/types" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_rockyOSAnalyzer_Analyze(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
inputFile string | ||
want *analyzer.AnalysisResult | ||
wantErr string | ||
}{ | ||
{ | ||
name: "happy path", | ||
inputFile: "testdata/rocky/rocky-release", | ||
want: &analyzer.AnalysisResult{ | ||
OS: &types.OS{Family: "rocky", Name: "8.4"}, | ||
}, | ||
}, | ||
{ | ||
name: "sad path", | ||
inputFile: "testdata/not_redhatbase/empty", | ||
wantErr: "rocky: unable to analyze OS information", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
a := rockyOSAnalyzer{} | ||
b, err := os.ReadFile(tt.inputFile) | ||
require.NoError(t, err) | ||
|
||
got, err := a.Analyze(analyzer.AnalysisTarget{ | ||
FilePath: "etc/rocky-release", | ||
Content: b, | ||
}) | ||
if tt.wantErr != "" { | ||
require.Error(t, err) | ||
assert.Contains(t, err.Error(), tt.wantErr) | ||
return | ||
} | ||
require.NoError(t, err) | ||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
AlmaLinux release 8.4 (Electric Cheetah) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Rocky Linux release 8.4 (Green Obsidian) |
Oops, something went wrong.