only handle slack events in $SLACK_CHANNELS csv

main
Bel LaPointe 2024-04-11 17:19:32 -06:00
parent 6a6524692a
commit 64af8f5085
2 changed files with 11 additions and 3 deletions

View File

@ -14,6 +14,7 @@ type Config struct {
Port int Port int
InitializeSlack bool InitializeSlack bool
SlackToken string SlackToken string
SlackChannels string
} }
func newConfig() (Config, error) { func newConfig() (Config, error) {

13
main.go
View File

@ -10,6 +10,8 @@ import (
"net" "net"
"net/http" "net/http"
"os/signal" "os/signal"
"slices"
"strings"
"syscall" "syscall"
) )
@ -95,15 +97,20 @@ func _newHandlerPostAPIV1EventsSlack(cfg Config) http.HandlerFunc {
b, _ := io.ReadAll(r.Body) b, _ := io.ReadAll(r.Body)
r.Body = io.NopCloser(bytes.NewReader(b)) r.Body = io.NopCloser(bytes.NewReader(b))
var token struct { var allowList struct {
Token string Token string
Event struct {
Channel string
} }
if err := json.Unmarshal(b, &token); err != nil { }
if err := json.Unmarshal(b, &allowList); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest) http.Error(w, err.Error(), http.StatusBadRequest)
return return
} else if token.Token != cfg.SlackToken { } else if allowList.Token != cfg.SlackToken {
http.Error(w, "invalid .token", http.StatusForbidden) http.Error(w, "invalid .token", http.StatusForbidden)
return return
} else if !slices.Contains(strings.Split(cfg.SlackChannels, ","), allowList.Event.Channel) {
return
} }
http.Error(w, "not impl", http.StatusNotImplemented) http.Error(w, "not impl", http.StatusNotImplemented)