Skip to content

Commit

Permalink
fix: change he to herrors
Browse files Browse the repository at this point in the history
Signed-off-by: chenzhixiang <[email protected]>
  • Loading branch information
chenzhixiang committed Mar 17, 2022
1 parent d5dab58 commit 4a07336
Show file tree
Hide file tree
Showing 64 changed files with 563 additions and 563 deletions.
2 changes: 1 addition & 1 deletion Horizon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions core/controller/access/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"g.hz.netease.com/horizon/core/middleware/user"
hauth "g.hz.netease.com/horizon/pkg/auth"
perrors "g.hz.netease.com/horizon/pkg/errors"
perror "g.hz.netease.com/horizon/pkg/errors"
"g.hz.netease.com/horizon/pkg/rbac"
"g.hz.netease.com/horizon/pkg/server/middleware"
"g.hz.netease.com/horizon/pkg/server/middleware/auth"
Expand Down Expand Up @@ -39,7 +39,7 @@ func (c *controller) Review(ctx context.Context, apis []API) (map[string]map[str
// get user info
currentUser, err := user.FromContext(ctx)
if err != nil {
return nil, perrors.WithMessage(err, "failed to get user info")
return nil, perror.WithMessage(err, "failed to get user info")
}
// traverse apis to authorize
for _, api := range apis {
Expand All @@ -55,7 +55,7 @@ func (c *controller) Review(ctx context.Context, apis []API) (map[string]map[str
// 1.new request by api
req, err := http.NewRequest(api.Method, api.URL, nil)
if err != nil {
return nil, perrors.Wrapf(err, "invalid api, url: %s, method: %s", api.URL, api.Method)
return nil, perror.Wrapf(err, "invalid api, url: %s, method: %s", api.URL, api.Method)
}
// 2.check skippers
for _, skipper := range c.skippers {
Expand All @@ -71,7 +71,7 @@ func (c *controller) Review(ctx context.Context, apis []API) (map[string]map[str
// 4.new request info by request
requestInfo, err := c.requestInfoFty.NewRequestInfo(req)
if err != nil {
return nil, perrors.WithMessagef(err, "invalid api, url: %s, method: %s", api.URL, api.Method)
return nil, perror.WithMessagef(err, "invalid api, url: %s, method: %s", api.URL, api.Method)
}
// 4. do rbac auth
authRecord := hauth.AttributesRecord{
Expand All @@ -88,7 +88,7 @@ func (c *controller) Review(ctx context.Context, apis []API) (map[string]map[str
}
decision, reason, err := c.authorizer.Authorize(ctx, authRecord)
if err != nil {
return nil, perrors.WithMessagef(err, "failed to authorize, url: %s, method: %s", api.URL, api.Method)
return nil, perror.WithMessagef(err, "failed to authorize, url: %s, method: %s", api.URL, api.Method)
}
reviewResult.Allowed = decision == hauth.DecisionAllow
reviewResult.Reason = reason
Expand Down
14 changes: 7 additions & 7 deletions core/controller/application/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"regexp"

"g.hz.netease.com/horizon/core/common"
he "g.hz.netease.com/horizon/core/errors"
herrors "g.hz.netease.com/horizon/core/errors"
"g.hz.netease.com/horizon/core/middleware/user"
"g.hz.netease.com/horizon/lib/q"
"g.hz.netease.com/horizon/pkg/application/gitrepo"
"g.hz.netease.com/horizon/pkg/application/manager"
"g.hz.netease.com/horizon/pkg/application/models"
applicationservice "g.hz.netease.com/horizon/pkg/application/service"
clustermanager "g.hz.netease.com/horizon/pkg/cluster/manager"
perrors "g.hz.netease.com/horizon/pkg/errors"
perror "g.hz.netease.com/horizon/pkg/errors"
groupmanager "g.hz.netease.com/horizon/pkg/group/manager"
groupsvc "g.hz.netease.com/horizon/pkg/group/service"
"g.hz.netease.com/horizon/pkg/hook/hook"
Expand Down Expand Up @@ -174,7 +174,7 @@ func (c *controller) CreateApplication(ctx context.Context, groupID uint, extraO

appExistsInDB, err := c.applicationMgr.GetByName(ctx, request.Name)
if err != nil {
if _, ok := perrors.Cause(err).(*he.HorizonErrNotFound); !ok {
if _, ok := perror.Cause(err).(*herrors.HorizonErrNotFound); !ok {
return nil, err
}
}
Expand Down Expand Up @@ -467,20 +467,20 @@ func (c *controller) ListUserApplication(ctx context.Context,
// get current user
currentUser, err := user.FromContext(ctx)
if err != nil {
return 0, nil, perrors.WithMessage(err, "no user in context")
return 0, nil, perror.WithMessage(err, "no user in context")
}

// get groups authorized to current user
groupIDs, err := c.memberManager.ListResourceOfMemberInfo(ctx, membermodels.TypeGroup, currentUser.GetID())
if err != nil {
return 0, nil,
perrors.WithMessage(err, "failed to list group resource of current user")
perror.WithMessage(err, "failed to list group resource of current user")
}

// get these groups' subGroups
subGroups, err := c.groupMgr.GetSubGroupsByGroupIDs(ctx, groupIDs)
if err != nil {
return 0, nil, perrors.WithMessage(err, "failed to get groups")
return 0, nil, perror.WithMessage(err, "failed to get groups")
}

subGroupIDs := make([]uint, 0)
Expand All @@ -491,7 +491,7 @@ func (c *controller) ListUserApplication(ctx context.Context,
count, applications, err := c.applicationMgr.ListUserAuthorizedByNameFuzzily(ctx,
filter, subGroupIDs, currentUser.GetID(), query)
if err != nil {
return 0, nil, perrors.WithMessage(err, "failed to list user applications")
return 0, nil, perror.WithMessage(err, "failed to list user applications")
}

// get groups for full path, full name
Expand Down
10 changes: 5 additions & 5 deletions core/controller/applicationregion/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"g.hz.netease.com/horizon/pkg/applicationregion/models"
"g.hz.netease.com/horizon/pkg/config/region"
envmanager "g.hz.netease.com/horizon/pkg/environment/manager"
perrors "g.hz.netease.com/horizon/pkg/errors"
perror "g.hz.netease.com/horizon/pkg/errors"
regionmanager "g.hz.netease.com/horizon/pkg/region/manager"
)

Expand Down Expand Up @@ -39,12 +39,12 @@ func NewController(regionConfig *region.Config) Controller {
func (c *controller) List(ctx context.Context, applicationID uint) (ApplicationRegion, error) {
applicationRegions, err := c.mgr.ListByApplicationID(ctx, applicationID)
if err != nil {
return nil, perrors.WithMessage(err, "failed to list application regions")
return nil, perror.WithMessage(err, "failed to list application regions")
}

environments, err := c.environmentMgr.ListAllEnvironment(ctx)
if err != nil {
return nil, perrors.WithMessage(err, "failed to list environment")
return nil, perror.WithMessage(err, "failed to list environment")
}

return ofApplicationRegion(applicationRegions, environments, c.regionConfig), nil
Expand All @@ -54,13 +54,13 @@ func (c *controller) Update(ctx context.Context, applicationID uint, regions App
applicationRegions := make([]*models.ApplicationRegion, 0)
currentUser, err := user.FromContext(ctx)
if err != nil {
return perrors.WithMessage(err, "no user in context")
return perror.WithMessage(err, "no user in context")
}

for _, r := range regions {
_, err := c.environmentMgr.GetByEnvironmentAndRegion(ctx, r.Environment, r.Region)
if err != nil {
return perrors.WithMessagef(err,
return perror.WithMessagef(err,
"environment/region %s/%s is not exists", r.Environment, r.Region)
}
applicationRegions = append(applicationRegions, &models.ApplicationRegion{
Expand Down
46 changes: 23 additions & 23 deletions core/controller/cluster/controller_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"regexp"
"strconv"

he "g.hz.netease.com/horizon/core/errors"
herrors "g.hz.netease.com/horizon/core/errors"
"g.hz.netease.com/horizon/core/middleware/user"
"g.hz.netease.com/horizon/lib/orm"
"g.hz.netease.com/horizon/lib/q"
Expand All @@ -18,7 +18,7 @@ import (
"g.hz.netease.com/horizon/pkg/cluster/gitrepo"
"g.hz.netease.com/horizon/pkg/cluster/registry"
clustertagmanager "g.hz.netease.com/horizon/pkg/clustertag/manager"
perrors "g.hz.netease.com/horizon/pkg/errors"
perror "g.hz.netease.com/horizon/pkg/errors"
"g.hz.netease.com/horizon/pkg/hook/hook"
membermodels "g.hz.netease.com/horizon/pkg/member/models"
"g.hz.netease.com/horizon/pkg/server/middleware/requestid"
Expand Down Expand Up @@ -92,20 +92,20 @@ func (c *controller) ListUserClusterByNameFuzzily(ctx context.Context, environme
// get current user
currentUser, err := user.FromContext(ctx)
if err != nil {
return 0, nil, perrors.WithMessage(err, "no user in context")
return 0, nil, perror.WithMessage(err, "no user in context")
}

// get groups authorized to current user
groupIDs, err := c.memberManager.ListResourceOfMemberInfo(ctx, membermodels.TypeGroup, currentUser.GetID())
if err != nil {
return 0, nil,
perrors.WithMessage(err, "failed to list group resource of current user")
perror.WithMessage(err, "failed to list group resource of current user")
}

// get these groups' subGroups
subGroups, err := c.groupManager.GetSubGroupsByGroupIDs(ctx, groupIDs)
if err != nil {
return 0, nil, perrors.WithMessage(err, "failed to get groups")
return 0, nil, perror.WithMessage(err, "failed to get groups")
}

subGroupIDs := make([]uint, 0)
Expand All @@ -116,7 +116,7 @@ func (c *controller) ListUserClusterByNameFuzzily(ctx context.Context, environme
// list applications of these subGroups
applications, err := c.applicationMgr.GetByGroupIDs(ctx, subGroupIDs)
if err != nil {
return 0, nil, perrors.WithMessage(err, "failed to get applications")
return 0, nil, perror.WithMessage(err, "failed to get applications")
}

applicationIDs := make([]uint, 0)
Expand All @@ -129,7 +129,7 @@ func (c *controller) ListUserClusterByNameFuzzily(ctx context.Context, environme
membermodels.TypeApplication, currentUser.GetID())
if err != nil {
return 0, nil,
perrors.WithMessage(err, "failed to list application resource of current user")
perror.WithMessage(err, "failed to list application resource of current user")
}

// all applicationIDs, including:
Expand All @@ -141,7 +141,7 @@ func (c *controller) ListUserClusterByNameFuzzily(ctx context.Context, environme
filter, applicationIDs, currentUser.GetID(), query)
if err != nil {
return 0, nil,
perrors.WithMessage(err, "failed to list user clusters")
perror.WithMessage(err, "failed to list user clusters")
}

// 2. get applications
Expand All @@ -152,7 +152,7 @@ func (c *controller) ListUserClusterByNameFuzzily(ctx context.Context, environme
applicationMap, err := c.applicationSvc.GetByIDs(ctx, clusterApplicationIDs)
if err != nil {
return 0, nil,
perrors.WithMessage(err, "failed to list application for clusters")
perror.WithMessage(err, "failed to list application for clusters")
}

resp = make([]*ListClusterWithFullResponse, 0)
Expand Down Expand Up @@ -298,7 +298,7 @@ func RenderOutputObject(outPutStr, templateName string,
}
binaryContent, err := yaml.Marshal(content)
if err != nil {
return nil, perrors.Wrap(he.ErrParamInvalid, err.Error())
return nil, perror.Wrap(herrors.ErrParamInvalid, err.Error())
}
oneDoc += string(binaryContent) + "\n"
}
Expand All @@ -307,7 +307,7 @@ func RenderOutputObject(outPutStr, templateName string,
var oneDocMap map[interface{}]interface{}
err := yaml.Unmarshal([]byte(oneDoc), &oneDocMap)
if err != nil {
return nil, perrors.Wrapf(he.ErrParamInvalid, "RenderOutputObject yaml Unmarshal error, err = %s", err.Error())
return nil, perror.Wrapf(herrors.ErrParamInvalid, "RenderOutputObject yaml Unmarshal error, err = %s", err.Error())
}

var addValuePrefixDocMap = make(map[interface{}]interface{})
Expand All @@ -316,17 +316,17 @@ func RenderOutputObject(outPutStr, templateName string,
doTemplate := template.Must(template.New("").Funcs(sprig.HtmlFuncMap()).Parse(outPutStr))
err = doTemplate.ExecuteTemplate(&b, "", addValuePrefixDocMap)
if err != nil {
return nil, perrors.Wrapf(he.ErrParamInvalid, "RenderOutputObject template error, err = %s", err.Error())
return nil, perror.Wrapf(herrors.ErrParamInvalid, "RenderOutputObject template error, err = %s", err.Error())
}

var retJSONObject interface{}
jsonBytes, err := kyaml.YAMLToJSON(b.Bytes())
if err != nil {
return nil, perrors.Wrapf(he.ErrParamInvalid, "RenderOutputObject YAMLToJSON error, err = %s", err.Error())
return nil, perror.Wrapf(herrors.ErrParamInvalid, "RenderOutputObject YAMLToJSON error, err = %s", err.Error())
}
err = json.Unmarshal(jsonBytes, &retJSONObject)
if err != nil {
return nil, perrors.Wrapf(he.ErrParamInvalid, "RenderOutputObject json Unmarshal error, err = %s", err.Error())
return nil, perror.Wrapf(herrors.ErrParamInvalid, "RenderOutputObject json Unmarshal error, err = %s", err.Error())
}
return retJSONObject, nil
}
Expand All @@ -353,7 +353,7 @@ func (c *controller) CreateCluster(ctx context.Context, applicationID uint,
return nil, err
}
if exists {
return nil, perrors.Wrap(he.ErrNameConflict,
return nil, perror.Wrap(herrors.ErrNameConflict,
"a cluster with the same name already exists, please do not create it again!")
}
if err := c.validateCreate(r); err != nil {
Expand Down Expand Up @@ -521,7 +521,7 @@ func (c *controller) UpdateCluster(ctx context.Context, clusterID uint,
renderValues[templateschema.ClusterIDKey] = clusterIDStr
if err := c.validateTemplateInput(ctx,
cluster.Template, templateRelease, r.TemplateInput, renderValues); err != nil {
return nil, perrors.Wrapf(he.ErrParamInvalid,
return nil, perror.Wrapf(herrors.ErrParamInvalid,
"request body validate err: %v", err)
}
// update cluster in git repo
Expand Down Expand Up @@ -791,13 +791,13 @@ func (c *controller) validateCreate(r *CreateClusterRequest) error {
return err
}
if r.Git == nil || r.Git.Branch == "" {
return perrors.Wrap(he.ErrParamInvalid, "git branch cannot be empty")
return perror.Wrap(herrors.ErrParamInvalid, "git branch cannot be empty")
}
if r.TemplateInput != nil && r.TemplateInput.Application == nil {
return perrors.Wrap(he.ErrParamInvalid, "application config for template cannot be empty")
return perror.Wrap(herrors.ErrParamInvalid, "application config for template cannot be empty")
}
if r.TemplateInput != nil && r.TemplateInput.Pipeline == nil {
return perrors.Wrap(he.ErrParamInvalid, "pipeline config for template cannot be empty")
return perror.Wrap(herrors.ErrParamInvalid, "pipeline config for template cannot be empty")
}
return nil
}
Expand All @@ -821,22 +821,22 @@ func (c *controller) validateTemplateInput(ctx context.Context,
// 3. name must start with application name
func validateClusterName(name string) error {
if len(name) == 0 {
return perrors.Wrap(he.ErrParamInvalid, "name cannot be empty")
return perror.Wrap(herrors.ErrParamInvalid, "name cannot be empty")
}

if len(name) > 53 {
return perrors.Wrap(he.ErrParamInvalid, "name must not exceed 53 characters")
return perror.Wrap(herrors.ErrParamInvalid, "name must not exceed 53 characters")
}

// cannot start with a digit.
if name[0] >= '0' && name[0] <= '9' {
return perrors.Wrap(he.ErrParamInvalid, "name cannot start with a digit")
return perror.Wrap(herrors.ErrParamInvalid, "name cannot start with a digit")
}

pattern := `^(([a-z][-a-z0-9]*)?[a-z0-9])?$`
r := regexp.MustCompile(pattern)
if !r.MatchString(name) {
return perrors.Wrapf(he.ErrParamInvalid, "invalid cluster name, regex used for validation is %v", pattern)
return perror.Wrapf(herrors.ErrParamInvalid, "invalid cluster name, regex used for validation is %v", pattern)
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions core/controller/cluster/controller_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"fmt"

he "g.hz.netease.com/horizon/core/errors"
herrors "g.hz.netease.com/horizon/core/errors"
"g.hz.netease.com/horizon/pkg/cluster/cd"
"g.hz.netease.com/horizon/pkg/cluster/common"
"g.hz.netease.com/horizon/pkg/cluster/gitrepo"
perrors "g.hz.netease.com/horizon/pkg/errors"
perror "g.hz.netease.com/horizon/pkg/errors"
"g.hz.netease.com/horizon/pkg/util/wlog"
)

Expand All @@ -23,7 +23,7 @@ func (c *controller) InternalDeploy(ctx context.Context, clusterID uint,
return nil, err
}
if pr == nil || pr.ClusterID != clusterID {
return nil, he.NewErrNotFound(he.Pipelinerun,
return nil, herrors.NewErrNotFound(herrors.Pipelinerun,
fmt.Sprintf("cannot find the pipelinerun with id: %v", r.PipelinerunID))
}

Expand Down Expand Up @@ -54,7 +54,7 @@ func (c *controller) InternalDeploy(ctx context.Context, clusterID uint,
},
})
if err != nil {
return nil, perrors.WithMessage(err, op)
return nil, perror.WithMessage(err, op)
}
if err := c.pipelinerunMgr.UpdateConfigCommitByID(ctx, pr.ID, commit); err != nil {
return nil, err
Expand All @@ -63,7 +63,7 @@ func (c *controller) InternalDeploy(ctx context.Context, clusterID uint,
// 4. merge branch from gitops to master
masterRevision, err := c.clusterGitRepo.MergeBranch(ctx, application.Name, cluster.Name)
if err != nil {
return nil, perrors.WithMessage(err, op)
return nil, perror.WithMessage(err, op)
}

// 5. create cluster in cd system
Expand Down
Loading

0 comments on commit 4a07336

Please sign in to comment.