ldap_url and ldap_base_dn not exist in user config (#7115)

Signed-off-by: stonezdj <stonezdj@gmail.com>
This commit is contained in:
stonezdj(Daojun Zhang) 2019-03-15 15:20:12 +08:00 committed by Yan
parent 7aa00aee87
commit 7060747d5b
2 changed files with 19 additions and 6 deletions

View File

@ -85,8 +85,7 @@ func (c *CfgManager) loadDefault() {
// Init Default Value
itemArray := metadata.Instance().GetAll()
for _, item := range itemArray {
// Every string type have default value, other types should have a default value
if _, ok := item.ItemType.(*metadata.StringType); ok || len(item.DefaultValue) > 0 {
if len(item.DefaultValue) > 0 {
cfgValue, err := metadata.NewCfgValue(item.Name, item.DefaultValue)
if err != nil {
log.Errorf("loadDefault failed, config item, key: %v, err: %v", item.Name, err)
@ -148,10 +147,17 @@ func (c *CfgManager) GetUserCfgs() map[string]interface{} {
if item.Scope == metadata.UserScope {
cfgValue, err := c.store.GetAnyType(item.Name)
if err != nil {
if err != metadata.ErrValueNotSet {
if err == metadata.ErrValueNotSet {
if _, ok := item.ItemType.(*metadata.StringType); ok {
cfgValue = ""
}
if _, ok := item.ItemType.(*metadata.NonEmptyStringType); ok {
cfgValue = ""
}
} else {
log.Errorf("Failed to get value of key %v, error %v", item.Name, err)
continue
}
continue
}
resultMap[item.Name] = cfgValue
}

View File

@ -2,10 +2,11 @@ package config
import (
"fmt"
"github.com/goharbor/harbor/src/common/utils/test"
"github.com/stretchr/testify/assert"
"os"
"testing"
"github.com/goharbor/harbor/src/common/utils/test"
"github.com/stretchr/testify/assert"
)
var TestDBConfig = map[string]interface{}{
@ -36,6 +37,12 @@ func TestLoadFromDatabase(t *testing.T) {
assert.Equal(t, `{"parameter":{"daily_time":0},"type":"daily"}`, configManager.Get("scan_all_policy").GetString())
}
func TestLoadUserCfg(t *testing.T) {
configMap := configManager.GetUserCfgs()
assert.NotNil(t, configMap["ldap_url"])
assert.NotNil(t, configMap["ldap_base_dn"])
}
func TestSaveToDatabase(t *testing.T) {
fmt.Printf("database config %#v\n", configManager.GetDatabaseCfg())
configManager.Load()