mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 15:49:58 +00:00
TUN-3464: Newtype to wrap []ingress.Rule
This commit is contained in:
@@ -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
|
||||
|
@@ -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())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user