From a952c37b2341cf5b18cef8f22b01f15c59af7707 Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Sat, 27 Jan 2024 10:03:40 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20ensure=20os=20provider=20is=20in?= =?UTF-8?q?stalled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- provisioner/provisioner.go | 45 +++++++++----------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/provisioner/provisioner.go b/provisioner/provisioner.go index b8de7c6..b803e29 100644 --- a/provisioner/provisioner.go +++ b/provisioner/provisioner.go @@ -523,10 +523,18 @@ func (p *Provisioner) executeCnspec(ui packer.Ui, comm packer.Communicator) erro } } - updateProviders(ui) + provider, err := providers.EnsureProvider(providers.ProviderLookup{ + ID: "go.mondoo.com/cnquery/v9/providers/os", + }, true, nil) + if err != nil { + ui.Error("could not load OS providers: " + err.Error()) + if err != nil { + return err + } + } + ui.Message("use OS provider version " + provider.Version + " (" + provider.Path + ")") var res *scan.ScanResult - var err error if p.config.Incognito { ui.Message("scan packer build in incognito mode") scanService := scan.NewLocalScanner() @@ -607,36 +615,3 @@ func (p *Provisioner) executeCnspec(ui packer.Ui, comm packer.Communicator) erro return nil } - -func updateProviders(ui packer.Ui) { - allProviders, err := providers.ListActive() - if err != nil { - ui.Error(err.Error()) - ui.Message("failed to list providers, not going to update cnspec providers") - return - } - updatedProviders := []*providers.Provider{} - for _, provider := range allProviders { - if provider.Name == "mock" || provider.Name == "core" { - continue - } - latestVersion, err := providers.LatestVersion(provider.Name) - if err != nil { - ui.Error(err.Error()) - ui.Message("failed to determine latest version for " + provider.Name + " provider, not going to update it") - continue - } - if latestVersion != provider.Version { - installed, err := providers.Install(provider.Name, "") - if err != nil { - ui.Error(err.Error()) - ui.Message("failed to install/update " + provider.Name + " provider") - continue - } - updatedProviders = append(updatedProviders, installed) - } - } - for _, p := range updatedProviders { - ui.Message("successfully installed " + p.Name + " provider" + " version=" + p.Version + " path=" + p.Path) - } -}