Files
pmg/config/config.go
T
Sahil BansalandGitHub ca752edf79 feat: add suppport for bypassing the blocking behavior of malicious packages (#53)
* feat: add suppport for bypassing the blocking behavior of malicious packages

* feat: add InsecureInstallation config to bypass malware scanning with tests

* ui: introduce ShowWarning interaction method

* guard test fix
2025-07-02 19:09:27 +05:30

42 lines
930 B
Go

package config
import (
"context"
"fmt"
)
type configKey struct{}
type contextValue struct {
Config Config
}
// Global configuration
type Config struct {
Transitive bool
TransitiveDepth int
IncludeDevDependencies bool
Paranoid bool
// DryRun to check for packages for risks.
// Do not actually execute any commands.
DryRun bool
// InsecureInstallation allows bypassing install blocking on malicious packages
InsecureInstallation bool
}
// Inject config into context while protecting against context poisoning
func (c Config) Inject(ctx context.Context) context.Context {
return context.WithValue(ctx, configKey{}, &contextValue{Config: c})
}
// Extract config from context
func FromContext(ctx context.Context) (Config, error) {
c, ok := ctx.Value(configKey{}).(*contextValue)
if !ok {
return Config{}, fmt.Errorf("config not found in context")
}
return c.Config, nil
}