Skip to content

Commit

Permalink
🐛 download os provider for login+status (#1998)
Browse files Browse the repository at this point in the history
Both commands need to get system infos at the start. Without the os
provider this is not possible (at the time of writing).

This PR also clarifies how the method `EnsureProviders` works and makes
the list of existing providers optional.

Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus authored Sep 30, 2023
1 parent 5e59bf1 commit a3a4afd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func AttachCLIs(rootCmd *cobra.Command, commands ...*Command) error {

connectorName, autoUpdate := detectConnectorName(os.Args, rootCmd, commands, existing)
if connectorName != "" {
if _, err := providers.EnsureProvider(existing, connectorName, "", autoUpdate); err != nil {
if _, err := providers.EnsureProvider(connectorName, "", autoUpdate, existing); err != nil {
return err
}
}
Expand Down
6 changes: 3 additions & 3 deletions cli/sysinfo/sysinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func GatherSystemInfo(opts ...SystemInfoOption) (*SystemInfo, error) {

log.Debug().Msg("Gathering system information")
if cfg.runtime == nil {

cfg.runtime = providers.Coordinator.NewRuntime()

// TODO: we need to ensure that the os provider is available here

// init runtime
if _, err := providers.EnsureProvider("local", "", true, nil); err != nil {
return nil, err
}
if err := cfg.runtime.UseProvider(providers.DefaultOsID); err != nil {
return nil, err
}
Expand Down
22 changes: 19 additions & 3 deletions providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,25 @@ func ListAll() ([]*Provider, error) {
return res, nil
}

// EnsureProvider find the provider for a given connector either from the list
// of existing proviers or by downloading and installing it.
func EnsureProvider(existing Providers, connectorName string, connectorType string, autoUpdate bool) (*Provider, error) {
// EnsureProvider makes sure that a given provider exists and returns it.
// You can supply providers either via:
// 1. connectorName, which is what you see in the CLI e.g. "local", "ssh", ...
// 2. connectorType, which is how assets define the connector type when
// they are moved between discovery and execution, e.g. "registry-image".
//
// If you disable autoUpdate, it will neither update NOR install missing providers.
//
// If you don't supply existing providers, it will look for alist of all
// active providers first.
func EnsureProvider(connectorName string, connectorType string, autoUpdate bool, existing Providers) (*Provider, error) {
if existing == nil {
var err error
existing, err = ListActive()
if err != nil {
return nil, err
}
}

provider := existing.ForConnection(connectorName, connectorType)
if provider != nil {
return provider, nil
Expand Down
2 changes: 1 addition & 1 deletion providers/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (r *Runtime) DetectProvider(asset *inventory.Asset) error {
continue
}

provider, err := EnsureProvider(r.coordinator.Providers, "", conn.Type, true)
provider, err := EnsureProvider("", conn.Type, true, r.coordinator.Providers)
if err != nil {
errs.Add(err)
continue
Expand Down

0 comments on commit a3a4afd

Please sign in to comment.