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

🧹 allow os-provider to be builtin via config #4708

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
62 changes: 42 additions & 20 deletions providers-sdk/v1/util/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,29 @@ func genBuiltinGo(conf ProvidersConf) ([]byte, error) {
var infos string
var configs string

osIsActive := false
for _, provider := range conf.Builtin {
if provider == "os" {
osIsActive = true
}

// imports cannot contain dashes
trimProvider := strings.Replace(provider, "-", "", -1)

imports += fmt.Sprintf("\t%sconf \"go.mondoo.com/cnquery/v11/providers/%s/config\"\n", trimProvider, provider)
imports += fmt.Sprintf("\t%s \"go.mondoo.com/cnquery/v11/providers/%s/provider\"\n", trimProvider, provider)

providerFilename := provider + ".resources.json"
// We still have some special handling around the (builtin) os provider
// which should be removed long-term...
if provider == "os" {
providerFilename = provider + "/resources/" + providerFilename
}
infos += fmt.Sprintf(
"//go:embed %s.resources.json\n"+
"//go:embed %s\n"+
"var %sInfo []byte\n",
provider, trimProvider)
providerFilename, trimProvider)

configs += fmt.Sprintf(`
builtinProviders[%sconf.Config.ID] = &builtinProvider{
Runtime: &RunningProvider{
Expand All @@ -158,6 +172,28 @@ func genBuiltinGo(conf ProvidersConf) ([]byte, error) {
`, trimProvider, trimProvider, trimProvider, trimProvider, provider, trimProvider, trimProvider)
}

if !osIsActive {
imports += "\t// osconf \"go.mondoo.com/cnquery/v11/providers/os/config\"\n"
imports += "\t// os \"go.mondoo.com/cnquery/v11/providers/os/provider\"\n"
// IMPORTANT: Still special handling for the OS provider!
// This is only relevant for the example. If we streamline the os provider
// this will be removed.
infos += "// //go:embed os/resources/os.resources.json\n" +
"// var osInfo []byte\n"
configs += `
// builtinProviders[osconf.Config.ID] = &builtinProvider{
// Runtime: &RunningProvider{
// Name: osconf.Config.Name,
// ID: osconf.Config.ID,
// Plugin: os.Init(),
// Schema: MustLoadSchema("os", osInfo),
// isClosed: false,
// },
// Config: &osconf.Config,
// }
`
}

res := fmt.Sprintf(template, imports, infos, configs)
return format.Source([]byte(res))
}
Expand All @@ -166,33 +202,19 @@ const template = `// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1
//
// This file is auto-generated by 'make providers/config'
// and configured via 'providers.yaml'
// and configured via 'providers.yaml'. For example, you can inline via:
//
// builtin: [os, aws, mondoo]

package providers

import (
_ "embed"
// osconf "go.mondoo.com/cnquery/v11/providers/os/config"
// os "go.mondoo.com/cnquery/v11/providers/os/provider"
%s)

// //go:embed os/resources/os.resources.json
// var osInfo []byte

%s

func init() {
// builtinProviders[osconf.Config.ID] = &builtinProvider{
// Runtime: &RunningProvider{
// Name: osconf.Config.Name,
// ID: osconf.Config.ID,
// Plugin: os.Init(),
// Schema: MustLoadSchema("os", osInfo),
// isClosed: false,
// },
// Config: &osconf.Config,
// }
%s
func init() {%s
}
`

Expand Down
4 changes: 3 additions & 1 deletion providers/builtin_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// SPDX-License-Identifier: BUSL-1.1
//
// This file is auto-generated by 'make providers/config'
// and configured via 'providers.yaml'
// and configured via 'providers.yaml'. For example, you can inline via:
//
// builtin: [os, aws, mondoo]

package providers

Expand Down
Loading