Expose debug API with pprof

Runs along the provisioning API with same authentication.
This commit is contained in:
Toni Spets 2023-12-05 12:09:11 +02:00 committed by Toni Spets
parent c013873d1c
commit 643d4c6e39
4 changed files with 14 additions and 2 deletions

View file

@ -83,8 +83,9 @@ type BridgeConfig struct {
Encryption bridgeconfig.EncryptionConfig `yaml:"encryption"` Encryption bridgeconfig.EncryptionConfig `yaml:"encryption"`
Provisioning struct { Provisioning struct {
Prefix string `yaml:"prefix"` Prefix string `yaml:"prefix"`
SharedSecret string `yaml:"shared_secret"` SharedSecret string `yaml:"shared_secret"`
DebugEndpoints bool `yaml:"debug_endpoints"`
} `yaml:"provisioning"` } `yaml:"provisioning"`
Permissions bridgeconfig.PermissionConfig `yaml:"permissions"` Permissions bridgeconfig.PermissionConfig `yaml:"permissions"`

View file

@ -113,6 +113,7 @@ func DoUpgrade(helper *up.Helper) {
} else { } else {
helper.Copy(up.Str, "bridge", "provisioning", "shared_secret") helper.Copy(up.Str, "bridge", "provisioning", "shared_secret")
} }
helper.Copy(up.Bool, "bridge", "provisioning", "debug_endpoints")
helper.Copy(up.Map, "bridge", "permissions") helper.Copy(up.Map, "bridge", "permissions")
//helper.Copy(up.Bool, "bridge", "relay", "enabled") //helper.Copy(up.Bool, "bridge", "relay", "enabled")

View file

@ -332,6 +332,8 @@ bridge:
# Shared secret for authentication. If set to "generate", a random secret will be generated, # Shared secret for authentication. If set to "generate", a random secret will be generated,
# or if set to "disable", the provisioning API will be disabled. # or if set to "disable", the provisioning API will be disabled.
shared_secret: generate shared_secret: generate
# Enable debug API at /debug with provisioning authentication.
debug_endpoints: false
# Permissions for using the bridge. # Permissions for using the bridge.
# Permitted values: # Permitted values:

View file

@ -7,6 +7,7 @@ import (
"errors" "errors"
"net" "net"
"net/http" "net/http"
_ "net/http/pprof"
"strings" "strings"
"time" "time"
@ -71,6 +72,13 @@ func newProvisioningAPI(br *DiscordBridge) *ProvisioningAPI {
r.HandleFunc("/v1/guilds/{guildID}", p.guildsBridge).Methods(http.MethodPost) r.HandleFunc("/v1/guilds/{guildID}", p.guildsBridge).Methods(http.MethodPost)
r.HandleFunc("/v1/guilds/{guildID}", p.guildsUnbridge).Methods(http.MethodDelete) r.HandleFunc("/v1/guilds/{guildID}", p.guildsUnbridge).Methods(http.MethodDelete)
if p.bridge.Config.Bridge.Provisioning.DebugEndpoints {
p.log.Debugln("Enabling debug API at /debug")
r := p.bridge.AS.Router.PathPrefix("/debug").Subrouter()
r.Use(p.authMiddleware)
r.PathPrefix("/pprof").Handler(http.DefaultServeMux)
}
return p return p
} }