Skip to content
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

Closed
wants to merge 7 commits into from

Conversation

stonezdj
Copy link
Contributor

@stonezdj stonezdj commented Nov 7, 2018

Remove adminserver

@stonezdj stonezdj force-pushed the remove_adminserver branch 3 times, most recently from ae02bcd to e716865 Compare November 20, 2018 09:15
@coveralls
Copy link

coveralls commented Nov 21, 2018

Pull Request Test Coverage Report for Build 9667

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-31.9%) to 33.252%

Totals Coverage Status
Change from base Build 9644: -31.9%
Covered Lines: 1915
Relevant Lines: 5759

💛 - Coveralls

@stonezdj stonezdj force-pushed the remove_adminserver branch 3 times, most recently from ac273f0 to 2f67c6d Compare November 22, 2018 03:48
@stonezdj stonezdj force-pushed the remove_adminserver branch 6 times, most recently from bf79da1 to 094a111 Compare November 26, 2018 02:35
Signed-off-by: stonezdj <stonezdj@gmail.com>
make/docker-compose.tpl Outdated Show resolved Hide resolved
core:
image: goharbor/harbor-core:__version__
container_name: harbor-core
env_file:
- ./common/config/core/env
- ./common/config/adminserver/env
Copy link
Contributor

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?

make/photon/db/Dockerfile Show resolved Hide resolved
src/common/config/configmetadata.go Show resolved Hide resolved
@@ -0,0 +1,105 @@
package db
Copy link
Contributor

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 {
Copy link
Contributor

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
Copy link
Contributor

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 {
Copy link
Contributor

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?

src/core/main.go Outdated Show resolved Hide resolved
import "github.com/goharbor/harbor/src/common/models"

// Client used to retrieve configuration
type Client interface {
Copy link
Contributor

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)
Copy link
Contributor

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))
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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 {
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Contributor

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)}
Copy link
Contributor

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 ...
Copy link
Contributor

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
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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"
Copy link
Contributor

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" {
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.

@stonezdj stonezdj changed the title [WIP]Remove adminserver [Reviewing]Remove adminserver Nov 27, 2018
}

// GetStringToStringMap - return the string to string map of current value
func (c *ConfigureValue) GetStringToStringMap() map[string]string {
Copy link
Contributor

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 {
Copy link
Contributor

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)
Copy link
Contributor

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},
Copy link
Contributor

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},
Copy link
Contributor

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.
Copy link
Contributor

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 {
Copy link
Contributor

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},
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about err !=nil?

@stonezdj stonezdj closed this Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants