forked from goodwithtech/dockle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new checkpoint : Only put necessary files (goodwithtech#54)
* use goodwithtech/deckoder and unuse xerrors * check unnecessary files * update ci goversion * fix lint * improve how to check required directory * create DockerOption from cli args * add scan test
- Loading branch information
1 parent
e2a12fa
commit fe3c549
Showing
25 changed files
with
299 additions
and
106 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
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,86 @@ | ||
package cache | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/goodwithtech/deckoder/utils" | ||
|
||
"github.com/goodwithtech/deckoder/extractor" | ||
"github.com/goodwithtech/dockle/pkg/log" | ||
"github.com/goodwithtech/dockle/pkg/types" | ||
) | ||
|
||
var ( | ||
reqFiles = []string{"Dockerfile", "docker-compose.yml", ".vimrc"} | ||
// Directory ends "/" separator | ||
reqDirs = []string{".cache/", "tmp/", ".git/", ".vscode/", ".idea/", ".npm/"} | ||
uncontrollableDirs = []string{"node_modules/", "vendor/"} | ||
detectedDir = map[string]struct{}{} | ||
) | ||
|
||
type CacheAssessor struct{} | ||
|
||
func (a CacheAssessor) Assess(fileMap extractor.FileMap) ([]*types.Assessment, error) { | ||
log.Logger.Debug("Start scan : cache files") | ||
assesses := []*types.Assessment{} | ||
for filename := range fileMap { | ||
fileBase := filepath.Base(filename) | ||
dirName := filepath.Dir(filename) | ||
dirBase := filepath.Base(dirName) | ||
|
||
// match Directory | ||
if utils.StringInSlice(dirBase+"/", reqDirs) || utils.StringInSlice(dirName+"/", reqDirs) { | ||
if _, ok := detectedDir[dirName]; ok { | ||
continue | ||
} | ||
detectedDir[dirName] = struct{}{} | ||
|
||
// Skip uncontrollable dependency directory e.g) npm : node_modules, php: composer | ||
if inIgnoreDir(filename) { | ||
continue | ||
} | ||
|
||
assesses = append( | ||
assesses, | ||
&types.Assessment{ | ||
Type: types.InfoDeletableFiles, | ||
Filename: dirName, | ||
Desc: fmt.Sprintf("Suspitcious directory : %s ", dirName), | ||
}) | ||
|
||
} | ||
|
||
// match File | ||
if utils.StringInSlice(filename, reqFiles) || utils.StringInSlice(fileBase, reqFiles) { | ||
assesses = append( | ||
assesses, | ||
&types.Assessment{ | ||
Type: types.InfoDeletableFiles, | ||
Filename: filename, | ||
Desc: fmt.Sprintf("unnecessary file : %s ", filename), | ||
}) | ||
} | ||
} | ||
return assesses, nil | ||
} | ||
|
||
// check and register uncontrollable directory e.g) npm : node_modules, php: composer | ||
func inIgnoreDir(filename string) bool { | ||
for _, ignoreDir := range uncontrollableDirs { | ||
if strings.Contains(filename, ignoreDir) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func (a CacheAssessor) RequiredFiles() []string { | ||
return append(reqFiles, reqDirs...) | ||
} | ||
|
||
func (a CacheAssessor) RequiredPermissions() []os.FileMode { | ||
return []os.FileMode{} | ||
} |
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
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
Oops, something went wrong.