1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 13:23:07 +01:00

chore: refactors sub commands

This commit is contained in:
Amir Raminfar
2025-02-21 15:03:14 -08:00
parent 90b90ceea4
commit 7be55cbc08
6 changed files with 203 additions and 135 deletions

View File

@@ -0,0 +1,38 @@
package cli
import (
"context"
"embed"
"fmt"
"github.com/amir20/dozzle/internal/agent"
"github.com/rs/zerolog/log"
)
type AgentTestCmd struct {
Address string `arg:"positional"`
}
func (at *AgentTestCmd) Run(args Args, embeddedCerts embed.FS) error {
certs, err := ReadCertificates(embeddedCerts)
if err != nil {
return fmt.Errorf("error reading certificates: %w", err)
}
log.Info().Str("endpoint", args.AgentTest.Address).Msg("Connecting to agent")
agent, err := agent.NewClient(args.AgentTest.Address, certs)
if err != nil {
return fmt.Errorf("error connecting to agent: %w", err)
}
ctx, cancel := context.WithTimeout(context.Background(), args.Timeout)
defer cancel()
host, err := agent.Host(ctx)
if err != nil {
return fmt.Errorf("error fetching host info for agent: %w", err)
}
log.Info().Str("endpoint", args.AgentTest.Address).Str("version", host.AgentVersion).Str("name", host.Name).Str("id", host.ID).Msg("Successfully connected to agent")
return nil
}