fix: display expire time.
Some checks failed
Coverage CI / build (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
Ubuntu CI / build (push) Has been cancelled

This commit is contained in:
Daniel Ding
2025-09-23 19:38:29 +08:00
parent 6a6d0893d7
commit d8140ddf08
4 changed files with 32 additions and 4 deletions

View File

@@ -15,8 +15,9 @@ func (v Version) Url(prefix, name string) string {
} }
func (v Version) Tmpl() string { func (v Version) Tmpl() string {
return `Version : {{ .Version }} return `Version : {{ .Version }}
Build at: {{ .Date}} Build at : {{ .Date}}
Expire at: {{ .Expire }}
` `
} }

View File

@@ -1,9 +1,11 @@
package api package api
import ( import (
"github.com/gorilla/mux"
"github.com/luscis/openlan/pkg/schema"
"net/http" "net/http"
"github.com/gorilla/mux"
"github.com/luscis/openlan/pkg/cache"
"github.com/luscis/openlan/pkg/schema"
) )
type Version struct { type Version struct {
@@ -15,5 +17,6 @@ func (l Version) Router(router *mux.Router) {
func (l Version) List(w http.ResponseWriter, r *http.Request) { func (l Version) List(w http.ResponseWriter, r *http.Request) {
ver := schema.NewVersionSchema() ver := schema.NewVersionSchema()
ver.Expire = cache.User.ExpireTime()
ResponseJson(w, ver) ResponseJson(w, ver)
} }

23
pkg/cache/user.go vendored
View File

@@ -246,6 +246,29 @@ func (w *user) SetCert(cfg *libol.CertConfig) {
w.Cert = cfg.Crt w.Cert = cfg.Crt
} }
func (w *user) ExpireTime() string {
if w.Cert == "" {
return ""
}
pemData, err := os.ReadFile(w.Cert)
if err != nil {
return ""
}
block, rest := pem.Decode(pemData)
if block == nil || len(rest) > 0 {
return ""
}
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return ""
}
return cert.NotAfter.Format(time.RFC3339)
}
var User = user{ var User = user{
Users: libol.NewSafeStrMap(1024), Users: libol.NewSafeStrMap(1024),
} }

View File

@@ -5,6 +5,7 @@ import "github.com/luscis/openlan/pkg/libol"
type Version struct { type Version struct {
Version string `json:"version"` Version string `json:"version"`
Date string `json:"date"` Date string `json:"date"`
Expire string `json:"expire"`
} }
func NewVersionSchema() Version { func NewVersionSchema() Version {