2019-06-18 00:52:01 +00:00
|
|
|
package xds
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/proxycfg"
|
2019-07-08 11:48:48 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2019-06-18 00:52:01 +00:00
|
|
|
)
|
|
|
|
|
2019-07-08 11:48:48 +00:00
|
|
|
func UpstreamSNI(u *structs.Upstream, subset string, cfgSnap *proxycfg.ConfigSnapshot) string {
|
|
|
|
if u.DestinationType == "prepared_query" {
|
|
|
|
return QuerySNI(u.DestinationName, u.Datacenter, cfgSnap)
|
|
|
|
}
|
|
|
|
return ServiceSNI(u.DestinationName, subset, u.DestinationNamespace, u.Datacenter, cfgSnap)
|
|
|
|
}
|
|
|
|
|
2019-06-18 00:52:01 +00:00
|
|
|
func DatacenterSNI(dc string, cfgSnap *proxycfg.ConfigSnapshot) string {
|
|
|
|
return fmt.Sprintf("%s.internal.%s", dc, cfgSnap.Roots.TrustDomain)
|
|
|
|
}
|
|
|
|
|
2019-07-02 13:43:35 +00:00
|
|
|
func ServiceSNI(service string, subset string, namespace string, datacenter string, cfgSnap *proxycfg.ConfigSnapshot) string {
|
2019-07-08 11:48:48 +00:00
|
|
|
if namespace == "" {
|
|
|
|
namespace = "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
if datacenter == "" {
|
|
|
|
datacenter = cfgSnap.Datacenter
|
|
|
|
}
|
|
|
|
|
2019-07-02 13:43:35 +00:00
|
|
|
if subset == "" {
|
|
|
|
return fmt.Sprintf("%s.%s.%s.internal.%s", service, namespace, datacenter, cfgSnap.Roots.TrustDomain)
|
|
|
|
} else {
|
|
|
|
return fmt.Sprintf("%s.%s.%s.%s.internal.%s", subset, service, namespace, datacenter, cfgSnap.Roots.TrustDomain)
|
|
|
|
}
|
2019-06-18 00:52:01 +00:00
|
|
|
}
|
2019-07-08 11:48:48 +00:00
|
|
|
|
|
|
|
func QuerySNI(service string, datacenter string, cfgSnap *proxycfg.ConfigSnapshot) string {
|
|
|
|
if datacenter == "" {
|
|
|
|
datacenter = cfgSnap.Datacenter
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s.default.%s.query.%s", service, datacenter, cfgSnap.Roots.TrustDomain)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TargetSNI(target structs.DiscoveryTarget, cfgSnap *proxycfg.ConfigSnapshot) string {
|
|
|
|
return ServiceSNI(target.Service, target.ServiceSubset, target.Namespace, target.Datacenter, cfgSnap)
|
|
|
|
}
|