mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
Improve UI with additional info
This commit is contained in:
@@ -29,6 +29,8 @@ pnpm add <package-name>
|
|||||||
- [Binaries](#binaries)
|
- [Binaries](#binaries)
|
||||||
- [Build from Source](#build-from-source)
|
- [Build from Source](#build-from-source)
|
||||||
- [Usage](#usage)
|
- [Usage](#usage)
|
||||||
|
- [Silent Mode](#silent-mode)
|
||||||
|
- [Verbose Mode](#verbose-mode)
|
||||||
- [Debugging](#debugging)
|
- [Debugging](#debugging)
|
||||||
- [PMG in Action](#pmg-in-action)
|
- [PMG in Action](#pmg-in-action)
|
||||||
- [Malicious Package Detection](#malicious-package-detection)
|
- [Malicious Package Detection](#malicious-package-detection)
|
||||||
@@ -95,6 +97,22 @@ npm install <package-name>
|
|||||||
pnpm add <package-name>
|
pnpm add <package-name>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Silent Mode
|
||||||
|
|
||||||
|
Use the `--silent` flag to run PMG in silent mode:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pmg --silent npm install <package-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Verbose Mode
|
||||||
|
|
||||||
|
Use the `--verbose` flag to run PMG in verbose mode:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pmg --verbose npm install <package-name>
|
||||||
|
```
|
||||||
|
|
||||||
### Debugging
|
### Debugging
|
||||||
|
|
||||||
Use the `--debug` flag to enable debug mode:
|
Use the `--debug` flag to enable debug mode:
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ type PackageVersionAnalysisResult struct {
|
|||||||
// Analyser specific analysis ID
|
// Analyser specific analysis ID
|
||||||
AnalysisID string
|
AnalysisID string
|
||||||
|
|
||||||
|
// Reference URL for the analysis
|
||||||
|
ReferenceURL string
|
||||||
|
|
||||||
// The action to take as recommended by the analyzer
|
// The action to take as recommended by the analyzer
|
||||||
Action Action
|
Action Action
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ func (a *malysisQueryAnalyzer) Analyze(ctx context.Context,
|
|||||||
// By default, the analyzer allows the package version
|
// By default, the analyzer allows the package version
|
||||||
analysisResult := &PackageVersionAnalysisResult{
|
analysisResult := &PackageVersionAnalysisResult{
|
||||||
PackageVersion: packageVersion,
|
PackageVersion: packageVersion,
|
||||||
|
ReferenceURL: malysisReportUrl(res.GetAnalysisId()),
|
||||||
Action: ActionAllow,
|
Action: ActionAllow,
|
||||||
AnalysisID: res.GetAnalysisId(),
|
AnalysisID: res.GetAnalysisId(),
|
||||||
Summary: res.GetReport().GetInference().GetSummary(),
|
Summary: res.GetReport().GetInference().GetSummary(),
|
||||||
@@ -73,3 +74,7 @@ func (a *malysisQueryAnalyzer) Analyze(ctx context.Context,
|
|||||||
|
|
||||||
return analysisResult, nil
|
return analysisResult, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func malysisReportUrl(analysisId string) string {
|
||||||
|
return fmt.Sprintf("https://platform.safedep.io/community/malysis/%s", analysisId)
|
||||||
|
}
|
||||||
|
|||||||
+14
-3
@@ -59,14 +59,25 @@ func SetStatus(status string) {
|
|||||||
|
|
||||||
func GetConfirmationOnMalware(malwarePackages []*analyzer.PackageVersionAnalysisResult) (bool, error) {
|
func GetConfirmationOnMalware(malwarePackages []*analyzer.PackageVersionAnalysisResult) (bool, error) {
|
||||||
StopSpinner()
|
StopSpinner()
|
||||||
fmt.Println(Colors.Red(fmt.Sprintf("🚨 Malicious packages detected: %d", len(malwarePackages))))
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
fmt.Println(Colors.Red(fmt.Sprintf("🚨 Suspicious package(s) detected: %d", len(malwarePackages))))
|
||||||
|
|
||||||
for _, mp := range malwarePackages {
|
for _, mp := range malwarePackages {
|
||||||
|
fmt.Println()
|
||||||
fmt.Println("⚠️ ", Colors.Red(fmt.Sprintf("%s@%s", mp.PackageVersion.GetPackage().GetName(),
|
fmt.Println("⚠️ ", Colors.Red(fmt.Sprintf("%s@%s", mp.PackageVersion.GetPackage().GetName(),
|
||||||
mp.PackageVersion.GetVersion())))
|
mp.PackageVersion.GetVersion())))
|
||||||
fmt.Println(Colors.Yellow(termWidthFormatText(mp.Summary, 60)))
|
|
||||||
fmt.Println()
|
if verbosityLevel == VerbosityLevelVerbose {
|
||||||
|
fmt.Println(Colors.Yellow(termWidthFormatText(mp.Summary, 60)))
|
||||||
|
|
||||||
|
if mp.ReferenceURL != "" {
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println(Colors.Yellow(fmt.Sprintf("Reference: %s", mp.ReferenceURL)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|||||||
@@ -7,11 +7,14 @@ import (
|
|||||||
"github.com/safedep/dry/log"
|
"github.com/safedep/dry/log"
|
||||||
"github.com/safedep/pmg/cmd/npm"
|
"github.com/safedep/pmg/cmd/npm"
|
||||||
"github.com/safedep/pmg/config"
|
"github.com/safedep/pmg/config"
|
||||||
|
"github.com/safedep/pmg/internal/ui"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
debug bool
|
debug bool
|
||||||
|
silent bool
|
||||||
|
verbose bool
|
||||||
globalConfig config.Config
|
globalConfig config.Config
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,6 +29,17 @@ func main() {
|
|||||||
|
|
||||||
log.InitZapLogger("pmg", "")
|
log.InitZapLogger("pmg", "")
|
||||||
|
|
||||||
|
if silent && verbose {
|
||||||
|
fmt.Println("pmg: --silent and --verbose cannot be used together")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if silent {
|
||||||
|
ui.SetVerbosityLevel(ui.VerbosityLevelSilent)
|
||||||
|
} else if verbose {
|
||||||
|
ui.SetVerbosityLevel(ui.VerbosityLevelVerbose)
|
||||||
|
}
|
||||||
|
|
||||||
cmd.SetContext(globalConfig.Inject(cmd.Context()))
|
cmd.SetContext(globalConfig.Inject(cmd.Context()))
|
||||||
},
|
},
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
@@ -38,7 +52,9 @@ func main() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.PersistentFlags().BoolVar(&debug, "debug", false, "Enable debug logging")
|
cmd.PersistentFlags().BoolVar(&silent, "silent", false, "Silent mode for invisible experience")
|
||||||
|
cmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Verbose mode for more information")
|
||||||
|
cmd.PersistentFlags().BoolVar(&debug, "debug", false, "Enable debug logging (defaults to stdout)")
|
||||||
cmd.PersistentFlags().BoolVar(&globalConfig.Transitive, "transitive", true, "Resolve transitive dependencies")
|
cmd.PersistentFlags().BoolVar(&globalConfig.Transitive, "transitive", true, "Resolve transitive dependencies")
|
||||||
cmd.PersistentFlags().IntVar(&globalConfig.TransitiveDepth, "transitive-depth", 20,
|
cmd.PersistentFlags().IntVar(&globalConfig.TransitiveDepth, "transitive-depth", 20,
|
||||||
"Maximum depth of transitive dependencies to resolve")
|
"Maximum depth of transitive dependencies to resolve")
|
||||||
|
|||||||
Reference in New Issue
Block a user