Skip to content

Commit

Permalink
Merge pull request #770 from hashicorp/f-service-name-period
Browse files Browse the repository at this point in the history
Ensure there are no periods in the service name
  • Loading branch information
dadgar committed Feb 5, 2016
2 parents 18cf58e + 7d3be2b commit c175213
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions nomad/structs/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c175213

Please sign in to comment.