Skip to content

Commit

Permalink
Add TLS support for Lark webhook (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
nt0xa authored Feb 1, 2023
1 parent da49e1f commit 049d6e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/server/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func Modules(
m, err = api.New(&cfg.API, db, log, tls, actions)

case "lark":
m, err = lark.New(&cfg.Lark, db, actions, domain)
m, err = lark.New(&cfg.Lark, db, tls, actions, domain)

}

Expand Down
20 changes: 15 additions & 5 deletions internal/modules/lark/lark.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ type Lark struct {
cmd cmd.Command
actions actions.Actions
client *lark.Client
tls *tls.Config

domain string
}

func New(cfg *Config, db *database.DB, actions actions.Actions, domain string) (*Lark, error) {
func New(cfg *Config, db *database.DB, tlsConfig *tls.Config, actions actions.Actions, domain string) (*Lark, error) {

httpClient := http.DefaultClient

Expand All @@ -62,7 +63,7 @@ func New(cfg *Config, db *database.DB, actions actions.Actions, domain string) (

}

// TODO: better logging
// TODO: better logging
var client = lark.NewClient(
cfg.AppID,
cfg.AppSecret,
Expand All @@ -85,6 +86,7 @@ func New(cfg *Config, db *database.DB, actions actions.Actions, domain string) (
cfg: cfg,
domain: domain,
actions: actions,
tls: tlsConfig,
}

lrk.cmd = cmd.New(actions, lrk, lrk.preExec)
Expand Down Expand Up @@ -145,12 +147,20 @@ func (lrk *Lark) Start() error {
},
)

// TODO: take path from config
http.HandleFunc("/webhook/event", httpserverext.NewEventHandlerFunc(handler,
mux := http.NewServeMux()

// TODO: take path from config
mux.HandleFunc("/webhook/event", httpserverext.NewEventHandlerFunc(handler,
larkevent.WithLogLevel(larkcore.LogLevelDebug)))

// TODO: take port from config
return http.ListenAndServe(":31338", nil)
srv := http.Server{
Addr: ":31338",
Handler: mux,
TLSConfig: lrk.tls,
}

return srv.ListenAndServeTLS("", "")
}

// TODO: add common notifier module
Expand Down

0 comments on commit 049d6e8

Please sign in to comment.