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:
|
GeneralInfo:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
current_time:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
x-nullable: true
|
||||||
|
x-omitempty: true
|
||||||
|
description: The current time of the server.
|
||||||
with_notary:
|
with_notary:
|
||||||
type: boolean
|
type: boolean
|
||||||
x-nullable: true
|
x-nullable: true
|
||||||
|
@ -17,14 +17,15 @@ package systeminfo
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/lib/config"
|
|
||||||
"github.com/goharbor/harbor/src/lib/config/models"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"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/errors"
|
||||||
"github.com/goharbor/harbor/src/lib/log"
|
"github.com/goharbor/harbor/src/lib/log"
|
||||||
"github.com/goharbor/harbor/src/pkg/systeminfo"
|
"github.com/goharbor/harbor/src/pkg/systeminfo"
|
||||||
@ -50,6 +51,7 @@ type Data struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type protectedData struct {
|
type protectedData struct {
|
||||||
|
CurrentTime time.Time
|
||||||
WithNotary bool
|
WithNotary bool
|
||||||
RegistryURL string
|
RegistryURL string
|
||||||
ExtURL string
|
ExtURL string
|
||||||
@ -115,6 +117,7 @@ func (c *controller) GetInfo(ctx context.Context, opt Options) (*Data, error) {
|
|||||||
_, caStatErr := os.Stat(defaultRootCert)
|
_, caStatErr := os.Stat(defaultRootCert)
|
||||||
enableCADownload := caStatErr == nil && strings.HasPrefix(extURL, "https://")
|
enableCADownload := caStatErr == nil && strings.HasPrefix(extURL, "https://")
|
||||||
res.Protected = &protectedData{
|
res.Protected = &protectedData{
|
||||||
|
CurrentTime: time.Now(),
|
||||||
WithNotary: config.WithNotary(),
|
WithNotary: config.WithNotary(),
|
||||||
WithChartMuseum: config.WithChartMuseum(),
|
WithChartMuseum: config.WithChartMuseum(),
|
||||||
ReadOnly: config.ReadOnly(ctx),
|
ReadOnly: config.ReadOnly(ctx),
|
||||||
|
@ -92,6 +92,8 @@ func (s *sysInfoCtlTestSuite) TestGetInfo() {
|
|||||||
assert.Nil(res.Protected)
|
assert.Nil(res.Protected)
|
||||||
assert.Equal(exp, *res)
|
assert.Equal(exp, *res)
|
||||||
} else {
|
} else {
|
||||||
|
// skip comparing exp.Protected.CurrentTime with res.Protected.CurrentTime
|
||||||
|
exp.Protected.CurrentTime = res.Protected.CurrentTime
|
||||||
assert.Equal(*exp.Protected, *res.Protected)
|
assert.Equal(*exp.Protected, *res.Protected)
|
||||||
exp.Protected = nil
|
exp.Protected = nil
|
||||||
res.Protected = nil
|
res.Protected = nil
|
||||||
|
@ -2,9 +2,10 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/goharbor/harbor/src/common/rbac"
|
|
||||||
|
|
||||||
"github.com/go-openapi/runtime/middleware"
|
"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"
|
"github.com/goharbor/harbor/src/common/security"
|
||||||
si "github.com/goharbor/harbor/src/controller/systeminfo"
|
si "github.com/goharbor/harbor/src/controller/systeminfo"
|
||||||
"github.com/goharbor/harbor/src/server/v2.0/models"
|
"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.ReadOnly = &d.Protected.ReadOnly
|
||||||
res.RegistryStorageProviderName = &d.Protected.RegistryStorageProviderName
|
res.RegistryStorageProviderName = &d.Protected.RegistryStorageProviderName
|
||||||
res.NotificationEnable = &d.Protected.NotificationEnable
|
res.NotificationEnable = &d.Protected.NotificationEnable
|
||||||
|
currentTime := strfmt.DateTime(d.Protected.CurrentTime)
|
||||||
|
res.CurrentTime = ¤tTime
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user