diff --git a/pkg/cloudcommon/db/db_dispatcher.go b/pkg/cloudcommon/db/db_dispatcher.go index 7f60ee134e..cde358e34e 100644 --- a/pkg/cloudcommon/db/db_dispatcher.go +++ b/pkg/cloudcommon/db/db_dispatcher.go @@ -601,7 +601,7 @@ func (dispatcher *DBModelDispatcher) tryGetModelProperty(ctx context.Context, pr return nil, httperrors.NewInternalServerError("Invald %s return value", funcName) } if !outs[0].Bool() { - return nil, httperrors.NewForbiddenError(fmt.Sprintf("%s not allow to get property %s", dispatcher.Keyword(), property)) + return nil, httperrors.NewForbiddenError("%s not allow to get property %s", dispatcher.Keyword(), property) } funcValue = modelValue.MethodByName(funcName) @@ -679,7 +679,7 @@ func (dispatcher *DBModelDispatcher) GetSpecific(ctx context.Context, idStr stri funcValue := modelValue.MethodByName(funcName) if !funcValue.IsValid() || funcValue.IsNil() { - return nil, httperrors.NewSpecNotFoundError(fmt.Sprintf("%s %s %s not found", dispatcher.Keyword(), idStr, spec)) + return nil, httperrors.NewSpecNotFoundError("%s %s %s not found", dispatcher.Keyword(), idStr, spec) } outs := funcValue.Call(params) @@ -690,13 +690,13 @@ func (dispatcher *DBModelDispatcher) GetSpecific(ctx context.Context, idStr stri } if !isAllow { - return nil, httperrors.NewForbiddenError(fmt.Sprintf("%s not allow to get spec %s", dispatcher.Keyword(), spec)) + return nil, httperrors.NewForbiddenError("%s not allow to get spec %s", dispatcher.Keyword(), spec) } funcName := fmt.Sprintf("GetDetails%s", specCamel) funcValue := modelValue.MethodByName(funcName) if !funcValue.IsValid() || funcValue.IsNil() { - return nil, httperrors.NewSpecNotFoundError(fmt.Sprintf("%s %s %s not found", dispatcher.Keyword(), idStr, spec)) + return nil, httperrors.NewSpecNotFoundError("%s %s %s not found", dispatcher.Keyword(), idStr, spec) } outs := funcValue.Call(params) @@ -740,7 +740,7 @@ func fetchOwnerProjectId(ctx context.Context, manager IModelManager, userCred mc } t, _ := TenantCacheManager.FetchTenantByIdOrName(ctx, projId) if t == nil { - return "", httperrors.NewNotFoundError(fmt.Sprintf("Project %s not found", projId)) + return "", httperrors.NewNotFoundError("Project %s not found", projId) } return t.GetId(), nil } @@ -1094,7 +1094,7 @@ func objectPerformAction(dispatcher *DBModelDispatcher, model IModel, modelValue isAllow = outs[0].Bool() } if !isAllow { - return nil, httperrors.NewForbiddenError(fmt.Sprintf("%s not allow to perform action %s", dispatcher.Keyword(), action)) + return nil, httperrors.NewForbiddenError("%s not allow to perform action %s", dispatcher.Keyword(), action) } outs := funcValue.Call(params) @@ -1193,7 +1193,7 @@ func (dispatcher *DBModelDispatcher) Update(ctx context.Context, idStr string, q isAllow = model.AllowUpdateItem(ctx, userCred) } if !isAllow { - return nil, httperrors.NewForbiddenError(fmt.Sprintf("Not allow to update item")) + return nil, httperrors.NewForbiddenError("Not allow to update item") } lockman.LockObject(ctx, model) @@ -1230,7 +1230,7 @@ func deleteItem(manager IModelManager, model IModel, ctx context.Context, userCr } if !isAllow { log.Errorf("not allow to delete") - return nil, httperrors.NewForbiddenError(fmt.Sprintf("%s(%s) not allow to delete", manager.KeywordPlural(), model.GetId())) + return nil, httperrors.NewForbiddenError("%s(%s) not allow to delete", manager.KeywordPlural(), model.GetId()) } err := model.ValidateDeleteCondition(ctx) diff --git a/pkg/cloudcommon/db/db_joint_dispatcher.go b/pkg/cloudcommon/db/db_joint_dispatcher.go index 345cc95403..cfee819025 100644 --- a/pkg/cloudcommon/db/db_joint_dispatcher.go +++ b/pkg/cloudcommon/db/db_joint_dispatcher.go @@ -218,7 +218,7 @@ func (dispatcher *DBJointModelDispatcher) Update(ctx context.Context, id1 string isAllow = item.AllowUpdateJointItem(ctx, userCred, item) } if !isAllow { - return nil, httperrors.NewForbiddenError(fmt.Sprintf("Not allow to update item")) + return nil, httperrors.NewForbiddenError("Not allow to update item") } lockman.LockJointObject(ctx, master, slave) diff --git a/pkg/cloudcommon/db/standalone.go b/pkg/cloudcommon/db/standalone.go index d1fd803ae7..d1cb1b4982 100644 --- a/pkg/cloudcommon/db/standalone.go +++ b/pkg/cloudcommon/db/standalone.go @@ -3,7 +3,6 @@ package db import ( "context" "database/sql" - "fmt" "yunion.io/x/jsonutils" "yunion.io/x/log" @@ -64,7 +63,7 @@ func (manager *SStandaloneResourceBaseManager) ValidateName(name string) error { return httperrors.NewInputParameterError("name starts with letter, and contains letter, number and ._@- only") } if manager.NameLength > 0 && len(name) > manager.NameLength { - return httperrors.NewInputParameterError(fmt.Sprintf("name longer than %d", manager.NameLength)) + return httperrors.NewInputParameterError("name longer than %d", manager.NameLength) } return nil } @@ -156,7 +155,7 @@ func (model *SStandaloneResourceBase) SetMetadata(ctx context.Context, key strin func (model *SStandaloneResourceBase) SetAllMetadata(ctx context.Context, dictstore map[string]interface{}, userCred mcclient.TokenCredential) error { for k := range dictstore { if Metadata.IsSystemAdminKey(k) && !userCred.IsSystemAdmin() { - return httperrors.NewNotSufficientPrivilegeError(fmt.Sprintf("not allow to set system key %s", k)) + return httperrors.NewNotSufficientPrivilegeError("not allow to set system key %s", k) } } return Metadata.SetAll(ctx, model, dictstore, userCred) diff --git a/pkg/cloudcommon/db/virtualjointbase.go b/pkg/cloudcommon/db/virtualjointbase.go index 23565cc777..e4d6d5bd80 100644 --- a/pkg/cloudcommon/db/virtualjointbase.go +++ b/pkg/cloudcommon/db/virtualjointbase.go @@ -112,7 +112,7 @@ func (manager *SVirtualJointResourceBaseManager) ListItemFilter(ctx context.Cont if len(tenant) > 0 { tc, _ := TenantCacheManager.FetchTenantByIdOrName(ctx, tenant) if tc == nil { - return nil, httperrors.NewTenantNotFoundError(fmt.Sprintf("tenant %s not found", tenant)) + return nil, httperrors.NewTenantNotFoundError("tenant %s not found", tenant) } q = q.Filter(sqlchemy.OR(sqlchemy.Equals(masterTable.Field("tenant_id"), tc.GetId()), sqlchemy.Equals(slaveTable.Field("tenant_id"), tc.GetId()))) diff --git a/pkg/cloudcommon/db/virtualresource.go b/pkg/cloudcommon/db/virtualresource.go index 16a9b44572..f3ff22967e 100644 --- a/pkg/cloudcommon/db/virtualresource.go +++ b/pkg/cloudcommon/db/virtualresource.go @@ -2,7 +2,6 @@ package db import ( "context" - "fmt" "strings" "time" @@ -85,7 +84,7 @@ func (manager *SVirtualResourceBaseManager) ListItemFilter(ctx context.Context, if tobj != nil { q = q.Equals("tenant_id", tobj.GetId()) } else { - return nil, httperrors.NewTenantNotFoundError(fmt.Sprintf("tenant %s not found", tenant)) + return nil, httperrors.NewTenantNotFoundError("tenant %s not found", tenant) } } isSystem, err := query.Bool("system") @@ -208,7 +207,7 @@ func (model *SVirtualResourceBase) PerformChangeOwner(ctx context.Context, userC } tobj, _ := TenantCacheManager.FetchTenantByIdOrName(ctx, tenant) if tobj == nil { - return nil, httperrors.NewTenantNotFoundError(fmt.Sprintf("tenant %s not found", tenant)) + return nil, httperrors.NewTenantNotFoundError("tenant %s not found", tenant) } q := model.GetModelManager().Query().Equals("name", model.GetName()) q = q.Equals("tenant_id", tobj.GetId()) diff --git a/pkg/compute/models/hoststorages.go b/pkg/compute/models/hoststorages.go index 90a55f5ba9..2c2481fc67 100644 --- a/pkg/compute/models/hoststorages.go +++ b/pkg/compute/models/hoststorages.go @@ -93,7 +93,7 @@ func (manager *SHoststorageManager) ValidateCreateData(ctx context.Context, user } storageTmp, _ := StorageManager.FetchById(storageId) if storageTmp == nil { - return nil, httperrors.NewInputParameterError(fmt.Sprintf("invalid storage_id %s", storageId)) + return nil, httperrors.NewInputParameterError("invalid storage_id %s", storageId) } storage := storageTmp.(*SStorage) if storage.StorageType == STORAGE_RBD { diff --git a/pkg/compute/models/networks.go b/pkg/compute/models/networks.go index c1ddf8b93d..d8521bd574 100644 --- a/pkg/compute/models/networks.go +++ b/pkg/compute/models/networks.go @@ -276,7 +276,7 @@ func (self *SNetwork) GetFreeIP(ctx context.Context, userCred mcclient.TokenCred if reserved { rip := ReservedipManager.GetReservedIP(self, candidate) if rip == nil { - return "", httperrors.NewInsufficientResourceError(fmt.Sprintf("Reserved address %s not found", candidate)) + return "", httperrors.NewInsufficientResourceError("Reserved address %s not found", candidate) } rip.Release(ctx, userCred, self) return candidate, nil diff --git a/pkg/compute/models/reservedips.go b/pkg/compute/models/reservedips.go index a03c11e945..d743ced163 100644 --- a/pkg/compute/models/reservedips.go +++ b/pkg/compute/models/reservedips.go @@ -2,7 +2,6 @@ package models import ( "context" - "fmt" "yunion.io/x/jsonutils" "yunion.io/x/log" @@ -131,7 +130,7 @@ func (manager *SReservedipManager) ListItemFilter(ctx context.Context, q *sqlche if len(network) > 0 { netObj, _ := NetworkManager.FetchByIdOrName(userCred, network) if netObj == nil { - return nil, httperrors.NewResourceNotFoundError(fmt.Sprintf("network %s not found", network)) + return nil, httperrors.NewResourceNotFoundError("network %s not found", network) } q = q.Equals("network_id", netObj.GetId()) } diff --git a/pkg/compute/models/secgrouprules.go b/pkg/compute/models/secgrouprules.go index e107610536..228a2dcfdc 100644 --- a/pkg/compute/models/secgrouprules.go +++ b/pkg/compute/models/secgrouprules.go @@ -109,7 +109,7 @@ func (manager *SSecurityGroupRuleManager) ListItemFilter(ctx context.Context, q if secgroup, _ := SecurityGroupManager.FetchByIdOrName(userCred, defsecgroup); secgroup != nil { sql = sql.Equals("secgroup_id", secgroup.GetId()) } else { - return nil, httperrors.NewNotFoundError(fmt.Sprintf("Security Group %s not found", defsecgroup)) + return nil, httperrors.NewNotFoundError("Security Group %s not found", defsecgroup) } } for _, field := range []string{"direction", "action", "protocol"} { diff --git a/pkg/mcclient/modules/mod_domains.go b/pkg/mcclient/modules/mod_domains.go index b2627fb39f..b437969cb4 100644 --- a/pkg/mcclient/modules/mod_domains.go +++ b/pkg/mcclient/modules/mod_domains.go @@ -240,7 +240,7 @@ func (this *DomainManager) DoDomainConfigDelete(s *mcclient.ClientSession, param log.Errorf("user list got error: %v", err) return ret, httperrors.NewInternalServerError("fetching user list failed: %s", err) } else if len(result.Data) > 0 { - return ret, httperrors.NewForbiddenError(fmt.Sprintf("cannot delete: there still exists %d user related with domain %s.", len(result.Data), objId)) + return ret, httperrors.NewForbiddenError("cannot delete: there still exists %d user related with domain %s.", len(result.Data), objId) } }