Merge pull request #16205 from zyyw/current_time_systeminfo

feat: add current_time to the response of systeminfo api when user logged in
This commit is contained in:
Shengwen YU 2022-01-12 18:35:38 +08:00 committed by GitHub
commit 61a0d41532
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 3 deletions

View File

@ -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

View File

@ -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),

View File

@ -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

View File

@ -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 = &currentTime
}
return res