mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-22 08:38:03 +01:00
refactor: remove initialization of clair db
To fetch vulnerability database updated time of the Clair had moved to the Clair adapter so removes the initialization of clair db in the core. Signed-off-by: He Weiwei <hweiwei@vmware.com>
This commit is contained in:
parent
3b2934bf48
commit
039aef5356
@ -26,12 +26,6 @@ JOBSERVICE_SECRET={{jobservice_secret}}
|
||||
WITH_NOTARY={{with_notary}}
|
||||
WITH_CLAIR={{with_clair}}
|
||||
WITH_TRIVY={{with_trivy}}
|
||||
CLAIR_DB_PASSWORD={{clair_db_password}}
|
||||
CLAIR_DB_HOST={{clair_db_host}}
|
||||
CLAIR_DB_PORT={{clair_db_port}}
|
||||
CLAIR_DB_USERNAME={{clair_db_username}}
|
||||
CLAIR_DB={{clair_db_name}}
|
||||
CLAIR_DB_SSLMODE={{clair_db_sslmode}}
|
||||
CORE_URL={{core_url}}
|
||||
CORE_LOCAL_URL={{core_local_url}}
|
||||
JOBSERVICE_URL={{jobservice_url}}
|
||||
|
@ -1,3 +1,17 @@
|
||||
// Copyright Project Harbor Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
@ -76,14 +90,13 @@ func TestCfgManager_loadDefaultValues(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCfgManger_loadSystemValues(t *testing.T) {
|
||||
// os.Setenv("CLAIR_DB", "mysql")
|
||||
configManager.loadDefault()
|
||||
configManager.loadSystemConfigFromEnv()
|
||||
configManager.UpdateConfig(map[string]interface{}{
|
||||
"clair_db": "mysql",
|
||||
"postgresql_host": "127.0.0.1",
|
||||
})
|
||||
if configManager.Get("clair_db").GetString() != "mysql" {
|
||||
t.Errorf("Failed to set system value clair_db, expected %v, actual %v", "mysql", configManager.Get("clair_db").GetString())
|
||||
if configManager.Get("postgresql_host").GetString() != "127.0.0.1" {
|
||||
t.Errorf("Failed to set system value postgresql_host, expected %v, actual %v", "127.0.0.1", configManager.Get("postgresql_host").GetString())
|
||||
}
|
||||
}
|
||||
func TestCfgManager_GetDatabaseCfg(t *testing.T) {
|
||||
|
@ -65,12 +65,6 @@ var (
|
||||
{Name: common.AUTHMode, Scope: UserScope, Group: BasicGroup, EnvKey: "AUTH_MODE", DefaultValue: "db_auth", ItemType: &AuthModeType{}, Editable: false},
|
||||
{Name: common.ChartRepoURL, Scope: SystemScope, Group: BasicGroup, EnvKey: "CHART_REPOSITORY_URL", DefaultValue: "http://chartmuseum:9999", ItemType: &StringType{}, Editable: false},
|
||||
|
||||
{Name: common.ClairDB, Scope: SystemScope, Group: ClairGroup, EnvKey: "CLAIR_DB", DefaultValue: "postgres", ItemType: &StringType{}, Editable: false},
|
||||
{Name: common.ClairDBHost, Scope: SystemScope, Group: ClairGroup, EnvKey: "CLAIR_DB_HOST", DefaultValue: "postgresql", ItemType: &StringType{}, Editable: false},
|
||||
{Name: common.ClairDBPassword, Scope: SystemScope, Group: ClairGroup, EnvKey: "CLAIR_DB_PASSWORD", DefaultValue: "root123", ItemType: &PasswordType{}, Editable: false},
|
||||
{Name: common.ClairDBPort, Scope: SystemScope, Group: ClairGroup, EnvKey: "CLAIR_DB_PORT", DefaultValue: "5432", ItemType: &PortType{}, Editable: false},
|
||||
{Name: common.ClairDBSSLMode, Scope: SystemScope, Group: ClairGroup, EnvKey: "CLAIR_DB_SSLMODE", DefaultValue: "disable", ItemType: &StringType{}, Editable: false},
|
||||
{Name: common.ClairDBUsername, Scope: SystemScope, Group: ClairGroup, EnvKey: "CLAIR_DB_USERNAME", DefaultValue: "postgres", ItemType: &StringType{}, Editable: false},
|
||||
{Name: common.ClairAdapterURL, Scope: SystemScope, Group: ClairGroup, EnvKey: "CLAIR_ADAPTER_URL", DefaultValue: "http://clair-adapter:8080", ItemType: &StringType{}, Editable: false},
|
||||
{Name: common.TrivyAdapterURL, Scope: SystemScope, Group: ClairGroup, EnvKey: "TRIVY_ADAPTER_URL", DefaultValue: "http://trivy-adapter:8080", ItemType: &StringType{}, Editable: false},
|
||||
|
||||
|
@ -91,12 +91,6 @@ const (
|
||||
WithClair = "with_clair"
|
||||
WithTrivy = "with_trivy"
|
||||
ScanAllPolicy = "scan_all_policy"
|
||||
ClairDBPassword = "clair_db_password"
|
||||
ClairDBHost = "clair_db_host"
|
||||
ClairDBPort = "clair_db_port"
|
||||
ClairDB = "clair_db"
|
||||
ClairDBUsername = "clair_db_username"
|
||||
ClairDBSSLMode = "clair_db_sslmode"
|
||||
UAAEndpoint = "uaa_endpoint"
|
||||
UAAClientID = "uaa_client_id"
|
||||
UAAClientSecret = "uaa_client_secret"
|
||||
@ -114,7 +108,6 @@ const (
|
||||
OIDCGroupsClaim = "oidc_groups_claim"
|
||||
OIDCScope = "oidc_scope"
|
||||
|
||||
DefaultClairEndpoint = "http://clair:6060"
|
||||
CfgDriverDB = "db"
|
||||
NewHarborAdminName = "admin@harbor.local"
|
||||
RegistryStorageProviderName = "registry_storage_provider_name"
|
||||
|
@ -29,8 +29,6 @@ import (
|
||||
const (
|
||||
// NonExistUserID : if a user does not exist, the ID of the user will be 0.
|
||||
NonExistUserID = 0
|
||||
// ClairDBAlias ...
|
||||
ClairDBAlias = "clair-db"
|
||||
)
|
||||
|
||||
// ErrDupRows is returned by DAO when inserting failed with error "duplicate key value violates unique constraint"
|
||||
@ -48,23 +46,6 @@ type Database interface {
|
||||
UpgradeSchema() error
|
||||
}
|
||||
|
||||
// InitClairDB ...
|
||||
func InitClairDB(clairDB *models.PostGreSQL) error {
|
||||
p := &pgsql{
|
||||
host: clairDB.Host,
|
||||
port: strconv.Itoa(clairDB.Port),
|
||||
usr: clairDB.Username,
|
||||
pwd: clairDB.Password,
|
||||
database: clairDB.Database,
|
||||
sslmode: clairDB.SSLMode,
|
||||
}
|
||||
if err := p.Register(ClairDBAlias); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Info("initialized clair database")
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpgradeSchema will call the internal migrator to upgrade schema based on the setting of database.
|
||||
func UpgradeSchema(database *models.Database) error {
|
||||
db, err := getDatabase(database)
|
||||
|
@ -56,11 +56,6 @@ var defaultConfig = map[string]interface{}{
|
||||
common.AdminInitialPassword: "password",
|
||||
common.WithNotary: false,
|
||||
common.WithClair: false,
|
||||
common.ClairDBUsername: "postgres",
|
||||
common.ClairDBHost: "postgresql",
|
||||
common.ClairDB: "postgres",
|
||||
common.ClairDBPort: 5432,
|
||||
common.ClairDBPassword: "root123",
|
||||
common.UAAClientID: "testid",
|
||||
common.UAAClientSecret: "testsecret",
|
||||
common.UAAEndpoint: "10.192.168.5",
|
||||
|
@ -115,7 +115,6 @@ func GetUnitTestConfig() map[string]interface{} {
|
||||
common.LDAPTimeout: 30,
|
||||
common.LDAPVerifyCert: true,
|
||||
common.UAAVerifyCert: true,
|
||||
common.ClairDBHost: "postgresql",
|
||||
common.AdminInitialPassword: "Harbor12345",
|
||||
common.LDAPGroupSearchFilter: "objectclass=groupOfNames",
|
||||
common.LDAPGroupBaseDN: "dc=example,dc=com",
|
||||
|
@ -335,19 +335,6 @@ func WithClair() bool {
|
||||
return cfgMgr.Get(common.WithClair).GetBool()
|
||||
}
|
||||
|
||||
// ClairDB return Clair db info
|
||||
func ClairDB() (*models.PostGreSQL, error) {
|
||||
clairDB := &models.PostGreSQL{
|
||||
Host: cfgMgr.Get(common.ClairDBHost).GetString(),
|
||||
Port: cfgMgr.Get(common.ClairDBPort).GetInt(),
|
||||
Username: cfgMgr.Get(common.ClairDBUsername).GetString(),
|
||||
Password: cfgMgr.Get(common.ClairDBPassword).GetString(),
|
||||
Database: cfgMgr.Get(common.ClairDB).GetString(),
|
||||
SSLMode: cfgMgr.Get(common.ClairDBSSLMode).GetString(),
|
||||
}
|
||||
return clairDB, nil
|
||||
}
|
||||
|
||||
// ClairAdapterEndpoint returns the endpoint of clair adapter instance, by default it's the one deployed within Harbor.
|
||||
func ClairAdapterEndpoint() string {
|
||||
return cfgMgr.Get(common.ClairAdapterURL).GetString()
|
||||
|
@ -137,17 +137,8 @@ func TestConfig(t *testing.T) {
|
||||
t.Fatalf("failed to get database: %v", err)
|
||||
}
|
||||
|
||||
clairDB, err := ClairDB()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get clair DB %v", err)
|
||||
}
|
||||
defaultConfig := test.GetDefaultConfigMap()
|
||||
Upload(defaultConfig)
|
||||
assert.Equal(defaultConfig[common.ClairDB], clairDB.Database)
|
||||
assert.Equal(defaultConfig[common.ClairDBUsername], clairDB.Username)
|
||||
assert.Equal(defaultConfig[common.ClairDBPassword], clairDB.Password)
|
||||
assert.Equal(defaultConfig[common.ClairDBHost], clairDB.Host)
|
||||
assert.Equal(defaultConfig[common.ClairDBPort], clairDB.Port)
|
||||
|
||||
if InternalNotaryEndpoint() != "http://notary-server:4443" {
|
||||
t.Errorf("Unexpected notary endpoint: %s", InternalNotaryEndpoint())
|
||||
|
@ -197,14 +197,6 @@ func registerScanners() {
|
||||
}
|
||||
|
||||
if config.WithClair() {
|
||||
clairDB, err := config.ClairDB()
|
||||
if err != nil {
|
||||
log.Fatalf("failed to load clair database information: %v", err)
|
||||
}
|
||||
if err := dao.InitClairDB(clairDB); err != nil {
|
||||
log.Fatalf("failed to initialize clair database: %v", err)
|
||||
}
|
||||
|
||||
log.Info("Registering Clair scanner")
|
||||
wantedScanners = append(wantedScanners, scanner.Registration{
|
||||
Name: clairScanner,
|
||||
|
Loading…
Reference in New Issue
Block a user