63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
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 UpdateCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "update",
|
|
Usage: "Updata agent",
|
|
Flags: agentFlag.WithAgentFlags(
|
|
&cli.IntFlag{
|
|
Name: "status",
|
|
Usage: "Set `STATUS` to selected agent",
|
|
Value: -1,
|
|
},
|
|
),
|
|
Action: func(ctx *cli.Context) error {
|
|
baseFlags := clientFlag.GetBaseFlags(ctx)
|
|
|
|
token, err := clientFlag.GetToken(baseFlags)
|
|
if err != nil {
|
|
return errors.WithStack(apierr.Wrap(err))
|
|
}
|
|
|
|
agentID, err := agentFlag.AssertAgentID(ctx)
|
|
if err != nil {
|
|
return errors.WithStack(err)
|
|
}
|
|
|
|
options := make([]client.UpdateAgentOptionFunc, 0)
|
|
|
|
status := ctx.Int("status")
|
|
if status != -1 {
|
|
options = append(options, client.WithAgentStatus(status))
|
|
}
|
|
|
|
client := client.New(baseFlags.ServerURL, client.WithToken(token))
|
|
|
|
agent, err := client.UpdateAgent(ctx.Context, agentID, options...)
|
|
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
|
|
},
|
|
}
|
|
}
|