bouncer/internal/command/admin/proxy/flag/flag.go

79 lines
1.5 KiB
Go
Raw Permalink Normal View History

2023-04-24 20:52:12 +02:00
package flag
import (
clientFlag "forge.cadoles.com/cadoles/bouncer/internal/command/admin/flag"
"forge.cadoles.com/cadoles/bouncer/internal/store"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)
func WithProxyFlags(flags ...cli.Flag) []cli.Flag {
baseFlags := clientFlag.ComposeFlags(
2023-06-23 19:08:35 +02:00
ProxyName(),
2023-04-24 20:52:12 +02:00
)
flags = append(flags, baseFlags...)
return flags
}
2023-06-23 19:08:35 +02:00
const KeyProxyName = "proxy-name"
func ProxyName() cli.Flag {
return &cli.StringFlag{
Name: KeyProxyName,
Usage: "use `PROXY_NAME` as targeted proxy",
Value: "",
Required: true,
}
}
const KeyProxyTo = "proxy-to"
2024-06-26 16:22:30 +02:00
func ProxyTo() cli.Flag {
2023-06-23 19:08:35 +02:00
return &cli.StringFlag{
2024-06-26 16:22:30 +02:00
Name: KeyProxyTo,
Usage: "Set `PROXY_TO` as proxy's destination url",
Value: "",
2023-06-23 19:08:35 +02:00
}
}
const KeyProxyFrom = "proxy-from"
func ProxyFrom() cli.Flag {
return &cli.StringSliceFlag{
Name: KeyProxyFrom,
Usage: "Set `PROXY_FROM` as proxy's patterns to match incoming requests",
Value: cli.NewStringSlice("*"),
}
}
const KeyProxyWeight = "proxy-weight"
func ProxyWeight() cli.Flag {
return &cli.IntFlag{
Name: KeyProxyWeight,
Usage: "Set `PROXY_WEIGHT` as proxy's weight",
}
}
const KeyProxyEnabled = "proxy-enabled"
func ProxyEnabled() cli.Flag {
return &cli.BoolFlag{
Name: KeyProxyEnabled,
Usage: "Enable or disable proxy",
}
}
2023-04-24 20:52:12 +02:00
func AssertProxyName(ctx *cli.Context) (store.ProxyName, error) {
2023-06-23 19:08:35 +02:00
rawProxyName := ctx.String(KeyProxyName)
2023-04-24 20:52:12 +02:00
name, err := store.ValidateName(rawProxyName)
if err != nil {
return "", errors.WithStack(err)
}
return store.ProxyName(name), nil
}