in proxy/pkg/egress/egress.go [62:106]
func Match(hostname string) (bool, *control.EgressConfig) {
var EgressRules []control.EgressConfig
if meshercontrol.DefaultPanelEgress != nil {
EgressRules = meshercontrol.DefaultPanelEgress.GetEgressRule()
} else {
mapEgressRules := DefaultEgress.FetchEgressRule()
for _, value := range mapEgressRules {
for _, rule := range value {
var Ports []*control.EgressPort
for _, port := range rule.Ports {
p := control.EgressPort{
Port: (*port).Port,
Protocol: (*port).Protocol,
}
Ports = append(Ports, &p)
}
c := control.EgressConfig{
Hosts: rule.Hosts,
Ports: Ports,
}
EgressRules = append(EgressRules, c)
}
}
}
for _, egress := range EgressRules {
for _, host := range egress.Hosts {
// Check host length greater than 0 and does not
// start with *
if len(host) > 0 && string(host[0]) != "*" {
if host == hostname {
return true, &egress
}
} else if string(host[0]) == "*" {
substring := host[1:]
match, _ := regexp.MatchString(substring+"$", hostname)
if match {
return true, &egress
}
}
}
}
return false, nil
}