when initializing slack, stash token in driver
parent
5f21098fdc
commit
fbd151f9ef
15
main.go
15
main.go
|
|
@ -196,12 +196,13 @@ func basicAuth(cfg Config, w http.ResponseWriter, r *http.Request) bool {
|
||||||
|
|
||||||
func newHandlerPostAPIV1EventsSlack(cfg Config) http.HandlerFunc {
|
func newHandlerPostAPIV1EventsSlack(cfg Config) http.HandlerFunc {
|
||||||
if cfg.InitializeSlack {
|
if cfg.InitializeSlack {
|
||||||
return handlerPostAPIV1EventsSlackInitialize
|
return handlerPostAPIV1EventsSlackInitialize(cfg)
|
||||||
}
|
}
|
||||||
return _newHandlerPostAPIV1EventsSlack(cfg)
|
return _newHandlerPostAPIV1EventsSlack(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlerPostAPIV1EventsSlackInitialize(w http.ResponseWriter, r *http.Request) {
|
func handlerPostAPIV1EventsSlackInitialize(cfg Config) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
b, _ := io.ReadAll(r.Body)
|
b, _ := io.ReadAll(r.Body)
|
||||||
var challenge struct {
|
var challenge struct {
|
||||||
Token string
|
Token string
|
||||||
|
|
@ -212,8 +213,16 @@ func handlerPostAPIV1EventsSlackInitialize(w http.ResponseWriter, r *http.Reques
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if _, err := cfg.driver.ExecContext(r.Context(), `
|
||||||
|
CREATE TABLE IF NOT EXISTS initialization (label TEXT, token TEXT, updated TIMESTAMP);
|
||||||
|
INSERT INTO initialization (token, updated) VALUES ('slack_events_webhook_token', $1, $2);
|
||||||
|
`, challenge.Token, time.Now().UTC()); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Println("stashed new slack initialization token")
|
||||||
encodeResponse(w, r, map[string]any{"challenge": challenge.Challenge})
|
encodeResponse(w, r, map[string]any{"challenge": challenge.Challenge})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _newHandlerPostAPIV1EventsSlack(cfg Config) http.HandlerFunc {
|
func _newHandlerPostAPIV1EventsSlack(cfg Config) http.HandlerFunc {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue