bouncer/internal/command/admin/layer/create.go

73 lines
1.8 KiB
Go
Raw Permalink Normal View History

2023-04-24 20:52:12 +02:00
package layer
import (
"os"
"forge.cadoles.com/cadoles/bouncer/internal/client"
"forge.cadoles.com/cadoles/bouncer/internal/command/admin/apierr"
clientFlag "forge.cadoles.com/cadoles/bouncer/internal/command/admin/flag"
"forge.cadoles.com/cadoles/bouncer/internal/command/admin/layer/flag"
layerFlag "forge.cadoles.com/cadoles/bouncer/internal/command/admin/layer/flag"
proxyFlag "forge.cadoles.com/cadoles/bouncer/internal/command/admin/proxy/flag"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
2024-05-17 15:44:28 +02:00
"gitlab.com/wpetit/goweb/cli/format"
2023-04-24 20:52:12 +02:00
)
func CreateCommand() *cli.Command {
return &cli.Command{
Name: "create",
Usage: "Create layer",
Flags: layerFlag.WithLayerCreateFlags(),
Action: func(ctx *cli.Context) error {
baseFlags := clientFlag.GetBaseFlags(ctx)
token, err := clientFlag.GetToken(baseFlags)
if err != nil {
return errors.WithStack(apierr.Wrap(err))
}
layerName, err := flag.AssertLayerName(ctx)
if err != nil {
return errors.WithStack(err)
}
proxyName, err := proxyFlag.AssertProxyName(ctx)
if err != nil {
return errors.WithStack(err)
}
layerType, err := flag.AssertLayerType(ctx)
if err != nil {
return errors.WithStack(err)
}
layerOptions, err := flag.AssertLayerOptions(ctx)
if err != nil {
return errors.WithStack(err)
}
client := client.New(baseFlags.ServerURL, client.WithToken(token))
layer, err := client.CreateLayer(
ctx.Context,
proxyName,
layerName,
layerType,
layerOptions,
)
if err != nil {
return errors.WithStack(apierr.Wrap(err))
}
hints := layerHints(baseFlags.OutputMode)
if err := format.Write(baseFlags.Format, os.Stdout, hints, layer); err != nil {
return errors.WithStack(err)
}
return nil
},
}
}