bouncer/internal/command/client/proxy/delete.go

57 lines
1.4 KiB
Go
Raw Normal View History

2023-04-24 20:52:12 +02:00
package proxy
import (
"os"
"forge.cadoles.com/cadoles/bouncer/internal/client"
"forge.cadoles.com/cadoles/bouncer/internal/command/client/apierr"
clientFlag "forge.cadoles.com/cadoles/bouncer/internal/command/client/flag"
proxyFlag "forge.cadoles.com/cadoles/bouncer/internal/command/client/proxy/flag"
"forge.cadoles.com/cadoles/bouncer/internal/format"
"forge.cadoles.com/cadoles/bouncer/internal/store"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)
func DeleteCommand() *cli.Command {
return &cli.Command{
Name: "delete",
Usage: "Delete proxy",
Flags: proxyFlag.WithProxyFlags(),
Action: func(ctx *cli.Context) error {
baseFlags := clientFlag.GetBaseFlags(ctx)
token, err := clientFlag.GetToken(baseFlags)
if err != nil {
return errors.WithStack(apierr.Wrap(err))
}
proxyID, err := proxyFlag.AssertProxyID(ctx)
if err != nil {
return errors.WithStack(err)
}
client := client.New(baseFlags.ServerURL, client.WithToken(token))
proxyID, err = client.DeleteProxy(ctx.Context, proxyID)
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 store.ProxyID `json:"id"`
}{
ID: proxyID,
}); err != nil {
return errors.WithStack(err)
}
return nil
},
}
}