mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 19:05:42 +03:00
Ensure there are no periods in the service name
This commit is contained in:
@@ -1414,6 +1414,13 @@ func (s *Service) InitFields(job string, taskGroup string, task string) {
|
||||
// Validate checks if the Check definition is valid
|
||||
func (s *Service) Validate() error {
|
||||
var mErr multierror.Error
|
||||
|
||||
// Ensure the name does not have a period in it.
|
||||
// RFC-2782: https://tools.ietf.org/html/rfc2782
|
||||
if strings.Contains(s.Name, ".") {
|
||||
mErr.Errors = append(mErr.Errors, fmt.Errorf("service name can't contain periods: %q", s.Name))
|
||||
}
|
||||
|
||||
for _, c := range s.Checks {
|
||||
if err := c.Validate(); err != nil {
|
||||
mErr.Errors = append(mErr.Errors, err)
|
||||
|
||||
@@ -485,6 +485,14 @@ func TestInvalidServiceCheck(t *testing.T) {
|
||||
if err := s.Validate(); err == nil {
|
||||
t.Fatalf("Service should be invalid")
|
||||
}
|
||||
|
||||
s = Service{
|
||||
Name: "service.name",
|
||||
PortLabel: "bar",
|
||||
}
|
||||
if err := s.Validate(); err != nil {
|
||||
t.Fatalf("Service should be invalid: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDistinctCheckID(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user