mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 02:35:17 +01:00
ldap_url and ldap_base_dn not exist in user config (#7115)
Signed-off-by: stonezdj <stonezdj@gmail.com>
This commit is contained in:
parent
7aa00aee87
commit
7060747d5b
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user