37 Star 407 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
validator.go 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
Aiwantaozi 提交于 2018-02-28 13:44 . update logging validate
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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.2-rc6

搜索帮助