Expose registered process tags via API

This commit is contained in:
Daniel
2022-10-04 12:53:42 +02:00
parent fcf603ea90
commit c4943a96b1
2 changed files with 43 additions and 0 deletions

39
process/api.go Normal file
View File

@@ -0,0 +1,39 @@
package process
import (
"github.com/safing/portbase/api"
)
func registerAPIEndpoints() error {
if err := api.RegisterEndpoint(api.Endpoint{
Path: "process/tags",
Read: api.PermitUser,
BelongsTo: module,
StructFunc: handleProcessTagMetadata,
Name: "Get Process Tag Metadata",
Description: "Get information about process tags.",
}); err != nil {
return err
}
return nil
}
func handleProcessTagMetadata(ar *api.Request) (i interface{}, err error) {
tagRegistryLock.Lock()
defer tagRegistryLock.Unlock()
// Create response struct.
resp := struct {
Tags []TagDescription
}{
Tags: make([]TagDescription, 0, len(tagRegistry)*2),
}
// Get all tag descriptions.
for _, th := range tagRegistry {
resp.Tags = append(resp.Tags, th.TagDescriptions()...)
}
return resp, nil
}

View File

@@ -26,5 +26,9 @@ func start() error {
updatesPath += string(os.PathSeparator)
}
if err := registerAPIEndpoints(); err != nil {
return err
}
return nil
}