New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Reviewing]Remove adminserver #6231
Conversation
ae02bcd
to
e716865
Compare
Pull Request Test Coverage Report for Build 9667
💛 - Coveralls |
ac273f0
to
2f67c6d
Compare
bf79da1
to
094a111
Compare
Signed-off-by: stonezdj <stonezdj@gmail.com>
ccf7d58
to
cfecbec
Compare
core: | ||
image: goharbor/harbor-core:__version__ | ||
container_name: harbor-core | ||
env_file: | ||
- ./common/config/core/env | ||
- ./common/config/adminserver/env |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use the /core/env for single?
@@ -0,0 +1,105 @@ | |||
package db |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not call the file driver.go
as the config
is in the package?
) | ||
|
||
// ConfigureDriver - Retrieve configurations from database | ||
type ConfigureDriver struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly as the config
is in the package path it should probably be called Driver
@@ -32,6 +32,15 @@ type Manager struct { | |||
key string | |||
} | |||
|
|||
// ManagerInterface api for configure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add more comments for each func in this interface?
) | ||
|
||
// ConfigSettingAPI ... | ||
type ConfigSettingAPI struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no function to set config, why it calls configsetting?
import "github.com/goharbor/harbor/src/common/models" | ||
|
||
// Client used to retrieve configuration | ||
type Client interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it in the models
package?
@@ -401,12 +388,14 @@ func Database() (*models.Database, error) { | |||
return nil, err | |||
} | |||
|
|||
log.Infof("database connections = %+v", cfg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the password gets compromised?
c.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) | ||
} | ||
configList, err := c.ConfigClient.GetSettingByGroup(group) | ||
log.Errorf("Found items %v", len(configList)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why log error here?
configList, err := c.ConfigClient.GetSettingByGroup(group) | ||
log.Errorf("Found items %v", len(configList)) | ||
if err != nil { | ||
log.Error("failed to get setting by group %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 501?
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package encrypt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move it to src/common/util, it could be used by other components, not just config.
func NewConfigureValue(key, value string) *ConfigureValue { | ||
result := &ConfigureValue{} | ||
if metaData, err := MetaData.GetConfigMetaData(key); err != nil { | ||
if metaData.Type == PasswordType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the difference on if/else?
} | ||
} | ||
log.Errorf("The current value can not convert to integer, %+v", c) | ||
return 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return -1?
} | ||
} | ||
log.Errorf("The current value can not convert to integer, %+v", c) | ||
return 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return -1?
return utils.TestTCPConn(addr, 60, 2) | ||
} | ||
|
||
// GetCfgs ... | ||
func (c *client) GetCfgs() (map[string]interface{}, error) { | ||
url := c.baseURL + "/api/configs" | ||
log.Infof("Create config from: url:%v", url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Infof -> log.Debug
|
||
// Load ... | ||
// FIXME: refactor | ||
func (cd *ConfigureDriver) Load() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree with refactoring this function as hard to understand.
@@ -0,0 +1,80 @@ | |||
package remote | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we just leverage the core client?
|
||
// NewCoreConfigManagerFromArray ... | ||
func NewCoreConfigManagerFromArray(items []config.Item) *CoreConfigManager { | ||
return &CoreConfigManager{Driver: NewDBConfigureStoreFromArray(items)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the DB driver is hardcoded here, how do we extend the driver? If the contributor wants to contribute a redis driver, the current structure seems not support well.
// ValidateFunc - function to validate configure items | ||
type ValidateFunc func(key, value string) error | ||
|
||
// ConfigureMetaData ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add more comment to this struct.
|
||
// ConfigureMetaData ... | ||
type ConfigureMetaData struct { | ||
sync.RWMutex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the lock?
} | ||
|
||
// GetConfigMetaData - Get single configuration item | ||
func (cm *ConfigureMetaData) GetConfigMetaData(key string) (Item, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to Get
} | ||
|
||
// GetAllConfigureItems - Get All Configuration Items | ||
func (cm *ConfigureMetaData) GetAllConfigureItems() (items []Item) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to All
ClairGroup = "clair" | ||
|
||
// Type | ||
IntType = "int" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about create a type for the type of config item and set ValidateFunc as a func of this type?
var systemConfigEditable = false | ||
|
||
func init() { | ||
if os.Getenv("UTTEST") == "true" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it needed if we have SetSystemConfigEditable ()
in line 35?
GetStringToStringMap() map[string]string | ||
// GetMap - return the map of current value | ||
GetMap() map[string]interface{} | ||
// Validator to validate configure items, if passed, return true, else return false and return error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment should be // Validate...
// Set this configure item to configure store | ||
Set(key, value string) error | ||
|
||
GetKey() string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please comment the following functions.
} | ||
|
||
// GetStringToStringMap - return the string to string map of current value | ||
func (c *ConfigureValue) GetStringToStringMap() map[string]string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call GetMap
and tranform the result into map[string]string
?
MetaData.InitMetaData() | ||
// Init Default Value | ||
itemArray := MetaData.GetAllConfigureItems() | ||
for _, item := range itemArray { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these two loops could be merged
} else if strings.EqualFold(c.Value, "off") || strings.EqualFold(c.Value, "false") { | ||
c.Value = "false" | ||
} | ||
boolValue, err := strconv.ParseBool(c.Value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else {
return ErrTypeNotMatch
}
// 1. Add configure item in configlist.go | ||
// 2. Get settings by config.Client | ||
ConfigList = []Item{ | ||
{Scope: SystemScope, Group: BasicGroup, EnvironmentKey: "HARBOR_ADMIN_PASSWORD", DefaultValue: "", Name: "admin_initial_password", Type: PasswordType, Editable: true, Reloadable: false}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
group them by scope
{Scope: SystemScope, Group: BasicGroup, EnvironmentKey: "CFG_EXPIRATION", DefaultValue: "5", Name: "cfg_expiration", Type: StringType, Editable: false, Reloadable: true}, | ||
{Scope: SystemScope, Group: BasicGroup, EnvironmentKey: "CHART_REPOSITORY_URL", DefaultValue: "http://chartmuseum:9999", Name: "chart_repository_url", Type: StringType, Editable: false, Reloadable: true}, | ||
|
||
{Scope: SystemScope, Group: ClairGroup, EnvironmentKey: "CLAIR_DB", DefaultValue: "postgres", Name: "clair_db", Type: StringType, Editable: false, Reloadable: true}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
editable should be false for systemscope item?
Name string `json:"name,omitempty"` | ||
// It can be integer, string, bool, password, map | ||
Type string `json:"type,omitempty"` | ||
// The validation function for this field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's a func it should be a verb, so better rename to Validate
} | ||
|
||
// GetInt - return the int value of current value | ||
func (c *ConfigureValue) GetInt() int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call GetInt64
?
{Scope: SystemScope, Group: ClairGroup, EnvironmentKey: "CLAIR_DB", DefaultValue: "postgres", Name: "clair_db", Type: StringType, Editable: false, Reloadable: true}, | ||
{Scope: SystemScope, Group: ClairGroup, EnvironmentKey: "CLAIR_DB_HOST", DefaultValue: "postgresql", Name: "clair_db_host", Type: StringType, Editable: false, Reloadable: true}, | ||
{Scope: SystemScope, Group: ClairGroup, EnvironmentKey: "CLAIR_DB_PASSWORD", DefaultValue: "root123", Name: "clair_db_password", Type: PasswordType, Editable: false, Reloadable: true}, | ||
{Scope: SystemScope, Group: ClairGroup, EnvironmentKey: "CLAIR_DB_PORT", DefaultValue: "5432", Name: "clair_db_port", Type: IntType, Editable: false, Reloadable: true}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put name first as you use the name as the key in the metadata map.
} | ||
|
||
// SetPassword ... | ||
func (c *ConfigureValue) SetPassword(key, value string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason that we don't put encrypt and decrypt at the same level?
s.configureValues.Range(func(key, value interface{}) bool { | ||
if keyString, suc := key.(string); suc { | ||
itemMataData, err := MetaData.GetConfigMetaData(keyString) | ||
if err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about err !=nil?
Remove adminserver