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
InitializeSlack bool
SlackToken string
SlackChannels string
}
func newConfig() (Config, error) {

13
main.go
View File

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