Esempio n. 1
0
func (p *OAuthPlugin) InitWebServerAuth(bot *plotbot.Bot, webserver plotbot.WebServer) {
	p.webserver = webserver

	var config struct {
		WebAuthConfig OAuthConfig
	}
	bot.LoadConfig(&config)

	conf := config.WebAuthConfig
	webserver.SetAuthMiddleware(func(handler http.Handler) http.Handler {
		return &OAuthMiddleware{
			handler:   handler,
			plugin:    p,
			webserver: webserver,
			bot:       bot,
			oauthCfg: &oauth2.Config{
				ClientID:     conf.ClientID,
				ClientSecret: conf.ClientSecret,
				RedirectURL:  conf.RedirectURL + "/oauth2callback",
				Scopes:       []string{"identify"},
				Endpoint: oauth2.Endpoint{
					AuthURL:  "https://slack.com/oauth/authorize",
					TokenURL: "https://slack.com/api/oauth.access",
				},
			},
		}
	})
	webserver.SetAuthenticatedUserFunc(p.AuthenticatedUser)
}
Esempio n. 2
0
func (plotberry *PlotBerry) InitPlugin(bot *plotbot.Bot) {

	var conf struct {
		Plotberry PlotberryConf
	}
	err := bot.LoadConfig(&conf)
	if err != nil {
		log.Fatalln("Error loading PlotBerry config section: ", err)
		return
	}

	plotberry.bot = bot
	plotberry.pingTime = time.Duration(conf.Plotberry.PingTime) * time.Second
	plotberry.eraLength = conf.Plotberry.EraLength
	plotberry.endpoint = conf.Plotberry.EndPoint

	// if plotberry.eraLength is 0 we will get a divide by zero error - lets abort first
	if plotberry.eraLength == 0 {
		log.Fatal("Plotberry.eraLength may not be zero (divide by zero error), please set the configuration")
		return
	}

	statchan := make(chan TotalUsers, 100)

	go plotberry.launchWatcher(statchan)
	go plotberry.launchCounter(statchan)

	bot.ListenFor(&plotbot.Conversation{
		HandlerFunc: plotberry.ChatHandler,
	})
}
Esempio n. 3
0
func (webapp *Webapp) InitWebServer(bot *plotbot.Bot, enabledPlugins []string) {
	var conf struct {
		Webapp WebappConfig
	}
	bot.LoadConfig(&conf)

	webapp.bot = bot
	webapp.enabledPlugins = enabledPlugins
	webapp.config = &conf.Webapp
	webapp.store = sessions.NewCookieStore([]byte(conf.Webapp.SessionAuthKey), []byte(conf.Webapp.SessionEncryptKey))
	webapp.privateRouter = mux.NewRouter()
	webapp.publicRouter = mux.NewRouter()

	webapp.privateRouter.HandleFunc("/", webapp.handleRoot)

	web = webapp
}
Esempio n. 4
0
func (healthy *Healthy) InitPlugin(bot *plotbot.Bot) {
	var conf struct {
		HealthCheck struct {
			Urls []string
		}
	}

	bot.LoadConfig(&conf)

	healthy.urls = conf.HealthCheck.Urls

	bot.ListenFor(&plotbot.Conversation{
		MentionsMeOnly: true,
		ContainsAny:    []string{"health", "healthy?", "health_check"},
		HandlerFunc:    healthy.ChatHandler,
	})
}
Esempio n. 5
0
func (bugger *Bugger) InitPlugin(bot *plotbot.Bot) {

	/*
	 * Get an array of issues matching Filters
	 */
	bugger.bot = bot

	var conf struct {
		Github github.Conf
	}

	bot.LoadConfig(&conf)

	bugger.ghclient = github.Client{
		Conf: conf.Github,
	}

	bot.ListenFor(&plotbot.Conversation{
		HandlerFunc: bugger.ChatHandler,
	})

}
Esempio n. 6
0
func (tabula *TabulaRasa) InitWebPlugin(bot *plotbot.Bot, privRouter *mux.Router, pubRouter *mux.Router) {
	var asanaConf struct {
		Asana struct {
			APIKey    string `json:"api_key"`
			Workspace string `json:"workspace"`
		}
	}

	bot.LoadConfig(&asanaConf)

	asanaClient := asana.NewClient(asanaConf.Asana.APIKey, asanaConf.Asana.Workspace)

	tabula.bot = bot
	tabula.asanaClient = asanaClient

	privRouter.HandleFunc("/plugins/tabularasa", func(w http.ResponseWriter, r *http.Request) {

		tabula.TabulaRasta()

	})

}
Esempio n. 7
0
func (dep *Deployer) InitPlugin(bot *plotbot.Bot) {
	var conf struct {
		Deployer DeployerConfig
	}
	bot.LoadConfig(&conf)

	dep.bot = bot
	dep.progress = make(chan string, 1000)
	dep.config = &conf.Deployer
	dep.env = os.Getenv("PLOTLY_ENV")

	if dep.env == "" {
		dep.env = "debug"
	}

	dep.loadInternalAPI()

	go dep.forwardProgress()

	bot.ListenFor(&plotbot.Conversation{
		HandlerFunc:    dep.ChatHandler,
		MentionsMeOnly: true,
	})
}
Esempio n. 8
0
func (hooker *Hooker) InitWebPlugin(bot *plotbot.Bot, privRouter *mux.Router, pubRouter *mux.Router) {
	hooker.bot = bot

	var conf struct {
		Hooker HookerConfig
	}
	bot.LoadConfig(&conf)
	hooker.config = conf.Hooker

	pubRouter.HandleFunc("/public/updated_plotbot_repo", hooker.updatedPlotbotRepo)

	stripeUrl := fmt.Sprintf("/public/stripehook/%s", hooker.config.StripeSecret)
	pubRouter.HandleFunc(stripeUrl, hooker.onPayingUser)

	pubRouter.HandleFunc("/public/monit", hooker.onMonit)

	privRouter.HandleFunc("/plugins/hooker.json", func(w http.ResponseWriter, r *http.Request) {
		if r.Method != "GET" {
			http.Error(w, "Method not accepted", 405)
			return
		}

	})
}