mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-25 01:58:35 +01:00
dcf4e2ee78
vmware -> goharbor Signed-off-by: Daniel Jiang <jiangd@vmware.com>
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package lib
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/goharbor/harbor/tests/apitests/api-testing/client"
|
|
"github.com/goharbor/harbor/tests/apitests/api-testing/models"
|
|
)
|
|
|
|
//SystemUtil : For getting system info
|
|
type SystemUtil struct {
|
|
rootURI string
|
|
hostname string
|
|
testingClient *client.APIClient
|
|
}
|
|
|
|
//NewSystemUtil : Constructor
|
|
func NewSystemUtil(rootURI, hostname string, httpClient *client.APIClient) *SystemUtil {
|
|
if len(strings.TrimSpace(rootURI)) == 0 || httpClient == nil {
|
|
return nil
|
|
}
|
|
|
|
return &SystemUtil{
|
|
rootURI: rootURI,
|
|
hostname: hostname,
|
|
testingClient: httpClient,
|
|
}
|
|
}
|
|
|
|
//GetSystemInfo : Get systeminfo
|
|
func (nsu *SystemUtil) GetSystemInfo() error {
|
|
url := nsu.rootURI + "/api/systeminfo"
|
|
data, err := nsu.testingClient.Get(url)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var info models.SystemInfo
|
|
if err := json.Unmarshal(data, &info); err != nil {
|
|
return err
|
|
}
|
|
|
|
if info.RegistryURL != nsu.hostname {
|
|
return fmt.Errorf("Invalid registry url in system info: expect %s got %s ", nsu.hostname, info.RegistryURL)
|
|
}
|
|
|
|
return nil
|
|
}
|