TUN-3464: Newtype to wrap []ingress.Rule

This commit is contained in:
Adam Chalmers
2020-10-15 12:41:50 -05:00
parent 4a4a1bb6b1
commit c96b9e8d8f
5 changed files with 59 additions and 50 deletions

View File

@@ -196,15 +196,15 @@ func ValidateUrl(c *cli.Context, allowFromArgs bool) (string, error) {
return validUrl, err
}
func ReadRules(c *cli.Context) ([]ingress.Rule, error) {
func ReadRules(c *cli.Context) (ingress.Ingress, error) {
configFilePath := c.String("config")
if configFilePath == "" {
return nil, ErrNoConfigFile
return ingress.Ingress{}, ErrNoConfigFile
}
fmt.Printf("Reading from config file %s\n", configFilePath)
configBytes, err := ioutil.ReadFile(configFilePath)
if err != nil {
return nil, err
return ingress.Ingress{}, err
}
rules, err := ingress.ParseIngress(configBytes)
return rules, err

View File

@@ -219,7 +219,7 @@ func prepareTunnelConfig(
}
dialContext := dialer.DialContext
var ingressRules []ingress.Rule
var ingressRules ingress.Ingress
if namedTunnel != nil {
clientUUID, err := uuid.NewRandom()
if err != nil {
@@ -235,14 +235,13 @@ func prepareTunnelConfig(
if err != nil && err != ingress.ErrNoIngressRules {
return nil, err
}
if len(ingressRules) > 0 && c.IsSet("url") {
if !ingressRules.IsEmpty() && c.IsSet("url") {
return nil, ingress.ErrURLIncompatibleWithIngress
}
}
var originURL string
isUsingMultipleOrigins := len(ingressRules) > 0
if !isUsingMultipleOrigins {
if ingressRules.IsEmpty() {
originURL, err = config.ValidateUrl(c, compatibilityMode)
if err != nil {
logger.Errorf("Error validating origin URL: %s", err)
@@ -275,10 +274,10 @@ func prepareTunnelConfig(
// List all origin URLs that require validation
var originURLs []string
if !isUsingMultipleOrigins {
if ingressRules.IsEmpty() {
originURLs = append(originURLs, originURL)
} else {
for _, rule := range ingressRules {
for _, rule := range ingressRules.Rules {
originURLs = append(originURLs, rule.Service.String())
}
}