Skip to content

Commit 66184cd

Browse files
authored
support multiple subdomains of the name gateways (#2356)
1 parent fd7d15f commit 66184cd

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

pkg/gateway/gateway.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ func (g *gatewayModule) validateNameContract(name string, twinID uint32) error {
541541
}
542542
contract, subErr := g.substrateGateway.GetContract(context.Background(), contractID)
543543
if subErr.IsCode(pkg.CodeNotFound) {
544-
return fmt.Errorf("contract by name returned %d, but retreiving it results in 'not found' error", contractID)
544+
return fmt.Errorf("contract by name returned %d, but retrieving it results in 'not found' error", contractID)
545545
} else if subErr.IsError() {
546546
return subErr.Err
547547
}
@@ -573,7 +573,11 @@ func (g *gatewayModule) SetNamedProxy(wlID string, config zos.GatewayNameProxy)
573573
if cfg.Domain == "" {
574574
return "", errors.New("node doesn't support name proxy (doesn't have a domain)")
575575
}
576-
if err := g.validateNameContract(config.Name, twinID); err != nil {
576+
577+
subdomains := strings.Split(config.Name, ".")
578+
reservedName := subdomains[len(subdomains)-1]
579+
580+
if err := g.validateNameContract(reservedName, twinID); err != nil {
577581
return "", errors.Wrap(err, "failed to verify name contract")
578582
}
579583

pkg/gridtypes/zos/gw_name.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/threefoldtech/zos/pkg/gridtypes"
99
)
1010

11-
var gwNameRegex = regexp.MustCompile(`^[a-zA-Z0-9-_]+$`)
11+
var gwNameRegex = regexp.MustCompile(`^([a-zA-Z0-9-_]+\.)?[a-zA-Z0-9-_]+$`)
1212

1313
// GatewayNameProxy definition. this will proxy name.<zos.domain> to backends
1414
type GatewayNameProxy struct {

0 commit comments

Comments
 (0)