Skip to content

Commit

Permalink
feat(config): ip address should be required and can be a domain
Browse files Browse the repository at this point in the history
  • Loading branch information
budimanjojo committed Sep 21, 2022
1 parent 84f50ed commit af36ff3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/config/validate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type CNIConfig struct {

type Node struct {
Hostname string `validate:"required"`
IPAddress string `validate:"isIP"`
IPAddress string `validate:"required|isDomainOrIP"`
ControlPlane string `validate:"isBool"`
InstallDisk string `validate:"requiredWithout:Nodes.InstallDiskSelector"`
InstallDiskSelector *InstallDiskSelector
Expand Down Expand Up @@ -160,5 +160,6 @@ func (c Config) Messages() map[string]string {
"isBool": "{field} is not a valid boolean (true or false)",
"isInt": "{field} is not a valid integer",
"isUint": "{field} is not a valid unsigned integer",
"isDomainOrIP": "{field} is not a valid domain or IP address",
}
}
8 changes: 8 additions & 0 deletions pkg/config/validate/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,11 @@ func (c Config) IsDomain(domain string) bool {
}
return regexp.MustCompile(`^([a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*[\._]?$`).MatchString(domain)
}

func (c Config) IsDomainOrIP(domainIP string) bool {
if c.IsDomain(domainIP) || validate.IsIP(domainIP) {
return true
}

return false
}

0 comments on commit af36ff3

Please sign in to comment.