2018-12-01 10:26:35 +08:00
|
|
|
package openresty
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/goodrain/rainbond/gateway/controller/openresty/model"
|
|
|
|
"github.com/goodrain/rainbond/gateway/v1"
|
|
|
|
)
|
|
|
|
|
2018-12-04 20:43:03 +08:00
|
|
|
func langGoodrainMe(ip string) (*model.Server, *model.Upstream) {
|
2018-12-01 10:26:35 +08:00
|
|
|
svr := &model.Server{
|
2018-12-04 21:56:29 +08:00
|
|
|
Listen: fmt.Sprintf("%s:%d", ip, 80), // TODO: change ip address
|
2018-12-01 10:26:35 +08:00
|
|
|
ServerName: "lang.goodrain.me",
|
|
|
|
Rewrites: []model.Rewrite{
|
|
|
|
{
|
|
|
|
Regex: "^/(.*)$",
|
|
|
|
Replacement: "/artifactory/pkg_lang/$1",
|
|
|
|
Flag: "break",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Locations: []*model.Location{
|
|
|
|
{
|
2018-12-04 21:56:29 +08:00
|
|
|
Path: "/",
|
|
|
|
ProxyRedirect: "off",
|
2018-12-01 10:26:35 +08:00
|
|
|
ProxyConnectTimeout: model.Time{Num: 60, Unit: "s"},
|
2018-12-04 21:56:29 +08:00
|
|
|
ProxyReadTimeout: model.Time{Num: 600, Unit: "s"},
|
|
|
|
ProxySendTimeout: model.Time{Num: 600, Unit: "s"},
|
2018-12-01 10:26:35 +08:00
|
|
|
ProxySetHeaders: []*model.ProxySetHeader{
|
|
|
|
{Field: "Host", Value: "$http_host"},
|
|
|
|
{Field: "X-Real-IP", Value: "$remote_addr"},
|
|
|
|
{Field: "X-Forwarded-For", Value: "$proxy_add_x_forwarded_for"},
|
|
|
|
},
|
|
|
|
NameCondition: map[string]*v1.Condition{
|
2018-12-04 21:56:29 +08:00
|
|
|
"lang": {
|
2018-12-01 10:26:35 +08:00
|
|
|
Type: v1.DefaultType,
|
|
|
|
Value: map[string]string{"1": "1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
us := &model.Upstream{
|
|
|
|
Name: "lang",
|
|
|
|
}
|
|
|
|
return svr, us
|
|
|
|
}
|
|
|
|
|
2018-12-04 20:43:03 +08:00
|
|
|
func mavenGoodrainMe(ip string) (*model.Server, *model.Upstream) {
|
2018-12-01 10:26:35 +08:00
|
|
|
svr := &model.Server{
|
2018-12-04 20:43:03 +08:00
|
|
|
Listen: fmt.Sprintf("%s:%d", ip, 80),
|
2018-12-01 10:26:35 +08:00
|
|
|
ServerName: "maven.goodrain.me",
|
|
|
|
Locations: []*model.Location{
|
|
|
|
{
|
|
|
|
Path: "/",
|
|
|
|
Rewrites: []model.Rewrite{
|
|
|
|
{
|
|
|
|
Regex: "^/(.*)$",
|
|
|
|
Replacement: "/artifactory/libs-release/$1",
|
|
|
|
Flag: "break",
|
|
|
|
},
|
|
|
|
},
|
2018-12-04 21:56:29 +08:00
|
|
|
ProxyRedirect: "off",
|
2018-12-01 10:26:35 +08:00
|
|
|
ProxyConnectTimeout: model.Time{Num: 60, Unit: "s"},
|
2018-12-04 21:56:29 +08:00
|
|
|
ProxyReadTimeout: model.Time{Num: 600, Unit: "s"},
|
|
|
|
ProxySendTimeout: model.Time{Num: 600, Unit: "s"},
|
2018-12-01 10:26:35 +08:00
|
|
|
ProxySetHeaders: []*model.ProxySetHeader{
|
|
|
|
{Field: "Host", Value: "$http_host"},
|
|
|
|
{Field: "X-Real-IP", Value: "$remote_addr"},
|
|
|
|
{Field: "X-Forwarded-For", Value: "$proxy_add_x_forwarded_for"},
|
|
|
|
},
|
|
|
|
NameCondition: map[string]*v1.Condition{
|
2018-12-04 21:56:29 +08:00
|
|
|
"maven": {
|
2018-12-01 10:26:35 +08:00
|
|
|
Type: v1.DefaultType,
|
|
|
|
Value: map[string]string{"1": "1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2018-12-04 21:56:29 +08:00
|
|
|
Path: "/monitor",
|
|
|
|
Return: model.Return{Code: 204},
|
2018-12-01 10:26:35 +08:00
|
|
|
DisableProxyPass: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
us := &model.Upstream{
|
|
|
|
Name: "maven",
|
|
|
|
}
|
|
|
|
return svr, us
|
|
|
|
}
|
|
|
|
|
2018-12-04 20:43:03 +08:00
|
|
|
func goodrainMe(cfgPath string, ip string) (*model.Server, *model.Upstream) {
|
2018-12-01 10:26:35 +08:00
|
|
|
svr := &model.Server{
|
2018-12-04 21:56:29 +08:00
|
|
|
Listen: fmt.Sprintf("%s:%d %s", ip, 443, "ssl"),
|
|
|
|
ServerName: "goodrain.me",
|
|
|
|
SSLCertificate: fmt.Sprintf("%s/%s", cfgPath, "ssl/server.crt"),
|
|
|
|
SSLCertificateKey: fmt.Sprintf("%s/%s", cfgPath, "ssl/server.key"),
|
|
|
|
ClientMaxBodySize: model.Size{Num: 0, Unit: "k"},
|
2018-12-01 10:26:35 +08:00
|
|
|
ChunkedTransferEncoding: true,
|
|
|
|
Locations: []*model.Location{
|
|
|
|
{
|
|
|
|
Path: "/v2/",
|
|
|
|
ProxySetHeaders: []*model.ProxySetHeader{
|
|
|
|
{Field: "Host", Value: "$http_host"},
|
|
|
|
{Field: "X-Real-IP", Value: "$remote_addr"},
|
|
|
|
{Field: "X-Forwarded-For", Value: "$proxy_add_x_forwarded_for"},
|
|
|
|
{Field: "X-Forwarded-Proto", Value: "$scheme"},
|
|
|
|
},
|
|
|
|
ProxyReadTimeout: model.Time{
|
2018-12-04 21:56:29 +08:00
|
|
|
Num: 900,
|
2018-12-01 10:26:35 +08:00
|
|
|
Unit: "s",
|
|
|
|
},
|
|
|
|
NameCondition: map[string]*v1.Condition{
|
2018-12-04 21:56:29 +08:00
|
|
|
"registry": {
|
2018-12-01 10:26:35 +08:00
|
|
|
Type: v1.DefaultType,
|
|
|
|
Value: map[string]string{"1": "1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
us := &model.Upstream{
|
|
|
|
Name: "registry",
|
|
|
|
}
|
|
|
|
return svr, us
|
|
|
|
}
|