Esempio n. 1
0
File: common.go Progetto: ovh/tat
// Init the test context with the database
func Init(t *testing.T) {
	if initiliazed {
		return
	}
	log.SetLevel(log.DebugLevel)
	log.SetFormatter(&log.TextFormatter{
		ForceColors:      true,
		DisableTimestamp: true,
	})

	flag.StringVar(&dbAddr, "db-addr", "127.0.0.1:27017", "Address of the mongodb server")
	flag.StringVar(&dbUser, "db-user", "", "User to authenticate with the mongodb server")
	flag.StringVar(&dbPassword, "db-password", "", "Password to authenticate with the mongodb server")
	flag.StringVar(&redisAddr, "redis-addr", "127.0.0.1:6379", "Address of the redis server")
	flag.StringVar(&redisPassword, "redis-password", "", "Password to authenticate with the redis server")

	flag.Parse()

	viper.Set("db_addr", dbAddr)
	viper.Set("db_user", dbUser)
	viper.Set("db_password", dbPassword)
	viper.Set("redis_hosts", redisAddr)
	viper.Set("redis_password", redisPassword)
	viper.Set("header_trust_username", "X-Remote-User")

	if err := store.NewStore(); err != nil {
		t.Errorf("Error initializing test context : %s", err)
		t.Fail()
		return
	}

	log.Infof("Connected to database %s", dbAddr)
	initiliazed = true
}
Esempio n. 2
0
File: main.go Progetto: ovh/tat
		//   - Logs all requests, like a combined access and error log.
		//   - Logs to stdout.
		//   - RFC3339 with UTC time format.
		router.Use(ginrus(log.StandardLogger(), time.RFC3339, true))

		router.Use(cors.Middleware(cors.Config{
			Origins:         "*",
			Methods:         "GET, PUT, POST, DELETE",
			RequestHeaders:  "Origin, Authorization, Content-Type, Accept, Tat_Password, Tat_Username",
			ExposedHeaders:  "Tat_Password, Tat_Username",
			MaxAge:          50 * time.Second,
			Credentials:     true,
			ValidateHeaders: false,
		}))

		if err := store.NewStore(); err != nil {
			log.Fatalf("Error trying to reach mongoDB. Please check your Tat Configuration and access to your MongoDB. Err: %s", err.Error())
		}
		topic.InitDB()
		group.InitDB()
		message.InitDB()

		routerRoot := router.Group("")

		initRoutesGroups(routerRoot, CheckPassword())
		initRoutesMessages(routerRoot, CheckPassword())
		initRoutesPresences(routerRoot, CheckPassword())
		initRoutesTopics(routerRoot, CheckPassword())
		initRoutesUsers(routerRoot, CheckPassword())
		initRoutesStats(routerRoot, CheckPassword())
		initRoutesSystem(routerRoot, CheckPassword())