Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 ensure os provider is installed #190

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 10 additions & 35 deletions provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
}
Loading