2023-03-02 13:05:24 +01:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/client"
|
|
|
|
agentFlag "forge.cadoles.com/Cadoles/emissary/internal/command/client/agent/flag"
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/command/client/apierr"
|
|
|
|
clientFlag "forge.cadoles.com/Cadoles/emissary/internal/command/client/flag"
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/format"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetCommand() *cli.Command {
|
|
|
|
return &cli.Command{
|
|
|
|
Name: "get",
|
|
|
|
Usage: "Get agent",
|
|
|
|
Flags: agentFlag.WithAgentFlags(),
|
|
|
|
Action: func(ctx *cli.Context) error {
|
|
|
|
baseFlags := clientFlag.GetBaseFlags(ctx)
|
|
|
|
|
2023-03-07 23:10:42 +01:00
|
|
|
token, err := clientFlag.GetToken(baseFlags)
|
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(apierr.Wrap(err))
|
|
|
|
}
|
|
|
|
|
2023-03-02 13:05:24 +01:00
|
|
|
agentID, err := agentFlag.AssertAgentID(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
2023-03-07 23:10:42 +01:00
|
|
|
client := client.New(baseFlags.ServerURL, client.WithToken(token))
|
2023-03-02 13:05:24 +01:00
|
|
|
|
|
|
|
agent, err := client.GetAgent(ctx.Context, agentID)
|
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(apierr.Wrap(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
hints := agentHints(baseFlags.OutputMode)
|
|
|
|
|
|
|
|
if err := format.Write(baseFlags.Format, os.Stdout, hints, agent); err != nil {
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|