-
Notifications
You must be signed in to change notification settings - Fork 6
/
object_validate_config.go
42 lines (38 loc) · 1.04 KB
/
object_validate_config.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
40
41
42
package omcmd
import (
"context"
"fmt"
"github.com/opensvc/om3/core/actioncontext"
"github.com/opensvc/om3/core/naming"
"github.com/opensvc/om3/core/object"
"github.com/opensvc/om3/core/objectaction"
)
type (
CmdObjectValidateConfig struct {
OptsGlobal
OptsLock
}
)
func (t *CmdObjectValidateConfig) Run(selector, kind string) error {
mergedSelector := mergeSelector(selector, t.ObjectSelector, kind, "")
return objectaction.New(
objectaction.LocalFirst(),
objectaction.WithLocal(t.Local),
objectaction.WithColor(t.Color),
objectaction.WithOutput(t.Output),
objectaction.WithObjectSelector(mergedSelector),
objectaction.WithLocalFunc(func(ctx context.Context, p naming.Path) (interface{}, error) {
o, err := object.New(p)
if err != nil {
return nil, err
}
c, ok := o.(object.Configurer)
if !ok {
return nil, fmt.Errorf("%s is not a configurer", o)
}
ctx = actioncontext.WithLockDisabled(ctx, t.Disable)
ctx = actioncontext.WithLockTimeout(ctx, t.Timeout)
return c.ValidateConfig(ctx)
}),
).Do()
}