-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Breaking Changes] Switch to Use Cobra/Viper for CLI and Config Handl…
…ing (#64)
- Loading branch information
1 parent
e0d6048
commit a7fa79b
Showing
10 changed files
with
428 additions
and
248 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/boostsecurityio/poutine/analyze" | ||
"github.com/boostsecurityio/poutine/providers/gitops" | ||
"github.com/boostsecurityio/poutine/providers/local" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// analyzeLocalCmd represents the analyzeLocal command | ||
var analyzeLocalCmd = &cobra.Command{ | ||
Use: "analyze_local", | ||
Short: "Analyzes a local repository for supply chain vulnerabilities", | ||
Long: `Analyzes a local repository for supply chain vulnerabilities | ||
Example: poutine analyze_local /path/to/repo`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := cmd.Context() | ||
repoPath := args[0] | ||
|
||
formatter := GetFormatter() | ||
|
||
localScmClient, err := local.NewGitSCMClient(ctx, repoPath, nil) | ||
if err != nil { | ||
return fmt.Errorf("failed to create local SCM client: %w", err) | ||
} | ||
|
||
localGitClient := gitops.NewLocalGitClient(nil) | ||
|
||
analyzer := analyze.NewAnalyzer(localScmClient, localGitClient, formatter, config) | ||
|
||
err = analyzer.AnalyzeLocalRepo(ctx, repoPath) | ||
if err != nil { | ||
return fmt.Errorf("failed to analyze repoPath %s: %w", repoPath, err) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(analyzeLocalCmd) | ||
} |
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,52 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var threads int | ||
|
||
// analyzeOrgCmd represents the analyzeOrg command | ||
var analyzeOrgCmd = &cobra.Command{ | ||
Use: "analyze_org", | ||
Short: "Analyzes an organization's repositories for supply chain vulnerabilities", | ||
Long: `Analyzes an organization's repositories for supply chain vulnerabilities | ||
Example: poutine analyze_org org --token "$GH_TOKEN" | ||
Analyze All Projects in a Self-Hosted Gitlab Organization: | ||
poutine analyze_org my-org/project --token "$GL_TOKEN" --scm gitlab --scm-base-uri https://gitlab.example.com | ||
Note: This command will scan all repositories in the organization except those that are Archived. | ||
`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
token = viper.GetString("token") | ||
ctx := cmd.Context() | ||
analyzer, err := GetAnalyzer(ctx, "analyze_org") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
org := args[0] | ||
|
||
err = analyzer.AnalyzeOrg(ctx, org, &threads) | ||
if err != nil { | ||
return fmt.Errorf("failed to analyze org %s: %w", org, err) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(analyzeOrgCmd) | ||
|
||
analyzeOrgCmd.Flags().StringVarP(&token, "token", "t", "", "SCM access token (env: GH_TOKEN)") | ||
|
||
analyzeOrgCmd.Flags().IntVarP(&threads, "threads", "j", 2, "Parallelization factor for scanning organizations") | ||
|
||
viper.BindPFlag("token", analyzeOrgCmd.Flags().Lookup("token")) | ||
viper.BindEnv("token", "GH_TOKEN") | ||
} |
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,42 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// analyzeRepoCmd represents the analyzeRepo command | ||
var analyzeRepoCmd = &cobra.Command{ | ||
Use: "analyze_repo", | ||
Short: "Analyzes a remote repository for supply chain vulnerabilities", | ||
Long: `Analyzes a remote repository for supply chain vulnerabilities | ||
Example Scanning a remote Github Repository: poutine analyze_repo org/repo --token "$GH_TOKEN"`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
token = viper.GetString("token") | ||
ctx := cmd.Context() | ||
analyzer, err := GetAnalyzer(ctx, "analyze_repo") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
repo := args[0] | ||
|
||
err = analyzer.AnalyzeRepo(ctx, repo) | ||
if err != nil { | ||
return fmt.Errorf("failed to analyze repo %s: %w", repo, err) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(analyzeRepoCmd) | ||
|
||
analyzeRepoCmd.Flags().StringVarP(&token, "token", "t", "", "SCM access token (env: GH_TOKEN)") | ||
|
||
viper.BindPFlag("token", analyzeOrgCmd.Flags().Lookup("token")) | ||
viper.BindEnv("token", "GH_TOKEN") | ||
} |
Oops, something went wrong.