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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user