mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-10 12:40:19 +01:00
feat: add current_time to the response of systeminfo api when user logged in
Signed-off-by: Shengwen Yu <yshengwen@vmware.com>
This commit is contained in:
parent
634f0139a0
commit
b7af0f1529
@ -7091,6 +7091,12 @@ definitions:
|
||||
GeneralInfo:
|
||||
type: object
|
||||
properties:
|
||||
current_time:
|
||||
type: string
|
||||
format: date-time
|
||||
x-nullable: true
|
||||
x-omitempty: true
|
||||
description: The current time of the server.
|
||||
with_notary:
|
||||
type: boolean
|
||||
x-nullable: true
|
||||
|
@ -17,14 +17,15 @@ package systeminfo
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/goharbor/harbor/src/lib/config"
|
||||
"github.com/goharbor/harbor/src/lib/config/models"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/goharbor/harbor/src/common"
|
||||
"github.com/goharbor/harbor/src/common/utils"
|
||||
"github.com/goharbor/harbor/src/lib/config"
|
||||
"github.com/goharbor/harbor/src/lib/config/models"
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/lib/log"
|
||||
"github.com/goharbor/harbor/src/pkg/systeminfo"
|
||||
@ -50,6 +51,7 @@ type Data struct {
|
||||
}
|
||||
|
||||
type protectedData struct {
|
||||
CurrentTime time.Time
|
||||
WithNotary bool
|
||||
RegistryURL string
|
||||
ExtURL string
|
||||
@ -115,6 +117,7 @@ func (c *controller) GetInfo(ctx context.Context, opt Options) (*Data, error) {
|
||||
_, caStatErr := os.Stat(defaultRootCert)
|
||||
enableCADownload := caStatErr == nil && strings.HasPrefix(extURL, "https://")
|
||||
res.Protected = &protectedData{
|
||||
CurrentTime: time.Now(),
|
||||
WithNotary: config.WithNotary(),
|
||||
WithChartMuseum: config.WithChartMuseum(),
|
||||
ReadOnly: config.ReadOnly(ctx),
|
||||
|
@ -92,6 +92,8 @@ func (s *sysInfoCtlTestSuite) TestGetInfo() {
|
||||
assert.Nil(res.Protected)
|
||||
assert.Equal(exp, *res)
|
||||
} else {
|
||||
// skip comparing exp.Protected.CurrentTime with res.Protected.CurrentTime
|
||||
exp.Protected.CurrentTime = res.Protected.CurrentTime
|
||||
assert.Equal(*exp.Protected, *res.Protected)
|
||||
exp.Protected = nil
|
||||
res.Protected = nil
|
||||
|
@ -2,9 +2,10 @@ package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/goharbor/harbor/src/common/rbac"
|
||||
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/goharbor/harbor/src/common/rbac"
|
||||
"github.com/goharbor/harbor/src/common/security"
|
||||
si "github.com/goharbor/harbor/src/controller/systeminfo"
|
||||
"github.com/goharbor/harbor/src/server/v2.0/models"
|
||||
@ -90,6 +91,8 @@ func (s *sysInfoAPI) convertInfo(d *si.Data) *models.GeneralInfo {
|
||||
res.ReadOnly = &d.Protected.ReadOnly
|
||||
res.RegistryStorageProviderName = &d.Protected.RegistryStorageProviderName
|
||||
res.NotificationEnable = &d.Protected.NotificationEnable
|
||||
currentTime := strfmt.DateTime(d.Protected.CurrentTime)
|
||||
res.CurrentTime = ¤tTime
|
||||
}
|
||||
return res
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user