diff --git a/api/v2.0/swagger.yaml b/api/v2.0/swagger.yaml index a032b4256..d15e4f06a 100644 --- a/api/v2.0/swagger.yaml +++ b/api/v2.0/swagger.yaml @@ -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 diff --git a/src/controller/systeminfo/controller.go b/src/controller/systeminfo/controller.go index d6309728e..42fd556a4 100644 --- a/src/controller/systeminfo/controller.go +++ b/src/controller/systeminfo/controller.go @@ -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), diff --git a/src/controller/systeminfo/controller_test.go b/src/controller/systeminfo/controller_test.go index 4bf2105c5..4a8ab186f 100644 --- a/src/controller/systeminfo/controller_test.go +++ b/src/controller/systeminfo/controller_test.go @@ -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 diff --git a/src/server/v2.0/handler/systeminfo.go b/src/server/v2.0/handler/systeminfo.go index e29afc5dd..07330df0c 100644 --- a/src/server/v2.0/handler/systeminfo.go +++ b/src/server/v2.0/handler/systeminfo.go @@ -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