Ejemplo n.º 1
0
func main() {
	configPath := flag.String("agentConfig", "", "Agent config yaml")
	flag.Parse()

	logger := lager.NewLogger("redis-agent")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
	logger.RegisterSink(lager.NewWriterSink(os.Stderr, lager.ERROR))

	config, err := agentconfig.Load(*configPath)
	if err != nil {
		logger.Fatal("Error loading config file", err, lager.Data{
			"path": *configPath,
		})
	}

	templateRedisConf(config, logger)

	redisResetter := resetter.New(
		config.DefaultConfPath,
		config.ConfPath,
		portChecker{},
		commandRunner{},
		config.MonitExecutablePath,
	)

	handler := auth.NewWrapper(
		config.AuthConfiguration.Username,
		config.AuthConfiguration.Password,
	).Wrap(
		agentapi.New(redisResetter, config.ConfPath),
	)

	http.Handle("/", handler)
	logger.Fatal("http-listen", http.ListenAndServe("localhost:"+config.Port, nil))
}
Ejemplo n.º 2
0
	var server *httptest.Server
	var redisClient *fakeRedisResetter
	var deleteCount int
	var configPath string
	var response *http.Response

	BeforeEach(func() {
		var err error
		configPath, err = filepath.Abs("assets/redis.conf")
		Ω(err).ShouldNot(HaveOccurred())
		redisClient = &fakeRedisResetter{}
		deleteCount = 0
	})

	JustBeforeEach(func() {
		handler := agentapi.New(redisClient, configPath)
		server = httptest.NewServer(handler)
	})

	AfterEach(func() {
		server.Close()
	})

	Describe("GET /", func() {
		JustBeforeEach(func() {
			response = makeRequest("GET", server.URL)
		})

		Context("When it can read the conf file successfully", func() {
			It("returns the correct credentials", func() {
				body, err := ioutil.ReadAll(response.Body)