Esempio 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))
}
import (
	"path"
	"path/filepath"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/pivotal-cf/cf-redis-broker/agentconfig"
)

var _ = Describe("Config", func() {
	Describe("Load", func() {
		Context("When the file does not exist", func() {
			It("returns an error", func() {
				_, err := agentconfig.Load("/this/is/an/invalid/path")
				Expect(err.Error()).To(Equal("open /this/is/an/invalid/path: no such file or directory"))
			})
		})

		Context("When the file is successfully loaded", func() {
			var config *agentconfig.Config

			BeforeEach(func() {
				path, err := filepath.Abs(path.Join("assets", "agent.yml"))
				Expect(err).ToNot(HaveOccurred())

				config, err = agentconfig.Load(path)
				Expect(err).ToNot(HaveOccurred())
			})