Skip to content

Commit

Permalink
Add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea committed Sep 27, 2023
1 parent 3df21ac commit a412623
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions xray/commands/scan/dockerscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (dsc *DockerScanCommand) SetTargetRepoPath(repoPath string) *DockerScanComm
return dsc
}

// Docker scan will save a docker image as .tar file and will prefore binary scan on it.
func (dsc *DockerScanCommand) Run() (err error) {
// Validate Xray minimum version
_, xrayVersion, err := xrayutils.CreateXrayServiceManagerAndGetVersion(dsc.ScanCommand.serverDetails)
Expand Down Expand Up @@ -103,13 +104,14 @@ func (dsc *DockerScanCommand) Run() (err error) {
err = errorutils.CheckError(e)
}
}()
// Preform binary scan.
extendedScanResults, cleanup, scanErrors, err := dsc.ScanCommand.binaryScan()
defer cleanup()
if err != nil {
return
}

// Print results
// Print results with docker commands mapping.
err = xrayutils.NewResultsWriter(extendedScanResults).
SetOutputFormat(dsc.outputFormat).
SetIncludeVulnerabilities(dsc.includeVulnerabilities).
Expand Down Expand Up @@ -143,16 +145,16 @@ func (dsc *DockerScanCommand) mapDockerLayerToCommand() (layersMapping map[strin
}

func formatCommand(layer *image.Layer) string {
command := trimSpacesInMiddle(layer.Command)
command := trimMiddleSpaces(layer.Command)
command = strings.TrimSuffix(command, buildKitSuffix)
if len(command) > maxDisplayCommandLength {
command = command[:maxDisplayCommandLength] + " ..."
}
return command
}

func trimSpacesInMiddle(input string) string {
parts := strings.Fields(input) // Split the string by spaces
func trimMiddleSpaces(input string) string {
parts := strings.Fields(input)
return strings.Join(parts, " ")
}

Expand Down

0 comments on commit a412623

Please sign in to comment.