mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
* feat: Add experimental proxy based npm interceptor * refactor: Analysis cache * ci: Add E2E for npm proxy * fix: Handle dry-run in proxy flow * fix: Handle special case for scope package name * fix: Misc fixes * fix: Code review fixes * fix: Code review fixes * refactor: Reusable code into base registry interceptor * Pause npm process during user confirmation (#90) * pause npm process when prompting user for confirmation * disable progress bar * fix logging and close chan on return * update use of deprecated field * refactor: Separation of concerns for handling process state * fix: Safe permission for cert file * fix: Handle nil check for interaction hook * fix: Add test for base registry * Fix goreleaser for windows build (#93) * introduce platform specific process control * rename common.go to common_flow.go * feat: Add support for pause resume on windows * fix: Code review fixes * test: Add confirmation handler tests --------- Co-authored-by: Sahil Bansal <bansalsahil315@gmail.com>
69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
package interceptors
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
packagev1 "buf.build/gen/go/safedep/api/protocolbuffers/go/safedep/messages/package/v1"
|
|
"github.com/safedep/pmg/analyzer"
|
|
"github.com/safedep/pmg/guard"
|
|
"github.com/safedep/pmg/proxy"
|
|
)
|
|
|
|
// InterceptorFactory creates ecosystem-specific interceptors for the proxy
|
|
type InterceptorFactory struct {
|
|
analyzer analyzer.PackageVersionAnalyzer
|
|
cache AnalysisCache
|
|
confirmationChan chan *ConfirmationRequest
|
|
interaction guard.PackageManagerGuardInteraction
|
|
}
|
|
|
|
// NewInterceptorFactory creates a new interceptor factory with shared dependencies
|
|
func NewInterceptorFactory(
|
|
analyzer analyzer.PackageVersionAnalyzer,
|
|
cache AnalysisCache,
|
|
confirmationChan chan *ConfirmationRequest,
|
|
interaction guard.PackageManagerGuardInteraction,
|
|
) *InterceptorFactory {
|
|
return &InterceptorFactory{
|
|
analyzer: analyzer,
|
|
cache: cache,
|
|
confirmationChan: confirmationChan,
|
|
interaction: interaction,
|
|
}
|
|
}
|
|
|
|
// CreateInterceptor creates an interceptor for the specified ecosystem
|
|
// Returns an error if the ecosystem is not supported for proxy-based interception
|
|
func (f *InterceptorFactory) CreateInterceptor(ecosystem packagev1.Ecosystem) (proxy.Interceptor, error) {
|
|
switch ecosystem {
|
|
case packagev1.Ecosystem_ECOSYSTEM_NPM:
|
|
return NewNpmRegistryInterceptor(
|
|
f.analyzer,
|
|
f.cache,
|
|
f.confirmationChan,
|
|
f.interaction,
|
|
), nil
|
|
|
|
default:
|
|
return nil, fmt.Errorf("proxy-based interception not yet supported for ecosystem: %s", ecosystem.String())
|
|
}
|
|
}
|
|
|
|
// SupportedEcosystems returns a list of ecosystems that support proxy-based interception
|
|
func SupportedEcosystems() []packagev1.Ecosystem {
|
|
return []packagev1.Ecosystem{
|
|
packagev1.Ecosystem_ECOSYSTEM_NPM,
|
|
}
|
|
}
|
|
|
|
// IsSupported checks if an ecosystem supports proxy-based interception
|
|
func IsSupported(ecosystem packagev1.Ecosystem) bool {
|
|
for _, supported := range SupportedEcosystems() {
|
|
if ecosystem == supported {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|