Skip to content

Commit 374cd49

Browse files
committed
fix: code format (including indentation and comment)
Signed-off-by: fengshunli <[email protected]>
1 parent 7fafc6d commit 374cd49

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

core/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func getDefaultConfig() (*Config, error) {
120120

121121
func loadConfigFile(configPath string) (*Config, error) {
122122
var (
123-
config *Config = &Config{}
123+
config = &Config{}
124124
data []byte
125125
err error
126126
)

core/lock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func getBootId() ([]byte, error) {
2525
return bootId, nil
2626
}
2727

28-
// Acquires a shared lock on the file.
28+
// LockFile Acquires a shared lock on the file.
2929
func (f *Flock) LockFile() error {
3030
f.m.Lock()
3131
defer f.m.Unlock()
@@ -51,7 +51,7 @@ func (f *Flock) LockFile() error {
5151
return nil
5252
}
5353

54-
// Releases the lock on the file.
54+
// UnlockFile Releases the lock on the file.
5555
func (f *Flock) UnlockFile() error {
5656
f.m.Lock()
5757
defer f.m.Unlock()

core/match.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ func NewMatchFile(path string) MatchFile {
1919
path = filepath.ToSlash(path)
2020
_, filename := filepath.Split(path)
2121
extension := filepath.Ext(path)
22-
// contents, _ := ioutil.ReadFile(path)
2322

2423
return MatchFile{
2524
Path: path,
@@ -29,7 +28,7 @@ func NewMatchFile(path string) MatchFile {
2928
}
3029
}
3130

32-
// IsSkippableFile Checks if the path is blacklisted
31+
// IsSkippableDir Checks if the path is blacklisted
3332
func IsSkippableDir(path string, baseDir string) bool {
3433
hostMountPath := *session.Options.HostMountPath
3534
if hostMountPath != "" {
@@ -92,8 +91,8 @@ func ContainsBlacklistedString(input []byte) bool {
9291
return false
9392
}
9493

95-
//// GetMatchingFiles Return the list of all applicable files inside the given directory for scanning
96-
//func GetMatchingFiles(dir string, baseDir string) (*bytes.Buffer, *bytes.Buffer, error) {
94+
// // GetMatchingFiles Return the list of all applicable files inside the given directory for scanning
95+
// func GetMatchingFiles(dir string, baseDir string) (*bytes.Buffer, *bytes.Buffer, error) {
9796
// findCmd := "find " + dir
9897
// for _, skippableExt := range session.Config.BlacklistedExtensions {
9998
// findCmd += " -not -name \"*" + skippableExt + "\""
@@ -110,7 +109,7 @@ func ContainsBlacklistedString(input []byte) bool {
110109
// GetSession().Log.Info("find command: %s", findCmd)
111110
//
112111
// return ExecuteCommand(findCmd)
113-
//}
112+
// }
114113

115114
// UpdateDirsPermissionsRW Update permissions for dirs in container images, so that they can be properly deleted
116115
func UpdateDirsPermissionsRW(dir string) {

core/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ func GetTmpDir(imageName string) (string, error) {
8585
dir := *session.Options.TempDirectory
8686
tempPath := filepath.Join(dir, "Deepfence", TempDirSuffix, scanId)
8787

88-
//if runtime.GOOS == "windows" {
88+
// if runtime.GOOS == "windows" {
8989
// tempPath = dir + "\temp\Deepfence\SecretScanning\df_" + scanId
90-
//}
90+
// }
9191

9292
completeTempPath := path.Join(tempPath, ExtractedImageFilesDir)
9393

signature/hs_pattens.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
// Build hyperscan Databases for matching different parts in the beginning
1111
// This can be used for repeated scanning
12+
1213
func BuildHsDb() {
1314
for _, part := range []string{ContentsPart, FilenamePart, PathPart, ExtPart} {
1415
core.GetSession().Log.Info("Creating hyperscan database for %s", part)
@@ -27,6 +28,7 @@ func BuildHsDb() {
2728
// @returns
2829
// []*hyperscan.Pattern - List of hyperscan patterns
2930
// error - Errors if any. Otherwise, returns nil
31+
3032
func CreateHsPatterns(part string) ([]*hyperscan.Pattern, error) {
3133
var hsPatterns []*hyperscan.Pattern
3234

@@ -56,6 +58,7 @@ func CreateHsPatterns(part string) ([]*hyperscan.Pattern, error) {
5658
// hsPatterns - List of hyperscan patterns
5759
// @returns
5860
// BlockDatabase - Hyperscan database for the given list of patterns
61+
5962
func CreateHsDb(hsPatterns []*hyperscan.Pattern) hyperscan.BlockDatabase {
6063
hyperscanBlockDb, err := hyperscan.NewBlockDatabase(hsPatterns...)
6164
if err != nil {
@@ -71,6 +74,7 @@ func CreateHsDb(hsPatterns []*hyperscan.Pattern) hyperscan.BlockDatabase {
7174
// hsIOData - Metadata containing the contents being matched, filename, layerID etc.
7275
// @returns
7376
// Error - Errors if any. Otherwise, returns nil
77+
7478
func RunHyperscan(hyperscanBlockDb hyperscan.BlockDatabase, hsIOData HsInputOutputData) error {
7579
hyperscanScratch, err := hyperscan.NewScratch(hyperscanBlockDb)
7680
if err != nil {

signature/signatures.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
)
2929

3030
// Data structure for passing inputs and getting outputs for hyperscan
31+
3132
type HsInputOutputData struct {
3233
inputData []byte
3334
// Avoids extra memory during blacklist comparison, reduces memory pressure
@@ -64,6 +65,7 @@ func init() {
6465
// layerID - layer ID of this file in the container image
6566
// @returns
6667
// []output.SecretFound - List of all secrets found
68+
6769
func MatchSimpleSignatures(path string, filename string, extension string, layerID string, numSecrets *uint) []output.SecretFound {
6870
var tempSecretsFound []output.SecretFound
6971
var matchingPart string
@@ -99,6 +101,7 @@ func MatchSimpleSignatures(path string, filename string, extension string, layer
99101
// @returns
100102
// []output.SecretFound - List of all secrets found
101103
// Error - Errors if any. Otherwise, returns nil
104+
102105
func MatchPatternSignatures(contents []byte, path string, filename string, extension string, layerID string,
103106
numSecrets *uint, matchedRuleSet map[uint]uint) ([]output.SecretFound, error) {
104107
var tempSecretsFound []output.SecretFound
@@ -152,6 +155,7 @@ func MatchPatternSignatures(contents []byte, path string, filename string, exten
152155
// store them in appropriate maps
153156
// @parameters
154157
// configSignatures - Extracted patterns from signature config file
158+
155159
func ProcessSignatures(configSignatures []core.ConfigSignature) {
156160
var simpleContentSignatures []core.ConfigSignature
157161
var simpleExtSignatures []core.ConfigSignature
@@ -418,7 +422,7 @@ func printMatchedSignatures(sid int, from, to int, hsIOData HsInputOutputData) (
418422
}
419423

420424
coloredMatch := fmt.Sprintf("%s%s%s\n", inputData[start:from], color.RedString(string(inputData[from:to])), inputData[to:end])
421-
//core.GetSession().Log.Info("%s%s%s\n", inputData[start:from], color.RedString(string(inputData[from:to])), inputData[to:end])
425+
// core.GetSession().Log.Info("%s%s%s\n", inputData[start:from], color.RedString(string(inputData[from:to])), inputData[to:end])
422426
core.GetSession().Log.Info(coloredMatch)
423427

424428
secret := output.SecretFound{
@@ -474,6 +478,7 @@ func calculateSeverity(inputMatch []byte, severity string, severityScore float64
474478
}
475479

476480
// Find min of 2 int values
481+
477482
func Min(value_0, value_1 int) int {
478483
if value_0 < value_1 {
479484
return value_0
@@ -482,6 +487,7 @@ func Min(value_0, value_1 int) int {
482487
}
483488

484489
// Find max of 2 int values
490+
485491
func Max(value_0, value_1 int) int {
486492
if value_0 > value_1 {
487493
return value_0

0 commit comments

Comments
 (0)