From 5e6070d809c3e137c507a646e772e6eea69893a7 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Mon, 30 Mar 2020 14:57:56 +0800 Subject: [PATCH] feature: make webconsole's api_server option common --- pkg/apis/identity/consts.go | 1 + pkg/apis/notify/notify.go | 5 ++++ pkg/apis/webconsole/consts.go | 20 ++++++++++++++++ pkg/apis/webconsole/doc.go | 15 ++++++++++++ pkg/cloudcommon/options/options.go | 2 ++ pkg/notify/models/mod_template.go | 4 ++++ pkg/notify/options/options.go | 37 ++++++++++++++++++++++-------- pkg/notify/service.go | 5 +++- pkg/webconsole/options/options.go | 14 ++++++++++- pkg/webconsole/service/service.go | 6 ++++- 10 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 pkg/apis/webconsole/consts.go create mode 100644 pkg/apis/webconsole/doc.go diff --git a/pkg/apis/identity/consts.go b/pkg/apis/identity/consts.go index 04520281e4..92a44ddc09 100644 --- a/pkg/apis/identity/consts.go +++ b/pkg/apis/identity/consts.go @@ -96,6 +96,7 @@ var ( "non_default_domain_projects", "time_zone", "domainized_namespace", + "api_server", }, } diff --git a/pkg/apis/notify/notify.go b/pkg/apis/notify/notify.go index dfa0dc05f3..f634f30b07 100644 --- a/pkg/apis/notify/notify.go +++ b/pkg/apis/notify/notify.go @@ -13,3 +13,8 @@ // limitations under the License. package notify + +const ( + SERVICE_TYPE = "notify" + SERVICE_VERSION = "" +) diff --git a/pkg/apis/webconsole/consts.go b/pkg/apis/webconsole/consts.go new file mode 100644 index 0000000000..bbf71f1504 --- /dev/null +++ b/pkg/apis/webconsole/consts.go @@ -0,0 +1,20 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package webconsole + +const ( + SERVICE_TYPE = "webconsole" + SERVICE_VERSION = "" +) diff --git a/pkg/apis/webconsole/doc.go b/pkg/apis/webconsole/doc.go new file mode 100644 index 0000000000..360afbd70d --- /dev/null +++ b/pkg/apis/webconsole/doc.go @@ -0,0 +1,15 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package webconsole // import "yunion.io/x/onecloud/pkg/apis/webconsole" diff --git a/pkg/cloudcommon/options/options.go b/pkg/cloudcommon/options/options.go index 7919876049..d4d59666cb 100644 --- a/pkg/cloudcommon/options/options.go +++ b/pkg/cloudcommon/options/options.go @@ -88,6 +88,8 @@ type BaseOptions struct { DomainizedNamespace bool `help:"turn on global name space, default is on" default:"false" json:"global_namespace,allowfalse"` + ApiServer string `help:"URL to access frontend webconsole" default:"http://webconsole.yunion.io"` + structarg.BaseOptions } diff --git a/pkg/notify/models/mod_template.go b/pkg/notify/models/mod_template.go index 9f6bc59150..aca9b1be47 100644 --- a/pkg/notify/models/mod_template.go +++ b/pkg/notify/models/mod_template.go @@ -34,6 +34,7 @@ import ( "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/notify/options" "yunion.io/x/onecloud/pkg/notify/rpc/apis" + "yunion.io/x/onecloud/pkg/util/httputils" ) type STemplateManager struct { @@ -72,6 +73,9 @@ type STemplate struct { } func (tm *STemplateManager) GetEmailUrl() string { + if len(options.Options.ApiServer) > 0 && len(options.Options.VerifyEmailUrlPath) > 0 { + return httputils.JoinPath(options.Options.ApiServer, options.Options.VerifyEmailUrlPath) + } return options.Options.VerifyEmailUrl } diff --git a/pkg/notify/options/options.go b/pkg/notify/options/options.go index 22f24aaed8..7d98829cb4 100644 --- a/pkg/notify/options/options.go +++ b/pkg/notify/options/options.go @@ -15,20 +15,39 @@ package options import ( - "yunion.io/x/onecloud/pkg/cloudcommon/options" + common_options "yunion.io/x/onecloud/pkg/cloudcommon/options" ) type NotifyOption struct { - options.CommonOptions - options.DBOptions + common_options.CommonOptions + common_options.DBOptions + + DingtalkEnabled bool `help:"Enable dingtalk"` + SocketFileDir string `help:"Socket file directory" default:"/etc/yunion/notify"` + UpdateInterval int `help:"Update send services interval(unit:min)" default:"30"` + VerifyEmailUrlPath string `help:"url of verify email" json:"verify_email_url_path"` + + // Deprecated + VerifyEmailUrl string `help:"url of verify email" json:"verify_email_url"` + + ReSendScope int `help:"Resend all messages that have not been sent successfully within ReSendScope seconds" default:"30"` - DingtalkEnabled bool `help:"Enable dingtalk"` - SocketFileDir string `help:"Socket file directory" default:"/etc/yunion/notify"` - UpdateInterval int `help:"Update send services interval(unit:min)" default:"30"` - VerifyEmailUrl string `help:"url of verify email"` - ReSendScope int `help:"Resend all messages that have not been sent successfully within ReSendScope -seconds" default:"30"` InitNotificationScope int `help:"initialize data of notification with in InitNotificationScope hours" default:"100"` } var Options NotifyOption + +func OnOptionsChange(oldO, newO interface{}) bool { + oldOpts := oldO.(*NotifyOption) + newOpts := newO.(*NotifyOption) + + if common_options.OnCommonOptionsChange(&oldOpts.CommonOptions, &newOpts.CommonOptions) { + return true + } + + if oldOpts.SocketFileDir != newOpts.SocketFileDir { + return true + } + + return false +} diff --git a/pkg/notify/service.go b/pkg/notify/service.go index 8212e72ffe..ef6781eb37 100644 --- a/pkg/notify/service.go +++ b/pkg/notify/service.go @@ -23,6 +23,7 @@ import ( "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/notify" "yunion.io/x/onecloud/pkg/cloudcommon" "yunion.io/x/onecloud/pkg/cloudcommon/app" "yunion.io/x/onecloud/pkg/cloudcommon/cronman" @@ -41,13 +42,15 @@ func StartService() { commonOpts := &options.Options.CommonOptions dbOpts := &options.Options.DBOptions baseOpts := &options.Options.BaseOptions - common_options.ParseOptions(opts, os.Args, "notify.conf", "notify") + common_options.ParseOptions(opts, os.Args, "notify.conf", api.SERVICE_TYPE) // init auth app.InitAuth(commonOpts, func() { log.Infof("Auth complete!") }) + common_options.StartOptionManager(opts, opts.ConfigSyncPeriodSeconds, api.SERVICE_TYPE, api.SERVICE_VERSION, options.OnOptionsChange) + // init handler applicaion := app.InitApp(baseOpts, true) InitHandlers(applicaion) diff --git a/pkg/webconsole/options/options.go b/pkg/webconsole/options/options.go index e5d33335de..67fdedab33 100644 --- a/pkg/webconsole/options/options.go +++ b/pkg/webconsole/options/options.go @@ -23,10 +23,22 @@ var ( type WebConsoleOptions struct { common_options.CommonOptions - ApiServer string `help:"API server url to handle websocket connection, usually with public access" default:"http://webconsole.yunion.io"` + //ApiServer string `help:"API server url to handle websocket connection, usually with public access" default:"http://webconsole.yunion.io"` + KubectlPath string `help:"kubectl binary path used to connect k8s cluster" default:"/usr/bin/kubectl"` IpmitoolPath string `help:"ipmitool binary path used to connect baremetal sol" default:"/usr/bin/ipmitool"` SshToolPath string `help:"sshtool binary path used to connect server sol" default:"/usr/bin/ssh"` SshpassToolPath string `help:"sshpass tool binary path used to connect server sol" default:"/usr/bin/sshpass"` EnableAutoLogin bool `help:"allow webconsole to log in directly with the cloudroot public key" default:"false"` } + +func OnOptionsChange(oldO, newO interface{}) bool { + oldOpts := oldO.(*WebConsoleOptions) + newOpts := newO.(*WebConsoleOptions) + + if common_options.OnCommonOptionsChange(&oldOpts.CommonOptions, &newOpts.CommonOptions) { + return true + } + + return false +} diff --git a/pkg/webconsole/service/service.go b/pkg/webconsole/service/service.go index 4893a8630e..4753442964 100644 --- a/pkg/webconsole/service/service.go +++ b/pkg/webconsole/service/service.go @@ -25,6 +25,7 @@ import ( "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/webconsole" app_common "yunion.io/x/onecloud/pkg/cloudcommon/app" common_options "yunion.io/x/onecloud/pkg/cloudcommon/options" "yunion.io/x/onecloud/pkg/webconsole" @@ -42,7 +43,7 @@ func StartService() { opts := &o.Options commonOpts := &o.Options.CommonOptions - common_options.ParseOptions(opts, os.Args, "webconsole.conf", "webconsole") + common_options.ParseOptions(opts, os.Args, "webconsole.conf", api.SERVICE_TYPE) if opts.ApiServer == "" { log.Fatalf("--api-server must specified") @@ -59,6 +60,9 @@ func StartService() { app_common.InitAuth(commonOpts, func() { log.Infof("Auth complete") }) + + common_options.StartOptionManager(opts, opts.ConfigSyncPeriodSeconds, api.SERVICE_TYPE, api.SERVICE_VERSION, o.OnOptionsChange) + start() }