Ejemplo n.º 1
0
// Run starts the Martini webapp handler
func (subway *Broker) Run() {
	username := os.Getenv("SUBWAY_USERNAME")
	if username == "" {
		username = "******"
	}

	password := os.Getenv("SUBWAY_PASSWORD")
	if password == "" {
		password = "******"
	}

	credentials := brokerapi.BrokerCredentials{
		Username: username,
		Password: password,
	}
	fmt.Println(credentials)

	port := os.Getenv("PORT")
	if port == "" {
		port = "3000"
	}

	brokerAPI := brokerapi.New(subway, subway.Logger, credentials)
	http.Handle("/", brokerAPI)
	subway.Logger.Fatal("http-listen", http.ListenAndServe(fmt.Sprintf("0.0.0.0:%s", port), nil))
}
Ejemplo n.º 2
0
func main() {
	flag.Parse()

	logger := lager.NewLogger("cf-rabbitmq-broker")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))
	logger.RegisterSink(lager.NewWriterSink(os.Stderr, lager.ERROR))

	rand.Seed(time.Now().UTC().UnixNano())

	config, err := rabbitbroker.ReadConfig(configPath)
	if err != nil {
		logger.Fatal("read-config", err)
	}

	client, _ := rabbithole.NewClient(
		fmt.Sprintf("http://%s:15672", config.Rabbitmq.Hosts[0]),
		config.Rabbitmq.Administrator.Username,
		config.Rabbitmq.Administrator.Password)

	serviceBroker := rabbitbroker.New(config, client, rabbitbroker.RandomCredentialsGenerator{}, logger, rabbitbroker.BindingInfoResource{ProtocolInfo: rabbitbroker.ProtocolInfoResource{}})

	credentials := brokerapi.BrokerCredentials{
		Username: config.Service.Username,
		Password: config.Service.Password,
	}

	http.Handle("/", brokerapi.New(serviceBroker, logger, credentials))

	logger.Info("starting-server")
	if err := http.ListenAndServe(":4567", nil); err != nil {
		logger.Fatal("starting-server-failed", err)
	}
}
Ejemplo n.º 3
0
func main() {

	var err error

	brokerConfig, err = config.LoadFromFile(*configFile)
	if err != nil {
		panic(fmt.Errorf("configuration load error from file %s. Err: %s", *configFile, err))
	}

	serviceBroker := &myServiceBroker{}

	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))

	logger.Debug("config-load-success", lager.Data{"file-source": *configFile, "config": brokerConfig})

	credentials := brokerapi.BrokerCredentials{
		Username: "******",
		Password: "******",
	}

	addr := getListeningAddr(brokerConfig)

	brokerAPI := brokerapi.New(serviceBroker, logger, credentials)

	http.Handle("/", brokerAPI)

	http.ListenAndServe(addr, nil)
	if err != nil {
		logger.Error("error-listenting", err)
	}
}
Ejemplo n.º 4
0
func main() {
	var port string
	serviceBroker := &myServiceBroker{}
	logger := lager.NewLogger("my-service-broker")
	credentials := brokerapi.BrokerCredentials{
		Username: "******",
		Password: "******",
	}

	port = os.Getenv("VCAP_APP_PORT")
	brokerAPI := brokerapi.New(serviceBroker, logger, credentials)
	http.Handle("/", brokerAPI)
	http.ListenAndServe("0.0.0.0:"+port, nil)
}
Ejemplo n.º 5
0
func main() {
	dbCreator := database.NewCreator("username", "password", "hostname", 123)

	serviceBroker := &exampleServiceBroker{
		dbCreator: dbCreator,
		instances: map[string]string{},
	}
	logger := lager.NewLogger("cf-example-broker")
	credentials := brokerapi.BrokerCredentials{
		Username: "******",
		Password: "******",
	}

	brokerAPI := brokerapi.New(serviceBroker, logger, credentials)
	http.Handle("/", brokerAPI)
	http.ListenAndServe(":3000", nil)
}
Ejemplo n.º 6
0
func main() {
	ipAddress := os.Getenv("REDIS_IP")

	serviceBroker := broker.New(broker.DatabaseIDs{}, ipAddress)
	logger := lager.NewLogger("redis-service-broker")
	credentials := brokerapi.BrokerCredentials{
		Username: "******",
		Password: "******",
	}

	brokerAPI := brokerapi.New(&serviceBroker, logger, credentials)
	fmt.Println("Listening on port " + os.Getenv("PORT") + " with IP " + ipAddress)
	http.Handle("/", brokerAPI)
	if err := http.ListenAndServe(":"+os.Getenv("PORT"), nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
Ejemplo n.º 7
0
func runMain(writer io.Writer) {

	if !flag.Parsed() {
		flag.Parse()
	}
	var err error
	brokerConfig, err = config.LoadFromFile(*configFile)

	if err != nil {
		panic(fmt.Errorf("configuration load error from file %s. Err: %s", *configFile, err))
	}

	logger.RegisterSink(lager.NewWriterSink(writer, getLogLevel(brokerConfig)))

	logger.Debug("config-load-success", lager.Data{"file-source": *configFile, "config": brokerConfig})

	mssqlPars := brokerConfig.BrokerMssqlConnection

	// set default sql driver if it is not set based on the OS
	if _, ok := mssqlPars["driver"]; !ok && brokerConfig.BrokerGoSqlDriver == "odbc" {
		if runtime.GOOS != "windows" {
			mssqlPars["driver"] = "freetds"
		} else {
			mssqlPars["driver"] = "sql server"
		}
	}

	mssqlProv = provisioner.NewMssqlProvisioner(logger, brokerConfig.BrokerGoSqlDriver, mssqlPars)
	err = mssqlProv.Init()
	if err != nil {
		logger.Fatal("error-initializing-provisioner", err)
	}

	serviceBroker := &mssqlServiceBroker{}

	brokerAPI := brokerapi.New(serviceBroker, logger, brokerConfig.Crednetials)
	http.Handle("/", brokerAPI)

	addr := getListeningAddr(brokerConfig)
	logger.Info("start-listening", lager.Data{"addr": addr})

	err = http.ListenAndServe(addr, exitOnPanicWrapper{http.DefaultServeMux})
	if err != nil {
		logger.Fatal("error-listening", err)
	}
}
Ejemplo n.º 8
0
func main() {
	sqlConn := ExtractDBSQL()
	basicAuthInfo := ExtractBasicAuthInfo()
	cloudControllerInfo := ExtractCloudControllerInfo()
	lo.G.Debug("cloud controller", cloudControllerInfo)
	chaos := chaospeddler.NewServiceBroker(
		chaospeddler.NewMaestro(
			cloudControllerInfo.Username,
			cloudControllerInfo.Password,
			cloudControllerInfo.LoginURL,
			cloudControllerInfo.CCURL,
			sqlConn,
		),
	)
	chaos.Start()
	logger := lager.NewLogger("chaos-peddler-servicebroker")
	credentials := brokerapi.BrokerCredentials{
		Username: basicAuthInfo.Username,
		Password: basicAuthInfo.Password,
	}
	brokerAPI := brokerapi.New(chaos, logger, credentials)
	http.Handle("/", brokerAPI)
	http.ListenAndServe(":"+os.Getenv("PORT"), nil)
}
Ejemplo n.º 9
0
	lastLogLine := func() lager.LogFormat {
		if len(brokerLogger.Logs()) == 0 {
			// better way to raise error?
			err := errors.New("expected some log lines but there were none!")
			Expect(err).NotTo(HaveOccurred())
		}

		return brokerLogger.Logs()[0]
	}

	BeforeEach(func() {
		fakeServiceBroker = &fakes.FakeServiceBroker{
			InstanceLimit: 3,
		}
		brokerLogger = lagertest.NewTestLogger("broker-api")
		brokerAPI = brokerapi.New(fakeServiceBroker, brokerLogger, credentials)
	})

	Describe("respose headers", func() {
		makeRequest := func() *httptest.ResponseRecorder {
			recorder := httptest.NewRecorder()
			request, _ := http.NewRequest("GET", "/v2/catalog", nil)
			request.SetBasicAuth(credentials.Username, credentials.Password)
			brokerAPI.ServeHTTP(recorder, request)
			return recorder
		}

		It("has a Content-Type header", func() {
			response := makeRequest()

			header := response.Header().Get("Content-Type")
Ejemplo n.º 10
0
func main() {
	brokerConfigPath := configPath()

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

	brokerLogger.Info("Starting CF Redis broker")

	brokerLogger.Info("Config File: " + brokerConfigPath)

	config, err := brokerconfig.ParseConfig(brokerConfigPath)
	if err != nil {
		brokerLogger.Fatal("Loading config file", err, lager.Data{
			"broker-config-path": brokerConfigPath,
		})
	}

	commandRunner := system.OSCommandRunner{
		Logger: brokerLogger,
	}

	localRepo := redis.NewLocalRepository(config.RedisConfiguration, brokerLogger)

	localRepo.AllInstancesVerbose()

	processController := &redis.OSProcessController{
		CommandRunner:            commandRunner,
		InstanceInformer:         localRepo,
		Logger:                   brokerLogger,
		ProcessChecker:           &process.ProcessChecker{},
		ProcessKiller:            &process.ProcessKiller{},
		PingFunc:                 redis.PingServer,
		WaitUntilConnectableFunc: availability.Check,
	}

	localCreator := &redis.LocalInstanceCreator{
		FindFreePort:            system.FindFreePort,
		RedisConfiguration:      config.RedisConfiguration,
		ProcessController:       processController,
		LocalInstanceRepository: localRepo,
	}

	agentClient := &redis.RemoteAgentClient{
		HttpAuth: config.AuthConfiguration,
	}
	remoteRepo, err := redis.NewRemoteRepository(agentClient, config, brokerLogger)
	if err != nil {
		brokerLogger.Fatal("Error initializing remote repository", err)
	}

	sigChannel := make(chan os.Signal, 1)
	signal.Notify(sigChannel, syscall.SIGTERM)
	go func() {
		<-sigChannel
		brokerLogger.Info("Starting Redis Broker shutdown")
		localRepo.AllInstancesVerbose()
		remoteRepo.StateFromFile()
		os.Exit(0)
	}()

	serviceBroker := &broker.RedisServiceBroker{
		InstanceCreators: map[string]broker.InstanceCreator{
			"shared":    localCreator,
			"dedicated": remoteRepo,
		},
		InstanceBinders: map[string]broker.InstanceBinder{
			"shared":    localRepo,
			"dedicated": remoteRepo,
		},
		Config: config,
	}

	brokerCredentials := brokerapi.BrokerCredentials{
		Username: config.AuthConfiguration.Username,
		Password: config.AuthConfiguration.Password,
	}

	brokerAPI := brokerapi.New(serviceBroker, brokerLogger, brokerCredentials)

	authWrapper := auth.NewWrapper(brokerCredentials.Username, brokerCredentials.Password)
	debugHandler := authWrapper.WrapFunc(debug.NewHandler(remoteRepo))
	instanceHandler := authWrapper.WrapFunc(redisinstance.NewHandler(remoteRepo))

	http.HandleFunc("/instance", instanceHandler)
	http.HandleFunc("/debug", debugHandler)
	http.Handle("/", brokerAPI)

	brokerLogger.Fatal("http-listen", http.ListenAndServe(config.Host+":"+config.Port, nil))
}