systeminfo returns flag for ca root

This commit is contained in:
Tan Jiang 2017-03-16 16:53:40 +08:00
parent 9d87279152
commit 5e229f7d96
3 changed files with 15 additions and 5 deletions

View File

@ -2025,6 +2025,9 @@ definitions:
self_registration: self_registration:
type: boolean type: boolean
description: Indicate whether the Harbor instance enable user to register himself. description: Indicate whether the Harbor instance enable user to register himself.
has_ca_root:
type: boolean
description: Indicate whether there is a ca root cert file ready for download in the file system.
SystemInfo: SystemInfo:
type: object type: object
properties: properties:
@ -2098,7 +2101,7 @@ definitions:
type: string type: string
description: The host of email server. description: The host of email server.
email_port: email_port:
type: string type: integer
description: The port of email server. description: The port of email server.
email_username: email_username:
type: string type: string
@ -2107,7 +2110,7 @@ definitions:
type: string type: string
description: The password of email server. description: The password of email server.
email_ssl: email_ssl:
type: string type: boolean
description: Use ssl/tls or not. description: Use ssl/tls or not.
email_identity: email_identity:
type: string type: string

View File

@ -44,6 +44,7 @@ type GeneralInfo struct {
RegistryURL string `json:"registry_url"` RegistryURL string `json:"registry_url"`
ProjectCreationRestrict string `json:"project_creation_restriction"` ProjectCreationRestrict string `json:"project_creation_restriction"`
SelfRegistration bool `json:"self_registration"` SelfRegistration bool `json:"self_registration"`
HasCARoot bool `json:"has_ca_root"`
} }
// validate for validating user if an admin. // validate for validating user if an admin.
@ -88,13 +89,16 @@ func (sia *SystemInfoAPI) GetVolumeInfo() {
func (sia *SystemInfoAPI) GetCert() { func (sia *SystemInfoAPI) GetCert() {
sia.validate() sia.validate()
if sia.isAdmin { if sia.isAdmin {
if _, err := os.Stat(defaultRootCert); !os.IsNotExist(err) { if _, err := os.Stat(defaultRootCert); err == nil {
sia.Ctx.Output.Header("Content-Type", "application/octet-stream") sia.Ctx.Output.Header("Content-Type", "application/octet-stream")
sia.Ctx.Output.Header("Content-Disposition", "attachment; filename=ca.crt") sia.Ctx.Output.Header("Content-Disposition", "attachment; filename=ca.crt")
http.ServeFile(sia.Ctx.ResponseWriter, sia.Ctx.Request, defaultRootCert) http.ServeFile(sia.Ctx.ResponseWriter, sia.Ctx.Request, defaultRootCert)
} else { } else if os.IsNotExist(err) {
log.Error("No certificate found.") log.Error("No certificate found.")
sia.CustomAbort(http.StatusNotFound, "No certificate found.") sia.CustomAbort(http.StatusNotFound, "No certificate found.")
} else {
log.Errorf("Unexpected error: %v", err)
sia.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
} }
} }
sia.CustomAbort(http.StatusForbidden, "") sia.CustomAbort(http.StatusForbidden, "")
@ -113,6 +117,7 @@ func (sia *SystemInfoAPI) GetGeneralInfo() {
} else { } else {
registryURL = l[0] registryURL = l[0]
} }
_, caStatErr := os.Stat(defaultRootCert)
info := GeneralInfo{ info := GeneralInfo{
AdmiralEndpoint: cfg[comcfg.AdmiralEndpoint].(string), AdmiralEndpoint: cfg[comcfg.AdmiralEndpoint].(string),
WithAdmiral: config.WithAdmiral(), WithAdmiral: config.WithAdmiral(),
@ -121,6 +126,7 @@ func (sia *SystemInfoAPI) GetGeneralInfo() {
ProjectCreationRestrict: cfg[comcfg.ProjectCreationRestriction].(string), ProjectCreationRestrict: cfg[comcfg.ProjectCreationRestriction].(string),
SelfRegistration: cfg[comcfg.SelfRegistration].(bool), SelfRegistration: cfg[comcfg.SelfRegistration].(bool),
RegistryURL: registryURL, RegistryURL: registryURL,
HasCARoot: caStatErr == nil,
} }
sia.Data["json"] = info sia.Data["json"] = info
sia.ServeJSON() sia.ServeJSON()

View File

@ -48,6 +48,7 @@ func TestGetGeneralInfo(t *testing.T) {
err = json.Unmarshal(body, g) err = json.Unmarshal(body, g)
assert.Nil(err, fmt.Sprintf("Unexpected Error: %v", err)) assert.Nil(err, fmt.Sprintf("Unexpected Error: %v", err))
assert.Equal(false, g.WithNotary, "with notary should be false") assert.Equal(false, g.WithNotary, "with notary should be false")
assert.Equal(true, g.HasCARoot, "has ca root should be true")
} }
func TestGetCert(t *testing.T) { func TestGetCert(t *testing.T) {