websocket actions: Refactor registration

This commit is contained in:
Tom Wiesing 2023-11-09 14:58:19 +01:00
parent 08ab7b4383
commit 7b5f8a9882
No known key found for this signature in database
4 changed files with 102 additions and 87 deletions

View file

@ -0,0 +1,36 @@
package proto
import (
"context"
"io"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth/scopes"
)
// Action is anything that can be retrieved from a
type Action struct {
// NumPara
NumParams int
// Scope and ScopeParam indicate the scope required by the caller.
// TODO(twiesing): Once we actually include scopes, make them dynamic
Scope component.Scope
ScopeParam string
// Handle handles this action.
//
// ctx is closed once the underlying connection is closed.
// out is an io.Writer that is automatically sent to the client.
// params holds exactly NumParams parameters.
Handle func(ctx context.Context, in io.Reader, out io.Writer, params ...string) error
}
// scope returns the actual scope required by this action.
// If the caller did not provide an actual scope, uses ScopeNever
func (action Action) scope() component.Scope {
if action.Scope == "" {
return scopes.ScopeNever
}
return action.Scope
}