57 lines
1.4 KiB
Go
57 lines
1.4 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/datastore"
|
|
"forge.cadoles.com/Cadoles/emissary/internal/format"
|
|
"github.com/pkg/errors"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func DeleteCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "delete",
|
|
Usage: "Delete agent",
|
|
Flags: agentFlag.WithAgentFlags(),
|
|
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)
|
|
}
|
|
|
|
client := client.New(baseFlags.ServerURL, client.WithToken(token))
|
|
|
|
agentID, err = client.DeleteAgent(ctx.Context, agentID)
|
|
if err != nil {
|
|
return errors.WithStack(apierr.Wrap(err))
|
|
}
|
|
|
|
hints := format.Hints{
|
|
OutputMode: baseFlags.OutputMode,
|
|
}
|
|
|
|
if err := format.Write(baseFlags.Format, os.Stdout, hints, struct {
|
|
ID datastore.AgentID `json:"id"`
|
|
}{
|
|
ID: agentID,
|
|
}); err != nil {
|
|
return errors.WithStack(err)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
}
|