providers/proxy: add backend_override
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
91d6f572a5
commit
7fd6be5abb
|
@ -1,7 +1,8 @@
|
||||||
package application
|
package application
|
||||||
|
|
||||||
type ProxyClaims struct {
|
type ProxyClaims struct {
|
||||||
UserAttributes map[string]interface{} `json:"user_attributes"`
|
UserAttributes map[string]interface{} `json:"user_attributes"`
|
||||||
|
BackendOverride string `json:"backend_override"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Claims struct {
|
type Claims struct {
|
||||||
|
|
|
@ -60,7 +60,7 @@ func (a *Application) configureProxy() error {
|
||||||
}
|
}
|
||||||
metrics.UpstreamTiming.With(prometheus.Labels{
|
metrics.UpstreamTiming.With(prometheus.Labels{
|
||||||
"outpost_name": a.outpostName,
|
"outpost_name": a.outpostName,
|
||||||
"upstream_host": u.String(),
|
"upstream_host": r.URL.Host,
|
||||||
"scheme": r.URL.Scheme,
|
"scheme": r.URL.Scheme,
|
||||||
"method": r.Method,
|
"method": r.Method,
|
||||||
"path": r.URL.Path,
|
"path": r.URL.Path,
|
||||||
|
@ -72,9 +72,17 @@ func (a *Application) configureProxy() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Application) proxyModifyRequest(u *url.URL) func(req *http.Request) {
|
func (a *Application) proxyModifyRequest(u *url.URL) func(req *http.Request) {
|
||||||
return func(req *http.Request) {
|
return func(r *http.Request) {
|
||||||
req.URL.Scheme = u.Scheme
|
claims, _ := a.getClaims(r)
|
||||||
req.URL.Host = u.Host
|
if claims.Proxy.BackendOverride != "" {
|
||||||
|
var err error
|
||||||
|
u, err = url.Parse(claims.Proxy.BackendOverride)
|
||||||
|
if err != nil {
|
||||||
|
a.log.WithField("backend_override", claims.Proxy.BackendOverride).WithError(err).Warning("failed parse user backend override")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r.URL.Scheme = u.Scheme
|
||||||
|
r.URL.Host = u.Host
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue