William Petit
d2bcdd2999
Some checks reported errors
arcad/emissary/pipeline/head Something is wrong with the build of this commit
73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/client"
|
|
agentFlag "forge.cadoles.com/Cadoles/emissary/internal/command/api/agent/flag"
|
|
"forge.cadoles.com/Cadoles/emissary/internal/command/api/apierr"
|
|
clientFlag "forge.cadoles.com/Cadoles/emissary/internal/command/api/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,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "label",
|
|
Usage: "Set `LABEL` to selected agent",
|
|
Value: "",
|
|
},
|
|
),
|
|
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))
|
|
}
|
|
|
|
label := ctx.String("label")
|
|
if label != "" {
|
|
options = append(options, client.WithAgentLabel(label))
|
|
}
|
|
|
|
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
|
|
},
|
|
}
|
|
}
|