From 48bc6e18e94f48963a3e619aa8842b976ad23df5 Mon Sep 17 00:00:00 2001 From: eball Date: Thu, 29 May 2025 14:58:07 +0800 Subject: [PATCH] fix: replace api terminus-info with olares-info --- config/ingress/nginx.tmpl | 2 +- pkg/apis/backend/v1/handler.go | 67 +++++++++++++++++++++++++++++++++ pkg/apis/backend/v1/model.go | 15 ++++++++ pkg/apis/backend/v1/register.go | 12 ++++++ 4 files changed, 95 insertions(+), 1 deletion(-) diff --git a/config/ingress/nginx.tmpl b/config/ingress/nginx.tmpl index 42e0971..8515d1b 100644 --- a/config/ingress/nginx.tmpl +++ b/config/ingress/nginx.tmpl @@ -466,7 +466,7 @@ http { location / { default_type text/html; - return 200 "

Bytetrade

"; + return 200 "

Olares

"; } location /ping { diff --git a/pkg/apis/backend/v1/handler.go b/pkg/apis/backend/v1/handler.go index 18468d0..6c699f7 100644 --- a/pkg/apis/backend/v1/handler.go +++ b/pkg/apis/backend/v1/handler.go @@ -317,6 +317,7 @@ func (h *Handler) handleReDownloadCert(req *restful.Request, resp *restful.Respo response.SuccessNoData(resp) } +// Deprecated: use handleOlaresInfo instead func (h *Handler) handleTerminusInfo(req *restful.Request, resp *restful.Response) { userOp, err := operator.NewUserOperator() @@ -383,6 +384,72 @@ func (h *Handler) handleTerminusInfo(req *restful.Request, resp *restful.Respons } +func (h *Handler) handleOlaresInfo(req *restful.Request, resp *restful.Response) { + + userOp, err := operator.NewUserOperator() + if err != nil { + response.HandleError(resp, errors.Errorf("olares info: new user operator err: %v", err)) + return + } + + user, err := userOp.GetUser("") + if err != nil { + response.HandleError(resp, errors.Errorf("olares info: get user err: %v", err)) + return + } + + tInfo := OlaresInfo{} + tInfo.OlaresName = userOp.GetTerminusName(user) + + status := userOp.GetTerminusStatus(user) + if status == "" { + tInfo.WizardStatus = constants.WaitActivateVault + } else { + tInfo.WizardStatus = constants.WizardStatus(status) + } + + selfhosted, terminusd, osVersion, err := userOp.SelfhostedAndOsVersion() + if err != nil { + response.HandleError(resp, errors.Errorf("olares info: get olares host type err: %v", err)) + return + } + + tInfo.Selfhosted = selfhosted + tInfo.OsVersion = osVersion + + tInfo.Olaresd = "0" + if terminusd { + tInfo.Olaresd = "1" + } + + terminusId, err := userOp.GetTerminusID() + if err != nil { + response.HandleError(resp, errors.Errorf("olares info: get olares id err: %v", err)) + return + } + + tInfo.OlaresID = terminusId + + var denyAllAnno string = userOp.GetDenyAllPolicy(user) + if denyAllAnno == "" { + tInfo.TailScaleEnable = false + } else { + denyAll, _ := strconv.Atoi(denyAllAnno) + tInfo.TailScaleEnable = denyAll == 1 + } + + tInfo.LoginBackground = userOp.GetLoginBackground(user) + tInfo.Avatar = userOp.GetAvatar(user) + tInfo.UserDID = userOp.GetUserDID(user) + + if reverseProxy := userOp.GetUserAnnotation(user, constants.UserAnnotationReverseProxyType); reverseProxy != "" { + tInfo.ReverseProxy = reverseProxy + } + + response.Success(resp, tInfo) + +} + func (h *Handler) myapps(req *restful.Request, resp *restful.Response) { // provider api var opt MyAppsProviderRequest diff --git a/pkg/apis/backend/v1/model.go b/pkg/apis/backend/v1/model.go index 5ddeba4..da22a8b 100644 --- a/pkg/apis/backend/v1/model.go +++ b/pkg/apis/backend/v1/model.go @@ -27,6 +27,7 @@ type IPAddress struct { MasterExternalIP string `json:"masterExternalIP"` } +// Depreacted type TerminusInfo struct { TerminusName string `json:"terminusName"` WizardStatus constants.WizardStatus `json:"wizardStatus"` @@ -41,6 +42,20 @@ type TerminusInfo struct { Terminusd string `json:"terminusd"` } +type OlaresInfo struct { + OlaresName string `json:"olaresName"` + WizardStatus constants.WizardStatus `json:"wizardStatus"` + Selfhosted bool `json:"selfhosted"` + TailScaleEnable bool `json:"tailScaleEnable"` + OsVersion string `json:"osVersion"` + LoginBackground string `json:"loginBackground"` + Avatar string `json:"avatar"` + OlaresID string `json:"olaresId"` + UserDID string `json:"did"` + ReverseProxy string `json:"reverseProxy"` + Olaresd string `json:"olaresd"` +} + type MyAppsParam struct { IsLocal bool `json:"isLocal"` } diff --git a/pkg/apis/backend/v1/register.go b/pkg/apis/backend/v1/register.go index cb9da62..91dfad8 100644 --- a/pkg/apis/backend/v1/register.go +++ b/pkg/apis/backend/v1/register.go @@ -43,6 +43,12 @@ func AddContainer(c *restful.Container) error { Metadata(restfulspec.KeyOpenAPITags, tags). Returns(http.StatusOK, "", response.Response{})) + ws.Route(ws.GET("/olares-info"). + To(handler.handleOlaresInfo). + Doc("olares information."). + Metadata(restfulspec.KeyOpenAPITags, tags). + Returns(http.StatusOK, "", response.Response{})) + ws.Route(ws.GET("/ip"). To(handler.handleGetIPAddress). Doc("IP Address."). @@ -87,6 +93,12 @@ func AddContainer(c *restful.Container) error { Metadata(restfulspec.KeyOpenAPITags, tags). Returns(http.StatusOK, "", response.Response{})) + wsWizard.Route(wsWizard.GET("/olares-info"). + To(handler.handleOlaresInfo). + Doc("olares information."). + Metadata(restfulspec.KeyOpenAPITags, tags). + Returns(http.StatusOK, "", response.Response{})) + c.Add(wsWizard) return nil }