mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +00:00
Implement review suggestions
This commit is contained in:
parent
40c2849bab
commit
ab05924bcf
4 changed files with 17 additions and 15 deletions
|
@ -64,7 +64,7 @@ func registerConfig() error {
|
||||||
err = config.Register(&config.Option{
|
err = config.Register(&config.Option{
|
||||||
Name: "API Keys",
|
Name: "API Keys",
|
||||||
Key: CfgAPIKeys,
|
Key: CfgAPIKeys,
|
||||||
Description: "Defined API Keys.",
|
Description: "Define API keys for priviledged access to the API. Every entry is a separate API key with respective permissions. Format is `<key>?read=<perm>&write=<perm>`. Permissions are `anyone`, `user` and `admin`, and may be omitted.",
|
||||||
OptType: config.OptTypeStringArray,
|
OptType: config.OptTypeStringArray,
|
||||||
ExpertiseLevel: config.ExpertiseLevelDeveloper,
|
ExpertiseLevel: config.ExpertiseLevelDeveloper,
|
||||||
ReleaseLevel: config.ReleaseLevelStable,
|
ReleaseLevel: config.ReleaseLevelStable,
|
||||||
|
|
|
@ -41,6 +41,7 @@ type Endpoint struct {
|
||||||
HandlerFunc http.HandlerFunc `json:"-"`
|
HandlerFunc http.HandlerFunc `json:"-"`
|
||||||
|
|
||||||
// Documentation Metadata.
|
// Documentation Metadata.
|
||||||
|
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
Parameters []Parameter
|
Parameters []Parameter
|
||||||
|
|
|
@ -11,6 +11,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func registerDebugEndpoints() error {
|
func registerDebugEndpoints() error {
|
||||||
|
if err := RegisterEndpoint(Endpoint{
|
||||||
|
Path: "ping",
|
||||||
|
Read: PermitAnyone,
|
||||||
|
ActionFunc: ping,
|
||||||
|
Name: "Ping",
|
||||||
|
Description: "Pong.",
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err := RegisterEndpoint(Endpoint{
|
if err := RegisterEndpoint(Endpoint{
|
||||||
Path: "debug/stack",
|
Path: "debug/stack",
|
||||||
Read: PermitAnyone,
|
Read: PermitAnyone,
|
||||||
|
@ -50,6 +60,11 @@ func registerDebugEndpoints() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ping responds with pong.
|
||||||
|
func ping(ar *Request) (msg string, err error) {
|
||||||
|
return "Pong.", nil
|
||||||
|
}
|
||||||
|
|
||||||
// getStack returns the current goroutine stack.
|
// getStack returns the current goroutine stack.
|
||||||
func getStack(_ *Request) (data []byte, err error) {
|
func getStack(_ *Request) (data []byte, err error) {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
|
|
|
@ -7,16 +7,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func registerMetaEndpoints() error {
|
func registerMetaEndpoints() error {
|
||||||
if err := RegisterEndpoint(Endpoint{
|
|
||||||
Path: "ping",
|
|
||||||
Read: PermitAnyone,
|
|
||||||
ActionFunc: ping,
|
|
||||||
Name: "Ping",
|
|
||||||
Description: "Pong.",
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := RegisterEndpoint(Endpoint{
|
if err := RegisterEndpoint(Endpoint{
|
||||||
Path: "endpoints",
|
Path: "endpoints",
|
||||||
Read: PermitAnyone,
|
Read: PermitAnyone,
|
||||||
|
@ -94,10 +84,6 @@ func permissions(ar *Request) (i interface{}, err error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ping(ar *Request) (msg string, err error) {
|
|
||||||
return "Pong.", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func authBearer(w http.ResponseWriter, r *http.Request) {
|
func authBearer(w http.ResponseWriter, r *http.Request) {
|
||||||
// Check if authenticated by checking read permission.
|
// Check if authenticated by checking read permission.
|
||||||
ar := GetAPIRequest(r)
|
ar := GetAPIRequest(r)
|
||||||
|
|
Loading…
Add table
Reference in a new issue