-
Notifications
You must be signed in to change notification settings - Fork 31
Add support to tar flag for docker scan #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -24,6 +24,7 @@ type AuditCommand struct { | |
IncludeLicenses bool | ||
Fail bool | ||
PrintExtendedTable bool | ||
IsTar bool | ||
AuditParams | ||
} | ||
|
||
|
@@ -56,6 +57,11 @@ func (auditCmd *AuditCommand) SetIncludeLicenses(include bool) *AuditCommand { | |
return auditCmd | ||
} | ||
|
||
func (auditCmd *AuditCommand) SetIsTar(isTar bool) *AuditCommand { | ||
auditCmd.IsTar = isTar | ||
return auditCmd | ||
} | ||
Comment on lines
+60
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why you need it in audit command? this is just for docker scan.... |
||
|
||
func (auditCmd *AuditCommand) SetFail(fail bool) *AuditCommand { | ||
auditCmd.Fail = fail | ||
return auditCmd | ||
|
This file contains hidden or 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 | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,16 +3,16 @@ package scan | |||||||||||||||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||||||||||||||||
"bytes" | ||||||||||||||||||||||||||||||||||||||||||
"fmt" | ||||||||||||||||||||||||||||||||||||||||||
"os" | ||||||||||||||||||||||||||||||||||||||||||
"os/exec" | ||||||||||||||||||||||||||||||||||||||||||
"strings" | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
"github.com/jfrog/jfrog-cli-core/v2/common/spec" | ||||||||||||||||||||||||||||||||||||||||||
xrayutils "github.com/jfrog/jfrog-cli-security/utils" | ||||||||||||||||||||||||||||||||||||||||||
clientutils "github.com/jfrog/jfrog-client-go/utils" | ||||||||||||||||||||||||||||||||||||||||||
"github.com/jfrog/jfrog-client-go/utils/errorutils" | ||||||||||||||||||||||||||||||||||||||||||
"github.com/jfrog/jfrog-client-go/utils/io/fileutils" | ||||||||||||||||||||||||||||||||||||||||||
"github.com/jfrog/jfrog-client-go/utils/log" | ||||||||||||||||||||||||||||||||||||||||||
"os" | ||||||||||||||||||||||||||||||||||||||||||
"os/exec" | ||||||||||||||||||||||||||||||||||||||||||
"path/filepath" | ||||||||||||||||||||||||||||||||||||||||||
"strings" | ||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
const ( | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -40,6 +40,11 @@ func (dsc *DockerScanCommand) SetTargetRepoPath(repoPath string) *DockerScanComm | |||||||||||||||||||||||||||||||||||||||||
return dsc | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
func (dsc *DockerScanCommand) SetIsTar(isTar bool) *DockerScanCommand { | ||||||||||||||||||||||||||||||||||||||||||
dsc.isTar = isTar | ||||||||||||||||||||||||||||||||||||||||||
return dsc | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
func (dsc *DockerScanCommand) Run() (err error) { | ||||||||||||||||||||||||||||||||||||||||||
// Validate Xray minimum version | ||||||||||||||||||||||||||||||||||||||||||
_, xrayVersion, err := xrayutils.CreateXrayServiceManagerAndGetVersion(dsc.ScanCommand.serverDetails) | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -63,17 +68,19 @@ func (dsc *DockerScanCommand) Run() (err error) { | |||||||||||||||||||||||||||||||||||||||||
}() | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// Run the 'docker save' command, to create tar file from the docker image, and pass it to the indexer-app | ||||||||||||||||||||||||||||||||||||||||||
if dsc.progress != nil { | ||||||||||||||||||||||||||||||||||||||||||
dsc.progress.SetHeadlineMsg("Creating image archive 📦") | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
log.Info("Creating image archive...") | ||||||||||||||||||||||||||||||||||||||||||
imageTarPath := filepath.Join(tempDirPath, "image.tar") | ||||||||||||||||||||||||||||||||||||||||||
dockerSaveCmd := exec.Command("docker", "save", dsc.imageTag, "-o", imageTarPath) | ||||||||||||||||||||||||||||||||||||||||||
var stderr bytes.Buffer | ||||||||||||||||||||||||||||||||||||||||||
dockerSaveCmd.Stderr = &stderr | ||||||||||||||||||||||||||||||||||||||||||
err = dockerSaveCmd.Run() | ||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf("failed running command: '%s' with error: %s - %s", strings.Join(dockerSaveCmd.Args, " "), err.Error(), stderr.String()) | ||||||||||||||||||||||||||||||||||||||||||
imageTarPath := dsc.imageTag | ||||||||||||||||||||||||||||||||||||||||||
if !dsc.isTar { | ||||||||||||||||||||||||||||||||||||||||||
guyshe-jfrog marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
if dsc.progress != nil { | ||||||||||||||||||||||||||||||||||||||||||
guyshe-jfrog marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
dsc.progress.SetHeadlineMsg("Creating image archive 📦") | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
log.Info("Creating image archive...") | ||||||||||||||||||||||||||||||||||||||||||
dockerSaveCmd := exec.Command("docker", "save", dsc.imageTag, "-o", imageTarPath) | ||||||||||||||||||||||||||||||||||||||||||
var stderr bytes.Buffer | ||||||||||||||||||||||||||||||||||||||||||
dockerSaveCmd.Stderr = &stderr | ||||||||||||||||||||||||||||||||||||||||||
err = dockerSaveCmd.Run() | ||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf("failed running command: '%s' with error: %s - %s", strings.Join(dockerSaveCmd.Args, " "), err.Error(), stderr.String()) | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
You can move it to a separated method to help with readability |
||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// Perform scan on image.tar | ||||||||||||||||||||||||||||||||||||||||||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.