refactor CLI to use shared clients from context

- Add Login() method to toughswitch and edgeos clients
- Use zerolog's built-in context methods for logger storage
- Add context helpers for toughswitch/edgeos clients
- Create prepareClients prerun to initialize clients from config
- Consolidate device fetching into shared client.go helper

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-18 17:03:35 -05:00
parent 868ab64bc9
commit 5e8e7cd41d
7 changed files with 182 additions and 97 deletions

View File

@@ -119,6 +119,17 @@ func (c *Client) getDeviceByHost(host string) (*deviceClient, error) {
return d, nil
}
// Login authenticates with the device at the given host.
// This is called automatically on 401 responses, but can be called explicitly
// to pre-authenticate before making requests.
func (c *Client) Login(ctx context.Context, host string) error {
d, err := c.getDeviceByHost(host)
if err != nil {
return err
}
return d.login(ctx)
}
func (d *deviceClient) login(ctx context.Context) error {
d.mu.Lock()
defer d.mu.Unlock()

View File

@@ -120,6 +120,17 @@ func (c *Client) getDeviceByHost(host string) (*deviceClient, error) {
return d, nil
}
// Login authenticates with the device at the given host.
// This is called automatically on 401 responses, but can be called explicitly
// to pre-authenticate before making requests.
func (c *Client) Login(ctx context.Context, host string) error {
d, err := c.getDeviceByHost(host)
if err != nil {
return err
}
return d.login(ctx)
}
func (d *deviceClient) login(ctx context.Context) error {
d.mu.Lock()
defer d.mu.Unlock()