Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Jeff MAURY <[email protected]>
  • Loading branch information
feloy and jeffmaury authored Nov 20, 2023
1 parent 41aa515 commit 8cf00d5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions pkg/cli/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ To find out more, run 'doa %s --help'
`, command, command)
}

func PrintPrettifyJsonOutput(errs []analyzer.Result) {
func PrintPrettifyJsonOutput(results []analyzer.Result) {
var bytes []byte
var err error
if bytes, err = json.MarshalIndent(errs, "", " "); err != nil {
if bytes, err = json.MarshalIndent(results, "", " "); err != nil {
fmt.Println("error while converting output to json. Please try again without the output (--o) flag")
}
fmt.Println(string(bytes))
}

func PrintPrettifyOutput(errs []analyzer.Result) {
func PrintPrettifyOutput(results []analyzer.Result) {
for i, sug := range errs {
fmt.Printf("%d - %s (%s): %s\n\n", i+1, sug.Name, sug.Severity, sug.Description)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/command/expose.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ type Expose struct {
}

func (e Expose) Analyze(node *parser.Node, source utils.Source, line Line) []Result {
errs := []Result{}
results := []Result{}
str := node.Value
index := strings.IndexByte(node.Value, '/')
if index >= 0 {
str = node.Value[0:index]
}
port, err := strconv.Atoi(str)
if err != nil {
errs = append(errs, Result{
results = append(results, Result{
Name: "Wrong port value",
Status: StatusFailed,
Severity: SeverityCritical,
Description: err.Error(),
})
}
if port < 1024 {
errs = append(errs, Result{
results = append(results, Result{
Name: "Privileged port exposed",
Status: StatusFailed,
Severity: SeverityHigh,
Expand Down
4 changes: 2 additions & 2 deletions pkg/command/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func (f From) Analyze(node *parser.Node, source utils.Source, line Line) []Resul
if node.Value == SCRATCH_IMAGE_NAME {
return nil
}
errs := []Result{}
results := []Result{}
decompiledNode, err := decompiler.Decompile(node.Value)
if err != nil {
// unable to decompile base image
errs = append(errs, Result{
results = append(results, Result{
Name: "Analyze error",
Status: StatusFailed,
Severity: SeverityLow,
Expand Down
6 changes: 3 additions & 3 deletions pkg/command/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ import (
type Run struct{}

func (r Run) Analyze(node *parser.Node, source utils.Source, line Line) []Result {
errs := []Result{}
results := []Result{}

// let's split the run command by &&. E.g chmod 070 /app && chmod 070 /app/routes && chmod 070 /app/bin
splittedCommands := strings.Split(node.Value, "&&")
for _, command := range splittedCommands {
if r.isChmodCommand(command) {
err := r.analyzeChmodCommand(command, source, line)
if err != nil {
errs = append(errs, *err)
results = append(results, *err)
}
} else if r.isChownCommand(command) {
err := r.analyzeChownCommand(command, source, line)
if err != nil {
errs = append(errs, *err)
results = append(results, *err)
}
} else if r.isSudoOrSuCommand(command) {
err := r.analyzeSudoAndSuCommand(command, source, line)
Expand Down

0 comments on commit 8cf00d5

Please sign in to comment.