Skip to content

Commit

Permalink
make var optimizationEnabled private
Browse files Browse the repository at this point in the history
  • Loading branch information
BugsGuru committed Nov 7, 2024
1 parent 2743a0a commit f553cba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions internal/apiserver/conf/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
pkgParams "github.com/actiontech/dms/pkg/params"
)

var IsOptimizationEnabled bool

type Options struct {
DMS DMSOptions `yaml:"dms" validate:"required"`
SQLE SQLEOptions `yaml:"sqle"`
Expand Down Expand Up @@ -60,11 +58,17 @@ type DatabaseDriverOption struct {
Params pkgParams.Params `yaml:"params"`
}

var optimizationEnabled bool

func IsOptimizationEnabled() bool {
return optimizationEnabled
}

func ReadOptions(log utilLog.Logger, path string) (*DMSOptions, error) {
var opts Options
if err := utilConf.ParseYamlFile(log, path, &opts); err != nil {
return nil, err
}
IsOptimizationEnabled = getOptimizationEnabled(&opts)
optimizationEnabled = getOptimizationEnabled(&opts)
return &opts.DMS, nil
}
2 changes: 1 addition & 1 deletion internal/dms/service/op_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (d *DMSService) ListOpPermissions(ctx context.Context, req *dmsV1.ListOpPer
}

// 不支持智能调优时,隐藏相关权限
if !conf.IsOptimizationEnabled {
if !conf.IsOptimizationEnabled() {
listOption.FilterBy = append(listOption.FilterBy,
pkgConst.FilterCondition{
Field: string(biz.OpPermissionFieldUID),
Expand Down
2 changes: 1 addition & 1 deletion internal/dms/service/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (d *DMSService) ListRoles(ctx context.Context, req *dmsV1.ListRoleReq) (rep
}
for _, op := range ops {
// 不支持智能调优时,隐藏相关权限
if !conf.IsOptimizationEnabled &&
if !conf.IsOptimizationEnabled() &&
(op.UID == pkgConst.UIDOfOpPermissionCreateOptimization || op.UID == pkgConst.UIDOfOpPermissionViewOthersOptimization) {
continue
}
Expand Down

0 comments on commit f553cba

Please sign in to comment.