-
Notifications
You must be signed in to change notification settings - Fork 26
Pre receive feature command (AST-89345) #1146
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
Open
cx-anjali-deore
wants to merge
20
commits into
main
Choose a base branch
from
feature/pre-receive
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8aba350
Moved to common hooks place
cx-anjali-deore c73ce10
removed common hooks code
cx-anjali-deore accce46
Added pre receive commands
cx-anjali-deore 813616c
Adding the commit version of secret detection
cx-anjali-deore 2719011
Added pre receive in Hooks doc
cx-anjali-deore a53d954
formatted
cx-anjali-deore e089ca3
typo changes
cx-anjali-deore 1ed44aa
Merge branch 'main' of https://github.com/Checkmarx/ast-cli into feat…
cx-anjali-deore d8a71c2
formatted the file
cx-anjali-deore 8d0c665
Update kics version from 2.1.5 to 2.1.7 (AST-93611) (#1121)
cx-rui-araujo c575b7c
Add support for uppercase filter in results command (#1136)
cx-ben-alvo 81039f6
Fix bug/AST-89866 and bug/AST-95350 (#1145)
cx-margarita-levitm feda3d2
Add OSS-Realtime scan functionality to identify malicious packages (A…
cx-ben-alvo 5da420f
formatted the file
cx-anjali-deore ca387d6
Add OSS-Realtime scan functionality to identify malicious packages (A…
cx-ben-alvo 049d630
Hide --ignore-policy flag (AST-96336) (#1141)
cx-sumit-morchhale 874c8ac
Adding secret detection to depgaurd allow list
cx-anjali-deore 645194e
Merge branch 'main' of https://github.com/Checkmarx/ast-cli into feat…
cx-anjali-deore e969109
Merge branch 'feature/pre-receive' of https://github.com/Checkmarx/as…
cx-anjali-deore 0676109
removed unnecessary merged changes
cx-anjali-deore 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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package commands | ||
|
||
import ( | ||
"github.com/MakeNowJust/heredoc" | ||
"github.com/checkmarx/ast-cli/internal/params" | ||
"github.com/checkmarx/ast-cli/internal/wrappers" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewHooksCommand creates the hooks command with pre-commit subcommand | ||
|
||
func NewHooksCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command { | ||
hooksCmd := &cobra.Command{ | ||
Use: "hooks", | ||
Short: "Manage Git hooks", | ||
Long: "The hooks command enables the ability to manage Git hooks for Checkmarx One.", | ||
Example: heredoc.Doc( | ||
` | ||
$ cx hooks pre-commit secrets-install-git-hook | ||
$ cx hooks pre-commit secrets-scan | ||
$ cx hooks pre-receive secrets-scan | ||
`, | ||
), | ||
Annotations: map[string]string{ | ||
"command:doc": heredoc.Doc( | ||
` | ||
https://checkmarx.com/resource/documents/en/xxxxx-xxxxx-hooks.html | ||
`, | ||
), | ||
}, | ||
} | ||
|
||
// Add pre-commit and pre-receive subcommand | ||
hooksCmd.AddCommand(PreCommitCommand(jwtWrapper)) | ||
hooksCmd.AddCommand(PreReceiveCommand(jwtWrapper)) | ||
|
||
return hooksCmd | ||
} | ||
|
||
func validateLicense(jwtWrapper wrappers.JWTWrapper) error { | ||
|
||
allowed, err := jwtWrapper.IsAllowedEngine(params.EnterpriseSecretsLabel) | ||
if err != nil { | ||
return errors.Wrapf(err, "Failed checking license") | ||
} | ||
if !allowed { | ||
return errors.New("Error: License validation failed. Please verify your CxOne license includes Enterprise Secrets.") | ||
} | ||
return nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package commands | ||
|
||
import ( | ||
prereceive "github.com/Checkmarx/secret-detection/pkg/hooks/pre-receive" | ||
"github.com/MakeNowJust/heredoc" | ||
"github.com/checkmarx/ast-cli/internal/wrappers" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func PreReceiveCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command { | ||
preReceiveCmd := &cobra.Command{ | ||
Use: "pre-receive", | ||
Short: "Manage pre-receive hooks and run secret detection scans", | ||
Long: "The pre-receive command enables the ability to manage Git pre-receive hooks for secret detection.", | ||
Example: heredoc.Doc( | ||
` | ||
$ cx hooks pre-receive secrets-scan | ||
`, | ||
), | ||
} | ||
preReceiveCmd.AddCommand(scanSecretsPreReceiveCommand(jwtWrapper)) | ||
|
||
return preReceiveCmd | ||
} | ||
|
||
func scanSecretsPreReceiveCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command { | ||
var configFile string | ||
scanPrereceiveCmd := &cobra.Command{ | ||
Use: "secrets-scan", | ||
Short: "Scan commits for secret detection.", | ||
Long: "Scan all commits about to enter the remote git repository for secret detection.", | ||
Example: heredoc.Doc( | ||
` | ||
$ cx hooks pre-receive secrets-scan | ||
$ cx hooks pre-receive secrets-scan --config /path/to/config.yaml | ||
`, | ||
), | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
return validateLicense(jwtWrapper) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return prereceive.Scan(configFile) | ||
}, | ||
} | ||
|
||
scanPrereceiveCmd.Flags().StringVarP(&configFile, "config", "c", "", "path to config.yaml file") | ||
|
||
return scanPrereceiveCmd | ||
} |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change this once module is release