2018-11-08 17:22:26 +08:00
|
|
|
// RAINBOND, Application Management Platform
|
|
|
|
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version. For any non-GPL usage of Rainbond,
|
|
|
|
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
|
|
|
|
// must be obtained first.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package v1
|
|
|
|
|
2019-03-10 18:51:10 +08:00
|
|
|
import (
|
|
|
|
"github.com/goodrain/rainbond/gateway/annotations/proxy"
|
|
|
|
"github.com/goodrain/rainbond/gateway/annotations/rewrite"
|
|
|
|
)
|
|
|
|
|
2018-12-01 10:27:14 +08:00
|
|
|
// ConditionType condition type
|
2018-11-18 11:53:11 +08:00
|
|
|
type ConditionType string
|
|
|
|
|
2018-12-01 10:27:14 +08:00
|
|
|
// HeaderType -
|
2018-11-18 11:53:11 +08:00
|
|
|
var HeaderType ConditionType = "header"
|
2018-12-01 10:27:14 +08:00
|
|
|
|
|
|
|
// CookieType -
|
2018-11-18 11:53:11 +08:00
|
|
|
var CookieType ConditionType = "cookie"
|
2018-12-01 10:27:14 +08:00
|
|
|
|
|
|
|
// DefaultType -
|
2018-11-18 11:53:11 +08:00
|
|
|
var DefaultType ConditionType = "default"
|
|
|
|
|
2018-12-01 10:27:14 +08:00
|
|
|
// Location -
|
2018-11-08 17:22:26 +08:00
|
|
|
type Location struct {
|
2018-11-18 11:53:11 +08:00
|
|
|
Path string
|
2019-02-12 15:40:42 +08:00
|
|
|
NameCondition map[string]*Condition // papping between backend name and condition
|
2019-03-10 18:51:10 +08:00
|
|
|
// Rewrite describes the redirection this location.
|
|
|
|
// +optional
|
|
|
|
Rewrite rewrite.Config `json:"rewrite,omitempty"`
|
|
|
|
// Proxy contains information about timeouts and buffer sizes
|
|
|
|
// to be used in connections against endpoints
|
|
|
|
// +optional
|
2019-04-02 16:19:30 +08:00
|
|
|
Proxy proxy.Config `json:"proxy,omitempty"`
|
|
|
|
DisableProxyPass bool
|
2018-11-18 11:53:11 +08:00
|
|
|
}
|
|
|
|
|
2018-12-01 10:27:14 +08:00
|
|
|
// Condition is the condition that the traffic can reach the specified backend
|
2018-11-18 11:53:11 +08:00
|
|
|
type Condition struct {
|
|
|
|
Type ConditionType
|
|
|
|
Value map[string]string
|
2018-11-08 17:22:26 +08:00
|
|
|
}
|
|
|
|
|
2018-12-01 10:27:14 +08:00
|
|
|
// Equals determines if two locations are equal
|
2018-11-08 17:22:26 +08:00
|
|
|
func (l *Location) Equals(c *Location) bool {
|
|
|
|
if l == c {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if l == nil || c == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if l.Path != c.Path {
|
|
|
|
return false
|
|
|
|
}
|
2018-11-18 11:53:11 +08:00
|
|
|
|
|
|
|
if len(l.NameCondition) != len(c.NameCondition) {
|
2018-11-08 17:22:26 +08:00
|
|
|
return false
|
|
|
|
}
|
2018-11-18 11:53:11 +08:00
|
|
|
for name, lc := range l.NameCondition {
|
|
|
|
if cc, exists := c.NameCondition[name]; !exists || !cc.Equals(lc) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 20:24:26 +08:00
|
|
|
if !l.Proxy.Equal(&c.Proxy) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-11-18 11:53:11 +08:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-12-01 10:27:14 +08:00
|
|
|
// Equals determines if two conditions are equal
|
2018-11-18 11:53:11 +08:00
|
|
|
func (c *Condition) Equals(cc *Condition) bool {
|
|
|
|
if c == cc {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if c == nil || cc == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if c.Type != cc.Type {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(c.Value) != len(cc.Value) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for k, v := range c.Value {
|
2019-02-12 15:40:42 +08:00
|
|
|
if vv, ok := cc.Value[k]; !ok || v != vv {
|
2018-11-18 11:53:11 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-08 17:22:26 +08:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFakeLocation() *Location {
|
|
|
|
return &Location{
|
2018-11-18 11:53:11 +08:00
|
|
|
Path: "foo-path",
|
2018-11-08 17:22:26 +08:00
|
|
|
}
|
|
|
|
}
|