-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.go
47 lines (38 loc) · 1.47 KB
/
validator.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
43
44
45
46
47
package logging
import (
"fmt"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
"github.com/rancher/rancher/pkg/controllers/user/logging/utils"
)
func ClusterLoggingValidator(resquest *types.APIContext, schema *types.Schema, data map[string]interface{}) error {
var clusterLogging v3.ClusterLoggingSpec
if err := convert.ToObj(data, &clusterLogging); err != nil {
return httperror.NewAPIError(httperror.InvalidBodyContent, fmt.Sprintf("%v", err))
}
wp := utils.WrapClusterLogging{
ClusterLoggingSpec: clusterLogging,
}
if err := wp.Validate(); err != nil {
logrus.Warnf("clusterlogging %s input validate failed, %v", resquest.ID, err)
return httperror.NewAPIError(httperror.InvalidFormat, fmt.Sprintf("%v", err))
}
return nil
}
func ProjectLoggingValidator(resquest *types.APIContext, schema *types.Schema, data map[string]interface{}) error {
var projectLogging v3.ProjectLoggingSpec
if err := convert.ToObj(data, &projectLogging); err != nil {
return httperror.NewAPIError(httperror.InvalidBodyContent, fmt.Sprintf("%v", err))
}
wp := utils.WrapProjectLogging{
ProjectLoggingSpec: projectLogging,
}
if err := wp.Validate(); err != nil {
logrus.Warnf("projectlogging %s input validate failed, %v", resquest.ID, err)
return httperror.NewAPIError(httperror.InvalidFormat, fmt.Sprintf("%v", err))
}
return nil
}