diff --git a/pkg/ansibleserver/service/service.go b/pkg/ansibleserver/service/service.go index 3e9950f8f72..ba054af6c4d 100644 --- a/pkg/ansibleserver/service/service.go +++ b/pkg/ansibleserver/service/service.go @@ -30,7 +30,7 @@ import ( func StartService() { opts := &options.Options - common_options.ParseOptions(opts, os.Args, "ansibleserver.conf", "ansibleserver") + common_options.ParseOptions(opts, os.Args, "ansibleserver.conf", "ansibleserver", nil) commonOpts := &opts.CommonOptions common_app.InitAuth(commonOpts, func() { diff --git a/pkg/apigateway/service/service.go b/pkg/apigateway/service/service.go index 8b374d164a2..7659d53ea64 100644 --- a/pkg/apigateway/service/service.go +++ b/pkg/apigateway/service/service.go @@ -38,7 +38,7 @@ func StartService() { opts := options.Options baseOpts := &opts.BaseOptions commonOpts := &opts.CommonOptions - common_options.ParseOptions(opts, os.Args, "apigateway.conf", api.SERVICE_TYPE) + common_options.ParseOptions(opts, os.Args, "apigateway.conf", api.SERVICE_TYPE, nil) app_common.InitAuth(commonOpts, func() { log.Infof("Auth complete.") }) diff --git a/pkg/apimap/options/options.go b/pkg/apimap/options/options.go index 3aac2d041b9..277e1a3054a 100644 --- a/pkg/apimap/options/options.go +++ b/pkg/apimap/options/options.go @@ -34,7 +34,7 @@ func GetOptions() *SOptions { } func Init() { - common_options.ParseOptions(&opts, os.Args, "apimap.conf", "apimap") + common_options.ParseOptions(&opts, os.Args, "apimap.conf", "apimap", nil) options.Options = opts.ComputeOptions } func OnOptionsChange(oldO, newO interface{}) bool { diff --git a/pkg/apis/identity/consts.go b/pkg/apis/identity/consts.go index 0c67ccdac76..a302c673f1a 100644 --- a/pkg/apis/identity/consts.go +++ b/pkg/apis/identity/consts.go @@ -236,6 +236,7 @@ var ( // kubeserver blacklist options // ############################ "running_mode", + "enable_default_policy", }, } ) diff --git a/pkg/baremetal/service/service.go b/pkg/baremetal/service/service.go index 097387afb02..659dbd891ce 100644 --- a/pkg/baremetal/service/service.go +++ b/pkg/baremetal/service/service.go @@ -46,7 +46,7 @@ func New() *BaremetalService { } func (s *BaremetalService) StartService() { - common_options.ParseOptions(&o.Options, os.Args, "baremetal.conf", "baremetal") + common_options.ParseOptions(&o.Options, os.Args, "baremetal.conf", "baremetal", nil) if len(o.Options.CachePath) == 0 { o.Options.CachePath = filepath.Join(filepath.Dir(o.Options.BaremetalsPath), "bm_image_cache") diff --git a/pkg/cloudcommon/consts/db.go b/pkg/cloudcommon/consts/db.go index f23999a3d36..aed840e223d 100644 --- a/pkg/cloudcommon/consts/db.go +++ b/pkg/cloudcommon/consts/db.go @@ -31,6 +31,8 @@ var ( localTaskWorkerCount int enableChangeOwnerAutoRename = false + + enableDefaultPolicy = true ) func SetDefaultDB(dialect, connStr string) { @@ -81,3 +83,11 @@ func TaskWorkerCount() int { func LocalTaskWorkerCount() int { return localTaskWorkerCount } + +func SetDefaultPolicy(enable bool) { + enableDefaultPolicy = enable +} + +func IsEnableDefaultPolicy() bool { + return enableDefaultPolicy == true +} diff --git a/pkg/cloudcommon/options/options.go b/pkg/cloudcommon/options/options.go index cd3c1fed871..efc9d22bf65 100644 --- a/pkg/cloudcommon/options/options.go +++ b/pkg/cloudcommon/options/options.go @@ -19,7 +19,7 @@ import ( "crypto/x509" "encoding/pem" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -123,6 +123,7 @@ type BaseOptions struct { EnableAppProfiling bool `help:"enable profiling API" default:"false"` EnableChangeOwnerAutoRename bool `help:"Allows renaming when changing names" default:"false"` + EnableDefaultPolicy bool `help:"Enable defualt policies" default:"true"` } const ( @@ -220,7 +221,7 @@ func (opt *EtcdOptions) GetEtcdTLSConfig() (*tls.Config, error) { opt.EtcdUseTLS = true } if opt.EtcdCacert != "" { - data, err := ioutil.ReadFile(opt.EtcdCacert) + data, err := os.ReadFile(opt.EtcdCacert) if err != nil { return nil, errors.Wrap(err, "read cacert file") } @@ -279,8 +280,11 @@ func ParseOptionsIgnoreNoConfigfile(optStruct interface{}, args []string, config parseOptions(optStruct, args, configFileName, serviceType, true) } -func ParseOptions(optStruct interface{}, args []string, configFileName string, serviceType string) { +func ParseOptions(optStruct interface{}, args []string, configFileName string, serviceType string, callback func()) { parseOptions(optStruct, args, configFileName, serviceType, false) + if callback != nil { + callback() + } } func parseOptions(optStruct interface{}, args []string, configFileName string, serviceType string, ignoreNoConfigfile bool) { @@ -377,7 +381,7 @@ func parseOptions(optStruct interface{}, args []string, configFileName string, s h.Init() log.DisableColors() log.Logger().AddHook(h) - log.Logger().Out = ioutil.Discard + log.Logger().Out = io.Discard atexit.Register(atexit.ExitHandler{ Prio: atexit.PRIO_LOG_CLOSE, Reason: "deinit log rotate hook", @@ -397,6 +401,7 @@ func parseOptions(optStruct interface{}, args []string, configFileName string, s consts.SetTaskWorkerCount(optionsRef.TaskWorkerCount) consts.SetLocalTaskWorkerCount(optionsRef.LocalTaskWorkerCount) + consts.SetDefaultPolicy(optionsRef.EnableDefaultPolicy) } func (self *BaseOptions) HttpTransportProxyFunc() httputils.TransportProxyFunc { diff --git a/pkg/cloudevent/service/service.go b/pkg/cloudevent/service/service.go index 952f2c31344..696801b1760 100644 --- a/pkg/cloudevent/service/service.go +++ b/pkg/cloudevent/service/service.go @@ -37,7 +37,7 @@ import ( func StartService() { opts := &options.Options - common_options.ParseOptions(opts, os.Args, "yunionevent.conf", api.SERVICE_TYPE) + common_options.ParseOptions(opts, os.Args, "yunionevent.conf", api.SERVICE_TYPE, nil) commonOpts := &opts.CommonOptions common_app.InitAuth(commonOpts, func() { diff --git a/pkg/cloudid/policy/defaults.go b/pkg/cloudid/policy/defaults.go index a0ca1a7633d..b2bc3ea3edf 100644 --- a/pkg/cloudid/policy/defaults.go +++ b/pkg/cloudid/policy/defaults.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/pkg/util/rbacscope" api "yunion.io/x/onecloud/pkg/apis/cloudid" + "yunion.io/x/onecloud/pkg/cloudcommon/consts" common_policy "yunion.io/x/onecloud/pkg/cloudcommon/policy" "yunion.io/x/onecloud/pkg/util/rbacutils" ) @@ -108,6 +109,8 @@ var ( } ) -func init() { - common_policy.AppendDefaultPolicies(predefinedDefaultPolicies) +func Init() { + if consts.IsEnableDefaultPolicy() { + common_policy.AppendDefaultPolicies(predefinedDefaultPolicies) + } } diff --git a/pkg/cloudid/service/service.go b/pkg/cloudid/service/service.go index e1ad110a00e..4ec320babaf 100644 --- a/pkg/cloudid/service/service.go +++ b/pkg/cloudid/service/service.go @@ -35,7 +35,7 @@ import ( _ "yunion.io/x/onecloud/pkg/cloudid/drivers" "yunion.io/x/onecloud/pkg/cloudid/models" "yunion.io/x/onecloud/pkg/cloudid/options" - _ "yunion.io/x/onecloud/pkg/cloudid/policy" + "yunion.io/x/onecloud/pkg/cloudid/policy" "yunion.io/x/onecloud/pkg/cloudid/saml" _ "yunion.io/x/onecloud/pkg/cloudid/tasks" "yunion.io/x/onecloud/pkg/mcclient/auth" @@ -46,7 +46,7 @@ func StartService() { dbOpts := &opts.DBOptions baseOpts := &opts.BaseOptions commonOpts := &opts.CommonOptions - common_options.ParseOptions(opts, os.Args, "cloudid.conf", api.SERVICE_TYPE) + common_options.ParseOptions(opts, os.Args, "cloudid.conf", api.SERVICE_TYPE, policy.Init) app_common.InitAuth(commonOpts, func() { log.Infof("Auth complete!!") diff --git a/pkg/cloudir/service/service.go b/pkg/cloudir/service/service.go index 91abd58ab26..e3e1a059b2d 100644 --- a/pkg/cloudir/service/service.go +++ b/pkg/cloudir/service/service.go @@ -30,7 +30,7 @@ func StartService() { opts := &options.Options baseOpts := &opts.BaseOptions commonOpts := &opts.CommonOptions - common_options.ParseOptions(opts, os.Args, "cloudir.conf", "cloudir") + common_options.ParseOptions(opts, os.Args, "cloudir.conf", "cloudir", nil) app_common.InitAuth(commonOpts, func() { log.Infof("Auth complete!!") diff --git a/pkg/cloudmon/service/service.go b/pkg/cloudmon/service/service.go index 250fd0f5de5..b3c00b4b2b3 100644 --- a/pkg/cloudmon/service/service.go +++ b/pkg/cloudmon/service/service.go @@ -38,7 +38,7 @@ import ( func StartService() { opts := &options.Options baseOpts := &options.Options.BaseOptions - common_options.ParseOptions(opts, os.Args, "cloudmon.conf", "cloudmon") + common_options.ParseOptions(opts, os.Args, "cloudmon.conf", "cloudmon", nil) commonOpts := &opts.CommonOptions app_common.InitAuth(commonOpts, func() { diff --git a/pkg/cloudnet/service/service.go b/pkg/cloudnet/service/service.go index bd3423bfeb2..e9d855831d0 100644 --- a/pkg/cloudnet/service/service.go +++ b/pkg/cloudnet/service/service.go @@ -35,7 +35,7 @@ import ( func StartService() { opts := &options.Options - common_options.ParseOptions(opts, os.Args, "cloudnet.conf", "cloudnet") + common_options.ParseOptions(opts, os.Args, "cloudnet.conf", "cloudnet", nil) commonOpts := &opts.CommonOptions app_common.InitAuth(commonOpts, func() { diff --git a/pkg/cloudproxy/options/options.go b/pkg/cloudproxy/options/options.go index 45281a55c25..1fd66cdfe5a 100644 --- a/pkg/cloudproxy/options/options.go +++ b/pkg/cloudproxy/options/options.go @@ -44,6 +44,7 @@ func Get() *Options { os.Args, "cloudproxy.conf", api.SERVICE_TYPE, + nil, ) }) return &opts diff --git a/pkg/cloutpost/service/service.go b/pkg/cloutpost/service/service.go index 1ede66c4d9c..90e5fff5e32 100644 --- a/pkg/cloutpost/service/service.go +++ b/pkg/cloutpost/service/service.go @@ -40,7 +40,7 @@ func StartService() { opts := &options.Options baseOpts := &opts.BaseOptions commonOpts := &opts.CommonOptions - common_options.ParseOptions(opts, os.Args, "cloutpost.conf", SERVICE_TYPE) + common_options.ParseOptions(opts, os.Args, "cloutpost.conf", SERVICE_TYPE, nil) app_common.InitAuth(commonOpts, func() { log.Infof("Auth complete!!") diff --git a/pkg/compute/policy/defaults.go b/pkg/compute/policy/defaults.go index e511b1eadf0..a5532ce1be7 100644 --- a/pkg/compute/policy/defaults.go +++ b/pkg/compute/policy/defaults.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/pkg/util/rbacscope" api "yunion.io/x/onecloud/pkg/apis/compute" + "yunion.io/x/onecloud/pkg/cloudcommon/consts" common_policy "yunion.io/x/onecloud/pkg/cloudcommon/policy" "yunion.io/x/onecloud/pkg/util/rbacutils" ) @@ -403,6 +404,8 @@ var ( } ) -func init() { - common_policy.AppendDefaultPolicies(predefinedDefaultPolicies) +func Init() { + if consts.IsEnableDefaultPolicy() { + common_policy.AppendDefaultPolicies(predefinedDefaultPolicies) + } } diff --git a/pkg/compute/service/service.go b/pkg/compute/service/service.go index 9174a96b985..33d45418f0d 100644 --- a/pkg/compute/service/service.go +++ b/pkg/compute/service/service.go @@ -48,7 +48,7 @@ import ( _ "yunion.io/x/onecloud/pkg/compute/hostdrivers" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/compute/options" - _ "yunion.io/x/onecloud/pkg/compute/policy" + "yunion.io/x/onecloud/pkg/compute/policy" _ "yunion.io/x/onecloud/pkg/compute/regiondrivers" _ "yunion.io/x/onecloud/pkg/compute/storagedrivers" "yunion.io/x/onecloud/pkg/compute/tasks" @@ -66,7 +66,7 @@ func StartServiceWithJobs(jobs func(cron *cronman.SCronJobManager)) { commonOpts := &options.Options.CommonOptions baseOpts := &options.Options.BaseOptions dbOpts := &options.Options.DBOptions - common_options.ParseOptions(opts, os.Args, "region.conf", api.SERVICE_TYPE) + common_options.ParseOptions(opts, os.Args, "region.conf", api.SERVICE_TYPE, policy.Init) if opts.PortV2 > 0 { log.Infof("Port V2 %d is specified, use v2 port", opts.PortV2) diff --git a/pkg/devtool/service/service.go b/pkg/devtool/service/service.go index 2521a71d1cc..6bb22d109af 100644 --- a/pkg/devtool/service/service.go +++ b/pkg/devtool/service/service.go @@ -36,7 +36,7 @@ func StartService() { commonOpts := &opts.CommonOptions dbOpts := &options.Options.DBOptions baseOpts := &opts.BaseOptions - common_options.ParseOptions(opts, os.Args, "devtool.conf", api.SERVICE_TYPE) + common_options.ParseOptions(opts, os.Args, "devtool.conf", api.SERVICE_TYPE, nil) app_common.InitAuth(commonOpts, func() { log.Infof("Auth complete!!") diff --git a/pkg/esxi/service/esxi_agent_service.go b/pkg/esxi/service/esxi_agent_service.go index 4af8966b408..87eb0b7c6e7 100644 --- a/pkg/esxi/service/esxi_agent_service.go +++ b/pkg/esxi/service/esxi_agent_service.go @@ -43,7 +43,7 @@ func New() *SExsiAgentService { } func (s *SExsiAgentService) StartService() { - options_common.ParseOptions(&options.Options, os.Args, "esxiagent.conf", "esxiagent") + options_common.ParseOptions(&options.Options, os.Args, "esxiagent.conf", "esxiagent", nil) if len(options.Options.ImageCachePath) == 0 { options.Options.ImageCachePath = filepath.Join(options.Options.EsxiAgentPath, "image_cache") diff --git a/pkg/hostimage/host_image_service.go b/pkg/hostimage/host_image_service.go index b057a03576b..cec127af52f 100644 --- a/pkg/hostimage/host_image_service.go +++ b/pkg/hostimage/host_image_service.go @@ -59,12 +59,12 @@ func init() { func StartService() { consts.SetServiceType("host-image") - common_options.ParseOptions(&HostImageOptions, os.Args, "host.conf", "host-image") + common_options.ParseOptions(&HostImageOptions, os.Args, "host.conf", "host-image", nil) if len(HostImageOptions.CommonConfigFile) > 0 { baseOpt := HostImageOptions.BaseOptions.BaseOptions commonCfg := new(common_options.CommonOptions) commonCfg.Config = HostImageOptions.CommonConfigFile - common_options.ParseOptions(commonCfg, []string{"host"}, "common.conf", "host") + common_options.ParseOptions(commonCfg, []string{"host"}, "common.conf", "host", nil) HostImageOptions.CommonOptions = *commonCfg HostImageOptions.BaseOptions.BaseOptions = baseOpt } diff --git a/pkg/hostman/hostdeployer/deployserver/options.go b/pkg/hostman/hostdeployer/deployserver/options.go index ac55019df19..913ab0b1d31 100644 --- a/pkg/hostman/hostdeployer/deployserver/options.go +++ b/pkg/hostman/hostdeployer/deployserver/options.go @@ -55,7 +55,7 @@ func Parse() SDeployOptions { if len(hostOpts.CommonConfigFile) > 0 && fileutils2.Exists(hostOpts.CommonConfigFile) { commonCfg := &host_options.SHostBaseOptions{} commonCfg.Config = hostOpts.CommonConfigFile - common_options.ParseOptions(commonCfg, []string{os.Args[0]}, "common.conf", "host") + common_options.ParseOptions(commonCfg, []string{os.Args[0]}, "common.conf", "host", nil) baseOpt := hostOpts.BaseOptions.BaseOptions hostOpts.SHostBaseOptions = *commonCfg // keep base options diff --git a/pkg/hostman/options/options.go b/pkg/hostman/options/options.go index 149ba542d15..14ee325a485 100644 --- a/pkg/hostman/options/options.go +++ b/pkg/hostman/options/options.go @@ -253,11 +253,11 @@ var ( func Parse() SHostOptions { var hostOpts SHostOptions - common_options.ParseOptions(&hostOpts, os.Args, "host.conf", "host") + common_options.ParseOptions(&hostOpts, os.Args, "host.conf", "host", nil) if len(hostOpts.CommonConfigFile) > 0 && fileutils2.Exists(hostOpts.CommonConfigFile) { commonCfg := &SHostBaseOptions{} commonCfg.Config = hostOpts.CommonConfigFile - common_options.ParseOptions(commonCfg, []string{os.Args[0]}, "common.conf", "host") + common_options.ParseOptions(commonCfg, []string{os.Args[0]}, "common.conf", "host", nil) baseOpt := hostOpts.BaseOptions.BaseOptions hostOpts.SHostBaseOptions = *commonCfg // keep base options diff --git a/pkg/image/policy/defaults.go b/pkg/image/policy/defaults.go index 6f77e2bcd2b..09a6c06fafb 100644 --- a/pkg/image/policy/defaults.go +++ b/pkg/image/policy/defaults.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/pkg/util/rbacscope" api "yunion.io/x/onecloud/pkg/apis/image" + "yunion.io/x/onecloud/pkg/cloudcommon/consts" common_policy "yunion.io/x/onecloud/pkg/cloudcommon/policy" "yunion.io/x/onecloud/pkg/util/rbacutils" ) @@ -65,6 +66,8 @@ var ( } ) -func init() { - common_policy.AppendDefaultPolicies(predefinedDefaultPolicies) +func Init() { + if consts.IsEnableDefaultPolicy() { + common_policy.AppendDefaultPolicies(predefinedDefaultPolicies) + } } diff --git a/pkg/image/service/service.go b/pkg/image/service/service.go index b57511ef940..ef6513d2f3c 100644 --- a/pkg/image/service/service.go +++ b/pkg/image/service/service.go @@ -40,7 +40,7 @@ import ( "yunion.io/x/onecloud/pkg/image/drivers/s3" "yunion.io/x/onecloud/pkg/image/models" "yunion.io/x/onecloud/pkg/image/options" - _ "yunion.io/x/onecloud/pkg/image/policy" + "yunion.io/x/onecloud/pkg/image/policy" _ "yunion.io/x/onecloud/pkg/image/tasks" "yunion.io/x/onecloud/pkg/image/torrent" "yunion.io/x/onecloud/pkg/mcclient/auth" @@ -54,7 +54,7 @@ func StartService() { commonOpts := &opts.CommonOptions baseOpts := &opts.BaseOptions dbOpts := &opts.DBOptions - common_options.ParseOptions(opts, os.Args, "glance-api.conf", api.SERVICE_TYPE) + common_options.ParseOptions(opts, os.Args, "glance-api.conf", api.SERVICE_TYPE, policy.Init) // no need to run glance as root any more // isRoot := sysutils.IsRootPermission() diff --git a/pkg/keystone/policy/defaults.go b/pkg/keystone/policy/defaults.go index f9c478931f4..26f7d35bdf3 100644 --- a/pkg/keystone/policy/defaults.go +++ b/pkg/keystone/policy/defaults.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/pkg/util/rbacscope" api "yunion.io/x/onecloud/pkg/apis/identity" + "yunion.io/x/onecloud/pkg/cloudcommon/consts" common_policy "yunion.io/x/onecloud/pkg/cloudcommon/policy" "yunion.io/x/onecloud/pkg/util/rbacutils" ) @@ -191,6 +192,8 @@ var ( } ) -func init() { - common_policy.AppendDefaultPolicies(predefinedDefaultPolicies) +func Init() { + if consts.IsEnableDefaultPolicy() { + common_policy.AppendDefaultPolicies(predefinedDefaultPolicies) + } } diff --git a/pkg/keystone/service/service.go b/pkg/keystone/service/service.go index e15e7b56296..6ea96ca6c57 100644 --- a/pkg/keystone/service/service.go +++ b/pkg/keystone/service/service.go @@ -35,7 +35,7 @@ import ( "yunion.io/x/onecloud/pkg/keystone/cronjobs" "yunion.io/x/onecloud/pkg/keystone/models" "yunion.io/x/onecloud/pkg/keystone/options" - _ "yunion.io/x/onecloud/pkg/keystone/policy" + kpolicy "yunion.io/x/onecloud/pkg/keystone/policy" "yunion.io/x/onecloud/pkg/keystone/saml" _ "yunion.io/x/onecloud/pkg/keystone/tasks" "yunion.io/x/onecloud/pkg/keystone/tokens" @@ -62,7 +62,7 @@ func StartService() { models.InitSyncWorkers() opts := &options.Options - common_options.ParseOptions(opts, os.Args, "keystone.conf", api.SERVICE_TYPE) + common_options.ParseOptions(opts, os.Args, "keystone.conf", api.SERVICE_TYPE, kpolicy.Init) if opts.Port == 0 { opts.Port = 5000 // keystone well-known port diff --git a/pkg/lbagent/service.go b/pkg/lbagent/service.go index 68c26ba6811..baa4c796b4a 100644 --- a/pkg/lbagent/service.go +++ b/pkg/lbagent/service.go @@ -38,12 +38,12 @@ func StartService() { opts := &Options{} commonOpts := &opts.CommonOptions { - common_options.ParseOptions(opts, os.Args, "lbagent.conf", "lbagent") + common_options.ParseOptions(opts, os.Args, "lbagent.conf", "lbagent", nil) if len(opts.CommonConfigFile) > 0 && fileutils2.Exists(opts.CommonConfigFile) { log.Infof("read common config file: %s", opts.CommonConfigFile) commonCfg := &LbagentCommonOptions{} commonCfg.Config = opts.CommonConfigFile - common_options.ParseOptions(commonCfg, []string{os.Args[0]}, "common.conf", "lbagent") + common_options.ParseOptions(commonCfg, []string{os.Args[0]}, "common.conf", "lbagent", nil) baseOpt := opts.BaseOptions.BaseOptions opts.LbagentCommonOptions = *commonCfg // keep base options diff --git a/pkg/logger/policy/defaults.go b/pkg/logger/policy/defaults.go index 1545ca9fd64..074ec408194 100644 --- a/pkg/logger/policy/defaults.go +++ b/pkg/logger/policy/defaults.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/pkg/util/rbacscope" api "yunion.io/x/onecloud/pkg/apis/logger" + "yunion.io/x/onecloud/pkg/cloudcommon/consts" common_policy "yunion.io/x/onecloud/pkg/cloudcommon/policy" "yunion.io/x/onecloud/pkg/util/rbacutils" ) @@ -57,6 +58,8 @@ var ( } ) -func init() { - common_policy.AppendDefaultPolicies(predefinedDefaultPolicies) +func Init() { + if consts.IsEnableDefaultPolicy() { + common_policy.AppendDefaultPolicies(predefinedDefaultPolicies) + } } diff --git a/pkg/logger/service/service.go b/pkg/logger/service/service.go index 31bd159924f..836f7ce416a 100644 --- a/pkg/logger/service/service.go +++ b/pkg/logger/service/service.go @@ -30,7 +30,7 @@ import ( "yunion.io/x/onecloud/pkg/logger/extern" "yunion.io/x/onecloud/pkg/logger/models" "yunion.io/x/onecloud/pkg/logger/options" - _ "yunion.io/x/onecloud/pkg/logger/policy" + "yunion.io/x/onecloud/pkg/logger/policy" ) func StartService() { @@ -41,7 +41,7 @@ func StartService() { baseOpts := &opts.BaseOptions commonOpts := &opts.CommonOptions dbOpts := &opts.DBOptions - common_options.ParseOptions(opts, os.Args, "log.conf", api.SERVICE_TYPE) + common_options.ParseOptions(opts, os.Args, "log.conf", api.SERVICE_TYPE, policy.Init) app_common.InitAuth(commonOpts, func() { log.Infof("Auth complete!!") diff --git a/pkg/monitor/service/service.go b/pkg/monitor/service/service.go index cbbdee0cfcc..627276021c0 100644 --- a/pkg/monitor/service/service.go +++ b/pkg/monitor/service/service.go @@ -50,7 +50,7 @@ import ( func StartService() { opts := &options.Options - common_options.ParseOptions(opts, os.Args, "monitor.conf", "monitor") + common_options.ParseOptions(opts, os.Args, "monitor.conf", "monitor", nil) commonOpts := &opts.CommonOptions common_app.InitAuth(commonOpts, func() { diff --git a/pkg/notify/policy/defaults.go b/pkg/notify/policy/defaults.go index 509b2efba7d..c3f405f3ea8 100644 --- a/pkg/notify/policy/defaults.go +++ b/pkg/notify/policy/defaults.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/pkg/util/rbacscope" api "yunion.io/x/onecloud/pkg/apis/notify" + "yunion.io/x/onecloud/pkg/cloudcommon/consts" common_policy "yunion.io/x/onecloud/pkg/cloudcommon/policy" "yunion.io/x/onecloud/pkg/util/rbacutils" ) @@ -180,6 +181,8 @@ var ( } ) -func init() { - common_policy.AppendDefaultPolicies(predefinedDefaultPolicies) +func Init() { + if consts.IsEnableDefaultPolicy() { + common_policy.AppendDefaultPolicies(predefinedDefaultPolicies) + } } diff --git a/pkg/notify/service/service.go b/pkg/notify/service/service.go index dad2b0fd1d7..912ec8466ac 100644 --- a/pkg/notify/service/service.go +++ b/pkg/notify/service/service.go @@ -30,7 +30,7 @@ import ( common_options "yunion.io/x/onecloud/pkg/cloudcommon/options" "yunion.io/x/onecloud/pkg/notify/models" "yunion.io/x/onecloud/pkg/notify/options" - _ "yunion.io/x/onecloud/pkg/notify/policy" + "yunion.io/x/onecloud/pkg/notify/policy" _ "yunion.io/x/onecloud/pkg/notify/sender/smsdriver" _ "yunion.io/x/onecloud/pkg/notify/tasks" ) @@ -41,7 +41,7 @@ func StartService() { commonOpts := &options.Options.CommonOptions dbOpts := &options.Options.DBOptions baseOpts := &options.Options.BaseOptions - common_options.ParseOptions(opts, os.Args, "notify.conf", api.SERVICE_TYPE) + common_options.ParseOptions(opts, os.Args, "notify.conf", api.SERVICE_TYPE, policy.Init) // init auth app.InitAuth(commonOpts, func() { diff --git a/pkg/s3gateway/service/service.go b/pkg/s3gateway/service/service.go index f6d2e5170cd..341ed7e91df 100644 --- a/pkg/s3gateway/service/service.go +++ b/pkg/s3gateway/service/service.go @@ -33,7 +33,7 @@ func StartService() { opts := &options.Options commonOpts := &opts.CommonOptions baseOpts := &opts.BaseOptions - common_options.ParseOptions(opts, os.Args, "s3gateway.conf", api.SERVICE_TYPE) + common_options.ParseOptions(opts, os.Args, "s3gateway.conf", api.SERVICE_TYPE, nil) app_common.InitAuth(commonOpts, func() { log.Infof("Auth complete!!") diff --git a/pkg/scheduledtask/service/service.go b/pkg/scheduledtask/service/service.go index eb4b17d325f..ef9f8755421 100644 --- a/pkg/scheduledtask/service/service.go +++ b/pkg/scheduledtask/service/service.go @@ -36,7 +36,7 @@ func StartService() { commonOpts := &options.Options.CommonOptions dbOpts := &options.Options.DBOptions baseOpts := &options.Options.BaseOptions - common_options.ParseOptions(opts, os.Args, "scheduledtask.conf", api.SERVICE_TYPE) + common_options.ParseOptions(opts, os.Args, "scheduledtask.conf", api.SERVICE_TYPE, nil) app.InitAuth(commonOpts, func() { log.Infof("Auth complete!") diff --git a/pkg/scheduler/options/options.go b/pkg/scheduler/options/options.go index c0bb56eddf4..2f49ada68ec 100644 --- a/pkg/scheduler/options/options.go +++ b/pkg/scheduler/options/options.go @@ -128,7 +128,7 @@ var ( ) func Init() { - common_options.ParseOptions(&Options, os.Args, "region.conf", api.SERVICE_TYPE) + common_options.ParseOptions(&Options, os.Args, "region.conf", api.SERVICE_TYPE, nil) options.Options = Options.ComputeOptions } diff --git a/pkg/vpcagent/service/service.go b/pkg/vpcagent/service/service.go index e269d1de69e..698946be037 100644 --- a/pkg/vpcagent/service/service.go +++ b/pkg/vpcagent/service/service.go @@ -54,7 +54,7 @@ func StartService() { opts := &options.Options{} commonOpts := &opts.CommonOptions { - common_options.ParseOptions(opts, os.Args, "vpcagent.conf", "vpcagent") + common_options.ParseOptions(opts, os.Args, "vpcagent.conf", "vpcagent", nil) app_common.InitAuth(commonOpts, func() { log.Infof("auth finished ok") }) diff --git a/pkg/webconsole/service/service.go b/pkg/webconsole/service/service.go index 39b4e47ba5e..832c59d65b7 100644 --- a/pkg/webconsole/service/service.go +++ b/pkg/webconsole/service/service.go @@ -45,7 +45,7 @@ func StartService() { opts := &o.Options commonOpts := &o.Options.CommonOptions - common_options.ParseOptions(opts, os.Args, "webconsole.conf", api.SERVICE_TYPE) + common_options.ParseOptions(opts, os.Args, "webconsole.conf", api.SERVICE_TYPE, nil) app_common.InitAuth(commonOpts, func() { log.Infof("Auth complete") diff --git a/pkg/yunionconf/policy/defaults.go b/pkg/yunionconf/policy/defaults.go index fd0d2caeb6e..01d3018deba 100644 --- a/pkg/yunionconf/policy/defaults.go +++ b/pkg/yunionconf/policy/defaults.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/pkg/util/rbacscope" api "yunion.io/x/onecloud/pkg/apis/yunionconf" + "yunion.io/x/onecloud/pkg/cloudcommon/consts" common_policy "yunion.io/x/onecloud/pkg/cloudcommon/policy" "yunion.io/x/onecloud/pkg/util/rbacutils" ) @@ -95,6 +96,8 @@ var ( } ) -func init() { - common_policy.AppendDefaultPolicies(predefinedDefaultPolicies) +func Init() { + if consts.IsEnableDefaultPolicy() { + common_policy.AppendDefaultPolicies(predefinedDefaultPolicies) + } } diff --git a/pkg/yunionconf/service/service.go b/pkg/yunionconf/service/service.go index 7a26502d613..0460638626a 100644 --- a/pkg/yunionconf/service/service.go +++ b/pkg/yunionconf/service/service.go @@ -32,7 +32,7 @@ import ( "yunion.io/x/onecloud/pkg/mcclient/auth" "yunion.io/x/onecloud/pkg/yunionconf/models" "yunion.io/x/onecloud/pkg/yunionconf/options" - _ "yunion.io/x/onecloud/pkg/yunionconf/policy" + "yunion.io/x/onecloud/pkg/yunionconf/policy" ) func StartService() { @@ -41,7 +41,7 @@ func StartService() { baseOpts := &options.Options.BaseOptions commonOpts := &options.Options.CommonOptions dbOpts := &options.Options.DBOptions - common_options.ParseOptions(opts, os.Args, "yunionconf.conf", api.SERVICE_TYPE) + common_options.ParseOptions(opts, os.Args, "yunionconf.conf", api.SERVICE_TYPE, policy.Init) app_common.InitAuth(commonOpts, func() { log.Infof("Auth complete!!") })