代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。