mirror of
https://github.com/umputun/reproxy.git
synced 2024-11-24 08:12:31 +02:00
allow docker rules to use external destinations
This commit is contained in:
parent
1c1f9d1c3c
commit
e092c7e989
@ -118,7 +118,11 @@ func (d *Docker) parseContainerInfo(c containerInfo) (res []discovery.URLMapper)
|
||||
}
|
||||
if v, ok := d.labelN(c.Labels, n, "dest"); ok {
|
||||
enabled, explicit = true, true
|
||||
destURL = fmt.Sprintf("http://%s:%d%s", c.IP, port, v)
|
||||
if strings.HasPrefix(v, "http://") || strings.HasPrefix(v, "https://") {
|
||||
destURL = v // proxy to http:// and https:// destinations as-is
|
||||
} else {
|
||||
destURL = fmt.Sprintf("http://%s:%d%s", c.IP, port, v)
|
||||
}
|
||||
}
|
||||
if v, ok := d.labelN(c.Labels, n, "server"); ok {
|
||||
enabled = true
|
||||
@ -126,7 +130,11 @@ func (d *Docker) parseContainerInfo(c containerInfo) (res []discovery.URLMapper)
|
||||
}
|
||||
if v, ok := d.labelN(c.Labels, n, "ping"); ok {
|
||||
enabled = true
|
||||
pingURL = fmt.Sprintf("http://%s:%d%s", c.IP, port, v)
|
||||
if strings.HasPrefix(v, "http://") || strings.HasPrefix(v, "https://") {
|
||||
pingURL = v // if ping is fulle url with http:// or https:// use it as-is
|
||||
} else {
|
||||
pingURL = fmt.Sprintf("http://%s:%d%s", c.IP, port, v)
|
||||
}
|
||||
}
|
||||
|
||||
if v, ok := d.labelN(c.Labels, n, "assets"); ok {
|
||||
|
@ -32,6 +32,11 @@ func TestDocker_List(t *testing.T) {
|
||||
Labels: map[string]string{"reproxy.route": "^/api/123/(.*)", "reproxy.dest": "/blah/$1",
|
||||
"reproxy.server": "example.com", "reproxy.ping": "/ping"},
|
||||
},
|
||||
{
|
||||
Name: "c1", State: "running", IP: "127.0.0.21", Ports: []int{12345},
|
||||
Labels: map[string]string{"reproxy.route": "^/api/90/(.*)", "reproxy.dest": "http://example.com/blah/$1",
|
||||
"reproxy.server": "example.com", "reproxy.ping": "https://example.com//ping"},
|
||||
},
|
||||
{
|
||||
Name: "c2", State: "running", IP: "127.0.0.3", Ports: []int{12346},
|
||||
Labels: map[string]string{"reproxy.enabled": "y"},
|
||||
@ -53,22 +58,27 @@ func TestDocker_List(t *testing.T) {
|
||||
d := Docker{DockerClient: dclient}
|
||||
res, err := d.List()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 3, len(res))
|
||||
require.Equal(t, 4, len(res))
|
||||
|
||||
assert.Equal(t, "^/api/123/(.*)", res[0].SrcMatch.String())
|
||||
assert.Equal(t, "http://127.0.0.2:12345/blah/$1", res[0].Dst)
|
||||
assert.Equal(t, "example.com", res[0].Server)
|
||||
assert.Equal(t, "http://127.0.0.2:12345/ping", res[0].PingURL)
|
||||
|
||||
assert.Equal(t, "^/c2/(.*)", res[1].SrcMatch.String())
|
||||
assert.Equal(t, "http://127.0.0.3:12346/$1", res[1].Dst)
|
||||
assert.Equal(t, "http://127.0.0.3:12346/ping", res[1].PingURL)
|
||||
assert.Equal(t, "*", res[1].Server)
|
||||
assert.Equal(t, "^/api/90/(.*)", res[1].SrcMatch.String())
|
||||
assert.Equal(t, "http://example.com/blah/$1", res[1].Dst)
|
||||
assert.Equal(t, "https://example.com//ping", res[1].PingURL)
|
||||
assert.Equal(t, "example.com", res[1].Server)
|
||||
|
||||
assert.Equal(t, "^/a/(.*)", res[2].SrcMatch.String())
|
||||
assert.Equal(t, "http://127.0.0.2:12348/a/$1", res[2].Dst)
|
||||
assert.Equal(t, "http://127.0.0.2:12348/ping", res[2].PingURL)
|
||||
assert.Equal(t, "example.com", res[2].Server)
|
||||
assert.Equal(t, "^/c2/(.*)", res[2].SrcMatch.String())
|
||||
assert.Equal(t, "http://127.0.0.3:12346/$1", res[2].Dst)
|
||||
assert.Equal(t, "http://127.0.0.3:12346/ping", res[2].PingURL)
|
||||
assert.Equal(t, "*", res[2].Server)
|
||||
|
||||
assert.Equal(t, "^/a/(.*)", res[3].SrcMatch.String())
|
||||
assert.Equal(t, "http://127.0.0.2:12348/a/$1", res[3].Dst)
|
||||
assert.Equal(t, "http://127.0.0.2:12348/ping", res[3].PingURL)
|
||||
assert.Equal(t, "example.com", res[3].Server)
|
||||
}
|
||||
|
||||
func TestDocker_ListMulti(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user