Esempio n. 1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	// subscription := account.NewEtcdSubscription("/apihub_development", &db.EtcdConfig{Machines: []string{"http://apihub_etcd_1:2379"}})
	subscription := account.NewEtcdSubscription("/apihub_development", &db.EtcdConfig{Machines: []string{"http://127.0.0.1:2379"}})
	// api := api.NewApi(mongore.New(mongore.Config{
	// Host: "apihub_mongo_1:27017",
	// Host:         "127.0.0.1:27017",
	// DatabaseName: "apihub_account_test",
	// }), subscription)
	api := api.NewApi(mem.New(), subscription)

	api.AddHook(account.Hook{
		Name:   "apihub-service-added-slack",
		Team:   account.ALL_TEAMS,
		Events: []string{"service.create"},
		Config: account.HookConfig{Address: "https://hooks.slack.com/services/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"},
		// Config: account.HookConfig{Address: "http://localhost:9999"},
		Text: `{"username": "******", "channel": "#general",
		"icon_emoji": ":ghost:",
		"text": "A new service has been added with the following subdomain: {{.Service.Subdomain}}."}`,
	})

	api.AddHook(account.Hook{
		Name:   "apihub-service-deleted-slack",
		Team:   account.ALL_TEAMS,
		Events: []string{"service.delete"},
		Config: account.HookConfig{Address: "https://hooks.slack.com/services/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"},
		Text: `{"username": "******", "channel": "#general",
		"icon_emoji": ":ghost:",
		"text": "Service -> {{.Service.Subdomain}} <- has been removed ."}`,
	})

	api.ListenEvents()
	api.Run()
}
Esempio n. 2
0
func (s *S) SetUpTest(c *C) {
	// setUpMongoreTest(s)
	setUpMemoryTest(s)

	s.api = api.NewApi(s.store, s.pubsub)
	s.server = httptest.NewServer(s.api.Handler())
	httpClient = requests.NewHTTPClient(s.server.URL)

	team = account.Team{Name: "ApiHub Team", Alias: "apihub"}
	service = account.Service{Endpoint: "http://example.org/api", Subdomain: "apihub"}
	user = account.User{Name: "Bob", Email: "*****@*****.**", Password: "******"}
	app = account.App{ClientId: "ios", ClientSecret: "secret", Name: "Ios App", Team: team.Alias, Owner: user.Email, RedirectUris: []string{"http://www.example.org/auth"}}
	pluginConfig = account.Plugin{Name: "Plugin Config", Service: service.Subdomain, Config: map[string]interface{}{"version": 1}}

	user.Create()
	token, err := s.api.Login(user.Email, "secret")
	if err != nil {
		panic(err)
	}
	s.authHeader = fmt.Sprintf("%s %s", token.Type, token.AccessToken)
}