Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #253 from threefoldtech/issue/domain-name-validation
Browse files Browse the repository at this point in the history
validate gateway registration
  • Loading branch information
xmonader authored Dec 21, 2020
2 parents a079285 + aec5236 commit 7336d47
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/threefoldtech/tfexplorer
go 1.14

require (
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/dave/jennifer v1.3.0
github.com/emicklei/dot v0.10.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ github.com/asaskevich/govalidator v0.0.0-20180319081651-7d2e70ef918f/go.mod h1:l
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg=
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef h1:46PFijGLmAjMPwCCCo7Jf0W6f9slllCkkv7vyc1yOSg=
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/aws/aws-sdk-go v1.25.25/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down
4 changes: 4 additions & 0 deletions pkg/directory/gateway_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (s *GatewayAPI) registerGateway(r *http.Request) (interface{}, mw.Response)
return nil, mw.BadRequest(err)
}

if err := gw.Validate(); err != nil {
return nil, mw.BadRequest(err)
}

db := mw.Database(r)
if _, err := s.Add(r.Context(), db, gw); err != nil {
return nil, mw.Error(err)
Expand Down
7 changes: 7 additions & 0 deletions pkg/directory/types/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"time"

"github.com/asaskevich/govalidator"
"github.com/jbenet/go-base58"
"github.com/pkg/errors"
"github.com/threefoldtech/tfexplorer/models"
Expand Down Expand Up @@ -47,6 +48,12 @@ func (n *Gateway) Validate() error {
return fmt.Errorf("nodeID and public key does not match")
}

for _, domain := range n.ManagedDomains {
if !govalidator.IsDNSName(domain) {
return fmt.Errorf("domain name '%s' is invalid", domain)
}
}

// Unfortunately, jsx schema does not support nil types
// so this is the only way to check if values are not set
empty := generated.Location{}
Expand Down

0 comments on commit 7336d47

Please sign in to comment.