Skip to content

Commit

Permalink
Modifiy the format validation of fqdn gateway backend
Browse files Browse the repository at this point in the history
  • Loading branch information
sameh-farouk committed Nov 21, 2022
1 parent 617be50 commit 780ca76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 6 additions & 2 deletions pkg/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,12 @@ func (g *gatewayModule) setupRouting(wlID string, fqdn string, backends []string
if err != nil {
return errors.Wrap(err, "couldn't parse backend host")
}
if u.Scheme != "https" {
return errors.New("enabling tls passthrough requires backends to have https scheme")
if u.Scheme != "" {
return errors.New("enabling tls passthrough requires backends to have no scheme")
}

if u.Port() == "" {
return errors.New("enabling tls passthrough requires backends to have a port")
}
servers[idx] = Server{
Address: u.Host,
Expand Down
12 changes: 9 additions & 3 deletions pkg/gridtypes/zos/gw_fqdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ var (

type Backend string

// check if valid http://x.x.x.x:port or [::]:port
// check if valid http://ip:port, http://ip or ip:port
func (b Backend) Valid() error {
u, err := url.Parse(string(b))
if err != nil {
return errors.Wrap(err, "failed to parse backend")
}
if u.Scheme != "http" && u.Scheme != "https" {
return fmt.Errorf("invalid scheme expected http, or https")
if u.Scheme != "" {
if u.Scheme != "http" {
return fmt.Errorf("invalid scheme expected either http, or empty")
}
} else {
if u.Port() == "" {
return fmt.Errorf("backend missing either scheme or port")
}
}

ip := net.ParseIP(u.Hostname())
Expand Down

0 comments on commit 780ca76

Please sign in to comment.