From 63ef233357f8d5014e49783d0de3d5303e87358b Mon Sep 17 00:00:00 2001 From: Ryan McGuire Date: Mon, 19 Jan 2026 11:50:51 -0500 Subject: [PATCH] add consolidated methods, update cli --- cmd/cmd/client.go | 2 +- pkg/edgeos/api.go | 76 +++++++++++++++++++++++++++++++++++++++++++++ pkg/edgeos/types.go | 6 ++++ 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/cmd/cmd/client.go b/cmd/cmd/client.go index 1080468..0eba736 100644 --- a/cmd/cmd/client.go +++ b/cmd/cmd/client.go @@ -44,5 +44,5 @@ func fetchEdgeOSDevice(ctx context.Context, clientConf *config.ClientConfig) (an return nil, fmt.Errorf("login failed: %w", err) } - return client.GetConfig(ctx, clientConf.Host) + return client.GetEdgeOS(ctx, clientConf.Host) } diff --git a/pkg/edgeos/api.go b/pkg/edgeos/api.go index c1c4914..bb7875a 100644 --- a/pkg/edgeos/api.go +++ b/pkg/edgeos/api.go @@ -203,3 +203,79 @@ func (c *Client) GetAllSystems(ctx context.Context) (map[string]*SystemConfig, e wg.Wait() return results, errs } + +// GetEdgeOS retrieves all information for a specific device, +// combining AuthInfo and Config. +func (c *Client) GetEdgeOS(ctx context.Context, host string) (*EdgeOS, error) { + _, err := c.getDeviceByHost(host) + if err != nil { + return nil, err + } + + eos := &EdgeOS{} + var ( + mu sync.Mutex + wg sync.WaitGroup + errs error + ) + + // Fetch auth info and config in parallel + wg.Go(func() { + res, err := c.GetAuthInfo(ctx, host) + mu.Lock() + defer mu.Unlock() + if err != nil { + errs = errors.Join(errs, err) + return + } + eos.AuthInfo = res + }) + + wg.Go(func() { + res, err := c.GetConfig(ctx, host) + mu.Lock() + defer mu.Unlock() + if err != nil { + errs = errors.Join(errs, err) + return + } + eos.Config = res + }) + + wg.Wait() + return eos, errs +} + +// GetAllEdgeOS retrieves all information for all devices. +func (c *Client) GetAllEdgeOS(ctx context.Context) (map[string]*EdgeOS, error) { + results := make(map[string]*EdgeOS) + var ( + mu sync.Mutex + wg sync.WaitGroup + errs error + ) + + c.mu.RLock() + hosts := make([]string, 0, len(c.devices)) + for h := range c.devices { + hosts = append(hosts, h) + } + c.mu.RUnlock() + + for _, host := range hosts { + wg.Go(func() { + res, err := c.GetEdgeOS(ctx, host) + if err != nil { + mu.Lock() + errs = errors.Join(errs, err) + mu.Unlock() + return + } + mu.Lock() + results[host] = res + mu.Unlock() + }) + } + wg.Wait() + return results, errs +} diff --git a/pkg/edgeos/types.go b/pkg/edgeos/types.go index 087269e..37de471 100644 --- a/pkg/edgeos/types.go +++ b/pkg/edgeos/types.go @@ -1,5 +1,11 @@ package edgeos +// EdgeOS combines all device information into one response. +type EdgeOS struct { + AuthInfo *AuthResponse `json:"authInfo,omitempty"` + Config *ConfigData `json:"config,omitempty"` +} + // AuthResponse represents the authentication response from login2 endpoint. type AuthResponse struct { Username string `json:"username"`