William Petit
6559d1f594
Some checks reported errors
Cadoles/bouncer/pipeline/head Something is wrong with the build of this commit
80 lines
1.6 KiB
Go
80 lines
1.6 KiB
Go
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(
|
|
ProxyName(),
|
|
)
|
|
|
|
flags = append(flags, baseFlags...)
|
|
|
|
return flags
|
|
}
|
|
|
|
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"
|
|
|
|
func ProxyTo(required bool) cli.Flag {
|
|
return &cli.StringFlag{
|
|
Name: KeyProxyTo,
|
|
Usage: "Set `PROXY_TO` as proxy's destination url",
|
|
Value: "",
|
|
Required: required,
|
|
}
|
|
}
|
|
|
|
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",
|
|
}
|
|
}
|
|
|
|
func AssertProxyName(ctx *cli.Context) (store.ProxyName, error) {
|
|
rawProxyName := ctx.String(KeyProxyName)
|
|
|
|
name, err := store.ValidateName(rawProxyName)
|
|
if err != nil {
|
|
return "", errors.WithStack(err)
|
|
}
|
|
|
|
return store.ProxyName(name), nil
|
|
}
|