-
Notifications
You must be signed in to change notification settings - Fork 178
/
toggle_uploader.go
39 lines (31 loc) · 1016 Bytes
/
toggle_uploader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package uploader
import (
"context"
"github.com/onflow/flow-go/admin"
"github.com/onflow/flow-go/admin/commands"
"github.com/onflow/flow-go/engine/execution/ingestion/uploader"
)
var _ commands.AdminCommand = (*ToggleUploaderCommand)(nil)
type ToggleUploaderCommand struct {
uploadManager *uploader.Manager
}
func (t *ToggleUploaderCommand) Handler(ctx context.Context, req *admin.CommandRequest) (interface{}, error) {
enabled := req.ValidatorData.(bool)
t.uploadManager.SetEnabled(enabled)
return "ok", nil
}
// Validator validates the request.
// Returns admin.InvalidAdminReqError for invalid/malformed requests.
func (t *ToggleUploaderCommand) Validator(req *admin.CommandRequest) error {
enabled, ok := req.Data.(bool)
if !ok {
return admin.NewInvalidAdminReqFormatError("expected bool")
}
req.ValidatorData = enabled
return nil
}
func NewToggleUploaderCommand(uploadManager *uploader.Manager) commands.AdminCommand {
return &ToggleUploaderCommand{
uploadManager: uploadManager,
}
}