diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 42202f4a5..48a3cb0fb 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -2150,6 +2150,9 @@ definitions: with_notary: type: boolean description: If the Harbor instance is deployed with nested notary. + with_clair: + type: boolean + description: If the Harbor instance is deployed with nested clair. with_admiral: type: boolean description: If the Harbor instance is deployed with Admiral. diff --git a/make/common/templates/adminserver/env b/make/common/templates/adminserver/env index 190acac5a..c74e30056 100644 --- a/make/common/templates/adminserver/env +++ b/make/common/templates/adminserver/env @@ -36,4 +36,5 @@ CFG_EXPIRATION=5 GODEBUG=netdns=cgo ADMIRAL_URL=$admiral_url WITH_NOTARY=$with_notary +WITH_CLAIR=$with_clair RESET=false diff --git a/make/prepare b/make/prepare index ce75eba5d..55144b897 100755 --- a/make/prepare +++ b/make/prepare @@ -225,7 +225,7 @@ render(os.path.join(templates_dir, "adminserver", "env"), token_expiration=token_expiration, admiral_url=admiral_url, with_notary=args.notary_mode, - scanner=args.clair_mode and "clair" or "none" + with_clair=args.clair_mode ) render(os.path.join(templates_dir, "ui", "env"), diff --git a/src/adminserver/systemcfg/systemcfg.go b/src/adminserver/systemcfg/systemcfg.go index ca63d5848..07f3d0bdb 100644 --- a/src/adminserver/systemcfg/systemcfg.go +++ b/src/adminserver/systemcfg/systemcfg.go @@ -116,6 +116,10 @@ var ( env: "WITH_NOTARY", parse: parseStringToBool, }, + common.WithClair: &parser{ + env: "WITH_CLAIR", + parse: parseStringToBool, + }, } // configurations need read from environment variables @@ -136,6 +140,10 @@ var ( env: "WITH_NOTARY", parse: parseStringToBool, }, + common.WithClair: &parser{ + env: "WITH_CLAIR", + parse: parseStringToBool, + }, } ) diff --git a/src/common/const.go b/src/common/const.go index 1c4282946..ca3bf1a26 100644 --- a/src/common/const.go +++ b/src/common/const.go @@ -64,4 +64,5 @@ const ( AdminInitialPassword = "admin_initial_password" AdmiralEndpoint = "admiral_url" WithNotary = "with_notary" + WithClair = "with_clair" ) diff --git a/src/common/utils/test/adminserver.go b/src/common/utils/test/adminserver.go index 39db32de5..862fdd653 100644 --- a/src/common/utils/test/adminserver.go +++ b/src/common/utils/test/adminserver.go @@ -59,6 +59,7 @@ var adminServerDefaultConfig = map[string]interface{}{ common.AdminInitialPassword: "password", common.AdmiralEndpoint: "http://www.vmware.com", common.WithNotary: false, + common.WithClair: false, } // NewAdminserver returns a mock admin server diff --git a/src/ui/api/systeminfo.go b/src/ui/api/systeminfo.go index 149759f67..0d161ffcb 100644 --- a/src/ui/api/systeminfo.go +++ b/src/ui/api/systeminfo.go @@ -47,6 +47,7 @@ type Storage struct { //GeneralInfo wraps common systeminfo for anonymous request type GeneralInfo struct { WithNotary bool `json:"with_notary"` + WithClair bool `json:"with_clair"` WithAdmiral bool `json:"with_admiral"` AdmiralEndpoint string `json:"admiral_endpoint"` AuthMode string `json:"auth_mode"` @@ -125,6 +126,7 @@ func (sia *SystemInfoAPI) GetGeneralInfo() { AdmiralEndpoint: cfg[common.AdmiralEndpoint].(string), WithAdmiral: config.WithAdmiral(), WithNotary: config.WithNotary(), + WithClair: config.WithClair(), AuthMode: cfg[common.AUTHMode].(string), ProjectCreationRestrict: cfg[common.ProjectCreationRestriction].(string), SelfRegistration: cfg[common.SelfRegistration].(bool), diff --git a/src/ui/config/config.go b/src/ui/config/config.go index 206e3fcc6..b8ebce6c7 100644 --- a/src/ui/config/config.go +++ b/src/ui/config/config.go @@ -313,6 +313,16 @@ func WithNotary() bool { return cfg[common.WithNotary].(bool) } +// WithClair returns a bool value to indicate if Harbor's deployed with Clair +func WithClair() bool { + cfg, err := mg.Get() + if err != nil { + log.Errorf("Failed to get configuration, will return WithClair == false") + return false + } + return cfg[common.WithClair].(bool) +} + // AdmiralEndpoint returns the URL of admiral, if Harbor is not deployed with admiral it should return an empty string. func AdmiralEndpoint() string { cfg, err := mg.Get() diff --git a/src/ui/config/config_test.go b/src/ui/config/config_test.go index a702c0f33..c7655a75e 100644 --- a/src/ui/config/config_test.go +++ b/src/ui/config/config_test.go @@ -125,6 +125,9 @@ func TestConfig(t *testing.T) { if WithNotary() { t.Errorf("Withnotary should be false") } + if WithClair() { + t.Errorf("WithClair should be false") + } if !WithAdmiral() { t.Errorf("WithAdmiral should be true") }