From dd3113f8a554dca7d93ed0a35d99a1843765eaaf Mon Sep 17 00:00:00 2001 From: ifooth Date: Tue, 2 Jul 2024 17:47:17 +0800 Subject: [PATCH] feat: add BKSharedResBaseJSURL conf --- bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml | 2 +- bcs-services/bcs-bscp/cmd/ui/service/web.go | 2 +- bcs-services/bcs-bscp/pkg/config/config.go | 2 +- bcs-services/bcs-bscp/pkg/config/frontend.go | 34 +++++++++++++++++--- bcs-services/bcs-bscp/pkg/config/web.go | 29 +++-------------- 5 files changed, 37 insertions(+), 32 deletions(-) diff --git a/bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml b/bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml index 14d1de2e6b..796bfa66bf 100644 --- a/bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml +++ b/bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml @@ -10,7 +10,6 @@ web: host: "" route_prefix: "" preferred_domains: "" - bk_shared_res_url: "" etcd: endpoints: 127.0.0.1:2379 ca: "" @@ -23,5 +22,6 @@ frontend_conf: bk_cmdb_host: "" bscp_api_url: "" bk_nodeman_host: "" + bk_shared_res_url: "" helper: "" enable_bk_notice: false diff --git a/bcs-services/bcs-bscp/cmd/ui/service/web.go b/bcs-services/bcs-bscp/cmd/ui/service/web.go index 46d3120e36..c4fbeba375 100644 --- a/bcs-services/bcs-bscp/cmd/ui/service/web.go +++ b/bcs-services/bcs-bscp/cmd/ui/service/web.go @@ -179,10 +179,10 @@ func (s *WebServer) subRouter() http.Handler { RunEnv: config.G.Base.RunEnv, ProxyAPI: shouldProxyAPI, SiteURL: config.G.Web.RoutePrefix, - BKSharedResBaseJSURL: config.G.Web.BKSharedResBaseJSURL, APIURL: config.G.Frontend.Host.BSCPAPIURL, IAMHost: config.G.Frontend.Host.BKIAMHost, CMDBHost: config.G.Frontend.Host.BKCMDBHost, + BKSharedResBaseJSURL: config.G.Frontend.Host.BKSharedResBaseJSURL, EnableBKNotice: config.G.Frontend.EnableBKNotice, Helper: config.G.Frontend.Helper, FeedAddr: config.G.Base.FeedAddr, diff --git a/bcs-services/bcs-bscp/pkg/config/config.go b/bcs-services/bcs-bscp/pkg/config/config.go index b59907af79..b1da5d64ca 100644 --- a/bcs-services/bcs-bscp/pkg/config/config.go +++ b/bcs-services/bcs-bscp/pkg/config/config.go @@ -41,7 +41,7 @@ func (c *Configuration) init() error { if err := c.Web.init(); err != nil { return err } - if err := c.Web.initResBaseJSURL(c.Base.AppCode); err != nil { + if err := c.Frontend.initResBaseJSURL(c.Base.AppCode); err != nil { return err } diff --git a/bcs-services/bcs-bscp/pkg/config/frontend.go b/bcs-services/bcs-bscp/pkg/config/frontend.go index ab0961b733..ef27143f7c 100644 --- a/bcs-services/bcs-bscp/pkg/config/frontend.go +++ b/bcs-services/bcs-bscp/pkg/config/frontend.go @@ -13,12 +13,20 @@ // Package config xxx package config +import ( + "fmt" + "net/url" + "path" +) + // HostConf host conf type HostConf struct { - BKIAMHost string `yaml:"bk_iam_host"` // 权限中心 - BKCMDBHost string `yaml:"bk_cmdb_host"` // 配置平台 - BSCPAPIURL string `yaml:"bscp_api_url"` // bscp api地址 - BKNODEMANHOST string `yaml:"bk_nodeman_host"` // 节点管理地址 + BKIAMHost string `yaml:"bk_iam_host"` // 权限中心 + BKCMDBHost string `yaml:"bk_cmdb_host"` // 配置平台 + BSCPAPIURL string `yaml:"bscp_api_url"` // bscp api地址 + BKNODEMANHOST string `yaml:"bk_nodeman_host"` // 节点管理地址 + BKSharedResURL string `yaml:"bk_shared_res_url"` // 对应运维公共变量bkSharedResUrl, PaaS环境变量BKPAAS_SHARED_RES_URL + BKSharedResBaseJSURL string `yaml:"-"` // 规则是${bkSharedResUrl}/${目录名 aks app_code}/base.js } // FrontendConf docs and host conf @@ -37,3 +45,21 @@ func defaultUIConf() *FrontendConf { } return c } + +func (c *FrontendConf) initResBaseJSURL(appCode string) error { + if c.Host.BKSharedResURL == "" { + return nil + } + if appCode == "" { + return fmt.Errorf("initResBaseJSURL: app_code is required") + } + + u, err := url.Parse(c.Host.BKSharedResURL) + if err != nil { + return err + } + u.Path = path.Join(u.Path, appCode, "base.js") + + c.Host.BKSharedResBaseJSURL = u.String() + return nil +} diff --git a/bcs-services/bcs-bscp/pkg/config/web.go b/bcs-services/bcs-bscp/pkg/config/web.go index bd436c668b..c6481494a2 100644 --- a/bcs-services/bcs-bscp/pkg/config/web.go +++ b/bcs-services/bcs-bscp/pkg/config/web.go @@ -13,19 +13,16 @@ package config import ( - "fmt" "net/url" "path" ) // WebConf web 相关配置 type WebConf struct { - Host string `yaml:"host"` - RoutePrefix string `yaml:"route_prefix"` // vue路由, 静态资源前缀 - PreferredDomains string `yaml:"preferred_domains"` - BaseURL *url.URL `yaml:"-"` - BKSharedResURL string `yaml:"bk_shared_res_url"` // 对应运维公共变量bkSharedResUrl, PaaS环境变量BKPAAS_SHARED_RES_URL - BKSharedResBaseJSURL string `yaml:"-"` // 规则是${bkSharedResUrl}/${目录名 aks app_code}/base.js + Host string `yaml:"host"` + RoutePrefix string `yaml:"route_prefix"` // vue路由, 静态资源前缀 + PreferredDomains string `yaml:"preferred_domains"` + BaseURL *url.URL `yaml:"-"` } // init 初始化 @@ -40,24 +37,6 @@ func (c *WebConf) init() error { return nil } -func (c *WebConf) initResBaseJSURL(appCode string) error { - if c.BKSharedResURL == "" { - return nil - } - if appCode == "" { - return fmt.Errorf("initResBaseJSURL: app_code is required") - } - - u, err := url.Parse(c.BKSharedResURL) - if err != nil { - return err - } - u.Path = path.Join(u.Path, appCode, "base.js") - - c.BKSharedResBaseJSURL = u.String() - return nil -} - // defaultWebConf 默认配置 func defaultWebConf() *WebConf { c := &WebConf{