webhooks support (#81)

This commit is contained in:
David Zhao
2021-08-09 09:57:37 -07:00
committed by GitHub
parent 1f4288744c
commit 9495646f1a
12 changed files with 286 additions and 19 deletions
+16
View File
@@ -6,6 +6,8 @@ import (
"github.com/go-redis/redis/v8"
"github.com/google/wire"
"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/webhook"
"github.com/pkg/errors"
"github.com/livekit/livekit-server/pkg/config"
@@ -18,6 +20,7 @@ var ServiceSet = wire.NewSet(
createRedisClient,
createRouter,
createStore,
createWebhookNotifier,
NewRecordingService,
NewRoomService,
NewRTCService,
@@ -66,6 +69,19 @@ func createStore(rc *redis.Client) RoomStore {
return NewLocalRoomStore()
}
func createWebhookNotifier(conf *config.Config, provider auth.KeyProvider) (*webhook.Notifier, error) {
wc := conf.WebHook
if len(wc.URLs) == 0 {
return nil, nil
}
secret := provider.GetSecret(wc.APIKey)
if secret == "" {
return nil, ErrWebHookMissingAPIKey
}
return webhook.NewNotifier(wc.APIKey, secret, wc.URLs), nil
}
func handleError(w http.ResponseWriter, status int, msg string) {
// GetLogger already with extra depth 1
logger.GetLogger().V(1).Info("error handling request", "error", msg, "status", status)