feat: passthrough proxies
This commit is contained in:
@ -2,6 +2,7 @@ package layer
|
||||
|
||||
import (
|
||||
"os"
|
||||
"slices"
|
||||
|
||||
"forge.cadoles.com/cadoles/bouncer/internal/client"
|
||||
"forge.cadoles.com/cadoles/bouncer/internal/command/admin/apierr"
|
||||
@ -52,14 +53,16 @@ func QueryCommand() *cli.Command {
|
||||
|
||||
client := client.New(baseFlags.ServerURL, client.WithToken(token))
|
||||
|
||||
proxies, err := client.QueryLayer(ctx.Context, proxyName, options...)
|
||||
layers, err := client.QueryLayer(ctx.Context, proxyName, options...)
|
||||
if err != nil {
|
||||
return errors.WithStack(apierr.Wrap(err))
|
||||
}
|
||||
|
||||
slices.SortFunc(layers, sortLayerssByWeight)
|
||||
|
||||
hints := layerHeaderHints(baseFlags.OutputMode)
|
||||
|
||||
if err := format.Write(baseFlags.Format, os.Stdout, hints, clientFlag.AsAnySlice(proxies)...); err != nil {
|
||||
if err := format.Write(baseFlags.Format, os.Stdout, hints, clientFlag.AsAnySlice(layers)...); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
@ -67,3 +70,13 @@ func QueryCommand() *cli.Command {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func sortLayerssByWeight(a *store.LayerHeader, b *store.LayerHeader) int {
|
||||
if a.Weight < b.Weight {
|
||||
return 1
|
||||
}
|
||||
if a.Weight > b.Weight {
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ func CreateCommand() *cli.Command {
|
||||
Name: "create",
|
||||
Usage: "Create proxy",
|
||||
Flags: proxyFlag.WithProxyFlags(
|
||||
flag.ProxyTo(true),
|
||||
flag.ProxyTo(),
|
||||
flag.ProxyFrom(),
|
||||
),
|
||||
Action: func(ctx *cli.Context) error {
|
||||
|
@ -30,12 +30,11 @@ func ProxyName() cli.Flag {
|
||||
|
||||
const KeyProxyTo = "proxy-to"
|
||||
|
||||
func ProxyTo(required bool) cli.Flag {
|
||||
func ProxyTo() cli.Flag {
|
||||
return &cli.StringFlag{
|
||||
Name: KeyProxyTo,
|
||||
Usage: "Set `PROXY_TO` as proxy's destination url",
|
||||
Value: "",
|
||||
Required: required,
|
||||
Name: KeyProxyTo,
|
||||
Usage: "Set `PROXY_TO` as proxy's destination url",
|
||||
Value: "",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package proxy
|
||||
|
||||
import (
|
||||
"os"
|
||||
"slices"
|
||||
|
||||
"forge.cadoles.com/cadoles/bouncer/internal/client"
|
||||
"forge.cadoles.com/cadoles/bouncer/internal/command/admin/apierr"
|
||||
@ -51,6 +52,8 @@ func QueryCommand() *cli.Command {
|
||||
return errors.WithStack(apierr.Wrap(err))
|
||||
}
|
||||
|
||||
slices.SortFunc(proxies, sortProxiesByWeight)
|
||||
|
||||
hints := proxyHeaderHints(baseFlags.OutputMode)
|
||||
|
||||
if err := format.Write(baseFlags.Format, os.Stdout, hints, clientFlag.AsAnySlice(proxies)...); err != nil {
|
||||
@ -61,3 +64,13 @@ func QueryCommand() *cli.Command {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func sortProxiesByWeight(a *store.ProxyHeader, b *store.ProxyHeader) int {
|
||||
if a.Weight < b.Weight {
|
||||
return 1
|
||||
}
|
||||
if a.Weight > b.Weight {
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ func UpdateCommand() *cli.Command {
|
||||
Name: "update",
|
||||
Usage: "Update proxy",
|
||||
Flags: proxyFlag.WithProxyFlags(
|
||||
flag.ProxyTo(false),
|
||||
flag.ProxyTo(),
|
||||
flag.ProxyFrom(),
|
||||
flag.ProxyEnabled(),
|
||||
flag.ProxyWeight(),
|
||||
|
Reference in New Issue
Block a user