Skip to content

Commit

Permalink
fix(plugin): delay initilizing plugin manager
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 committed May 13, 2024
1 parent d41b592 commit 9dbecdf
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions pkg/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const configFile = "plugin.yaml"
var (
pluginsRelativeDir = filepath.Join(".trivy", "plugins")

defaultManager = NewManager()
_defaultManager *Manager
)

type ManagerOption func(indexer *Manager)
Expand Down Expand Up @@ -64,22 +64,28 @@ func NewManager(opts ...ManagerOption) *Manager {
return m
}

func defaultManager() *Manager {
if _defaultManager == nil {
_defaultManager = NewManager()
}
return _defaultManager
}

func Install(ctx context.Context, name string, opts Options) (Plugin, error) {
return defaultManager.Install(ctx, name, opts)
return defaultManager().Install(ctx, name, opts)
}
func Start(ctx context.Context, name string, opts Options) (Wait, error) {
return defaultManager.Start(ctx, name, opts)
return defaultManager().Start(ctx, name, opts)
}
func RunWithURL(ctx context.Context, name string, opts Options) error {
return defaultManager.RunWithURL(ctx, name, opts)
return defaultManager().RunWithURL(ctx, name, opts)
}
func Upgrade(ctx context.Context, names []string) error { return defaultManager.Upgrade(ctx, names) }
func Uninstall(ctx context.Context, name string) error { return defaultManager.Uninstall(ctx, name) }
func Information(name string) error { return defaultManager.Information(name) }
func List(ctx context.Context) error { return defaultManager.List(ctx) }
func Update(ctx context.Context) error { return defaultManager.Update(ctx) }
func Search(ctx context.Context, args []string) error { return defaultManager.Search(ctx, args) }
func LoadAll(ctx context.Context) ([]Plugin, error) { return defaultManager.LoadAll(ctx) }
func Upgrade(ctx context.Context, names []string) error { return defaultManager().Upgrade(ctx, names) }
func Uninstall(ctx context.Context, name string) error { return defaultManager().Uninstall(ctx, name) }
func Information(name string) error { return defaultManager().Information(name) }
func List(ctx context.Context) error { return defaultManager().List(ctx) }
func Update(ctx context.Context) error { return defaultManager().Update(ctx) }
func Search(ctx context.Context, args []string) error { return defaultManager().Search(ctx, args) }

// Install installs a plugin
func (m *Manager) Install(ctx context.Context, name string, opts Options) (Plugin, error) {
Expand Down

0 comments on commit 9dbecdf

Please sign in to comment.