Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Remove invalid characters from DC name #349

Merged
merged 1 commit into from
Jun 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions uchiwa/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/rand"
"os"
"strings"

"github.com/palourde/logger"
"github.com/sensu/uchiwa/uchiwa/auth"
Expand Down Expand Up @@ -99,6 +100,10 @@ func (c *Config) initSensu() {
logger.Warningf("Sensu API %s has no name property. Generating random one...", api.URL)
c.Sensu[i].Name = fmt.Sprintf("sensu-%v", rand.Intn(100))
}
// escape special characters in DC name
r := strings.NewReplacer(":", "", "/", "", ";", "", "?", "")
c.Sensu[i].Name = r.Replace(api.Name)

if api.Host == "" {
logger.Fatalf("Sensu API %q Host is missing", api.Name)
}
Expand Down
19 changes: 18 additions & 1 deletion uchiwa/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestLoad(t *testing.T) {
assert.NotEqual(t, "*****", conf.Uchiwa.User, "Uchiwa user in private config shouldn't be masked")
assert.NotEqual(t, "*****", conf.Uchiwa.Pass, "Uchiwa pass in private config shouldn't be masked")
for i := range conf.Sensu {
assert.NotEqual(t, "*****",conf.Sensu[i].User, "Sensu APIs user in private config shouldn't be masked")
assert.NotEqual(t, "*****", conf.Sensu[i].User, "Sensu APIs user in private config shouldn't be masked")
assert.NotEqual(t, "*****", conf.Sensu[i].Pass, "Sensu APIs pass in private config shouldn't be masked")
}
assert.Equal(t, 1, len(conf.Uchiwa.Users))
Expand Down Expand Up @@ -55,3 +55,20 @@ func TestLoadArrayOfUsersOnPublicGet(t *testing.T) {
public := conf.GetPublic()
assert.Equal(t, 0, len(public.Uchiwa.Users))
}

func TestInitSensu(t *testing.T) {
c := Config{
Sensu: []SensuConfig{
{Name: "foo ? bar", Host: "127.0.0.1"},
{Name: "bar / foo", Host: "127.0.0.1"},
},
}

c.initSensu()

expectedConfig := []SensuConfig{
{Name: "foo bar", Host: "127.0.0.1", Port: 4567, Ssl: false, Insecure: false, URL: "http://127.0.0.1:4567", User: "", Path: "", Pass: "", Timeout: 10},
{Name: "bar foo", Host: "127.0.0.1", Port: 4567, Ssl: false, Insecure: false, URL: "http://127.0.0.1:4567", User: "", Path: "", Pass: "", Timeout: 10},
}
assert.Equal(t, expectedConfig, c.Sensu)
}