Merge pull request #7322 from cd1989/update-with-props

Update only specific props in registry update
This commit is contained in:
Wenkai Yin 2019-04-10 09:44:51 +08:00 committed by GitHub
commit 7fcc391fed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 13 deletions

View File

@ -1,8 +1,6 @@
package dao
import (
"time"
"github.com/astaxie/beego/orm"
"github.com/goharbor/harbor/src/common/dao"
@ -89,16 +87,10 @@ func ListRegistries(query ...*ListRegistryQuery) (int64, []*models.Registry, err
}
// UpdateRegistry updates one registry
func UpdateRegistry(registry *models.Registry) error {
func UpdateRegistry(registry *models.Registry, props ...string) error {
o := dao.GetOrmer()
sql := `update registry
set url = ?, name = ?, credential_type = ?, access_key = ?, access_secret = ?, type = ?, insecure = ?, health = ?, description = ?, update_time = ?
where id = ?`
_, err := o.Raw(sql, registry.URL, registry.Name, registry.CredentialType, registry.AccessKey, registry.AccessSecret,
registry.Type, registry.Insecure, registry.Health, registry.Description, time.Now(), registry.ID).Exec()
_, err := o.Update(registry, props...)
return err
}

View File

@ -136,8 +136,6 @@ func (m *DefaultManager) Add(registry *model.Registry) (int64, error) {
// Update updates a registry
func (m *DefaultManager) Update(registry *model.Registry, props ...string) error {
// TODO(ChenDe): Only update the given props
r, err := toDaoModel(registry)
if err != nil {
log.Errorf("Convert registry model to dao layer model error: %v", err)
@ -172,7 +170,7 @@ func (m *DefaultManager) HealthCheck() error {
log.Warningf("Check health status for %s error: %v", r.URL, err)
}
r.Status = string(status)
err = m.Update(r)
err = m.Update(r, "status")
if err != nil {
log.Warningf("Update health status for '%s' error: %v", r.URL, err)
errCount++