37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
store.go 1.43 KB
一键复制 编辑 原始数据 按行查看 历史
Darren Shepherd 提交于 2018-02-07 21:46 . API structure refactor
package cert
import (
"time"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/rancher/pkg/cert"
"github.com/rancher/types/client/project/v3"
)
func Wrap(store types.Store) types.Store {
return &Store{
Store: store,
}
}
type Store struct {
types.Store
}
func (s *Store) Create(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}) (map[string]interface{}, error) {
if err := AddCertInfo(data); err != nil {
return nil, err
}
return s.Store.Create(apiContext, schema, data)
}
func (s *Store) Update(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, id string) (map[string]interface{}, error) {
if err := AddCertInfo(data); err != nil {
return nil, err
}
return s.Store.Update(apiContext, schema, data, id)
}
func AddCertInfo(data map[string]interface{}) error {
certs, _ := data[client.CertificateFieldCerts].(string)
key, _ := data[client.CertificateFieldKey].(string)
if certs == "" || key == "" {
return nil
}
certInfo, err := cert.Info(certs, key)
if err != nil {
return httperror.NewFieldAPIError(httperror.InvalidBodyContent, "certs", err.Error())
}
certData, err := convert.EncodeToMap(certInfo)
if err != nil {
return err
}
for k, v := range certData {
if t, ok := v.(time.Time); ok {
data[k] = convert.ToString(t)
} else {
data[k] = v
}
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.4-rc12

搜索帮助

0d507c66 1850385 C8b1a773 1850385