diff --git a/config/bridge.go b/config/bridge.go index 98b7b14..046632f 100644 --- a/config/bridge.go +++ b/config/bridge.go @@ -83,8 +83,9 @@ type BridgeConfig struct { Encryption bridgeconfig.EncryptionConfig `yaml:"encryption"` Provisioning struct { - Prefix string `yaml:"prefix"` - SharedSecret string `yaml:"shared_secret"` + Prefix string `yaml:"prefix"` + SharedSecret string `yaml:"shared_secret"` + DebugEndpoints bool `yaml:"debug_endpoints"` } `yaml:"provisioning"` Permissions bridgeconfig.PermissionConfig `yaml:"permissions"` diff --git a/config/upgrade.go b/config/upgrade.go index 6fb2c2a..c3e9cff 100644 --- a/config/upgrade.go +++ b/config/upgrade.go @@ -113,6 +113,7 @@ func DoUpgrade(helper *up.Helper) { } else { 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.Bool, "bridge", "relay", "enabled") diff --git a/example-config.yaml b/example-config.yaml index ed51965..42b5c6c 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -332,6 +332,8 @@ bridge: # 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. shared_secret: generate + # Enable debug API at /debug with provisioning authentication. + debug_endpoints: false # Permissions for using the bridge. # Permitted values: diff --git a/provisioning.go b/provisioning.go index 7116873..c9ff3ab 100644 --- a/provisioning.go +++ b/provisioning.go @@ -7,6 +7,7 @@ import ( "errors" "net" "net/http" + _ "net/http/pprof" "strings" "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.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 }