diff --git a/src/chartserver/handler_utility.go b/src/chartserver/handler_utility.go index 767b17d01..13a72ef00 100644 --- a/src/chartserver/handler_utility.go +++ b/src/chartserver/handler_utility.go @@ -2,7 +2,7 @@ package chartserver import ( "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "path" "strings" "sync" diff --git a/src/common/job/client.go b/src/common/job/client.go index 2d0e6c86e..dcee622e3 100644 --- a/src/common/job/client.go +++ b/src/common/job/client.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "io/ioutil" "net/http" "regexp" diff --git a/src/controller/config/controller.go b/src/controller/config/controller.go index c3884d643..1e8b41322 100644 --- a/src/controller/config/controller.go +++ b/src/controller/config/controller.go @@ -22,10 +22,9 @@ import ( "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/config/metadata" + "github.com/goharbor/harbor/src/lib/config/models" "github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/log" - "github.com/goharbor/harbor/src/pkg/config/db" - "github.com/goharbor/harbor/src/pkg/config/inmemory" ) var ( @@ -36,75 +35,36 @@ var ( // Controller define operations related to configures type Controller interface { // UserConfigs get the user scope configurations - UserConfigs(ctx context.Context) (map[string]*config.Value, error) + UserConfigs(ctx context.Context) (map[string]*models.Value, error) // UpdateUserConfigs update the user scope configurations UpdateUserConfigs(ctx context.Context, conf map[string]interface{}) error // GetAll get all configurations, used by internal, should include the system config items AllConfigs(ctx context.Context) (map[string]interface{}, error) - // Load ... - Load(ctx context.Context) error - // GetString ... - GetString(ctx context.Context, item string) string - // GetBool ... - GetBool(ctx context.Context, item string) bool - // GetInt ... - GetInt(ctx context.Context, item string) int - // Get ... - Get(ctx context.Context, item string) *metadata.ConfigureValue - // GetCfgManager ... - GetManager() config.Manager } type controller struct { - mgr config.Manager } // NewController ... func NewController() Controller { - return &controller{mgr: db.NewDBCfgManager()} + return &controller{} } -// NewInMemoryController ... -func NewInMemoryController() Controller { - return &controller{mgr: inmemory.NewInMemoryManager()} -} - -func (c *controller) GetManager() config.Manager { - return c.mgr -} - -func (c *controller) Get(ctx context.Context, item string) *metadata.ConfigureValue { - return c.mgr.Get(ctx, item) -} - -func (c *controller) Load(ctx context.Context) error { - return c.mgr.Load(ctx) -} - -func (c *controller) GetString(ctx context.Context, item string) string { - return c.mgr.Get(ctx, item).GetString() -} - -func (c *controller) GetBool(ctx context.Context, item string) bool { - return c.mgr.Get(ctx, item).GetBool() -} - -func (c *controller) GetInt(ctx context.Context, item string) int { - return c.mgr.Get(ctx, item).GetInt() -} - -func (c *controller) UserConfigs(ctx context.Context) (map[string]*config.Value, error) { - configs := c.mgr.GetUserCfgs(ctx) +func (c *controller) UserConfigs(ctx context.Context) (map[string]*models.Value, error) { + mgr := config.GetCfgManager(ctx) + configs := mgr.GetUserCfgs(ctx) return ConvertForGet(ctx, configs, false) } func (c *controller) AllConfigs(ctx context.Context) (map[string]interface{}, error) { - configs := c.mgr.GetAll(ctx) + mgr := config.GetCfgManager(ctx) + configs := mgr.GetAll(ctx) return configs, nil } func (c *controller) UpdateUserConfigs(ctx context.Context, conf map[string]interface{}) error { - err := c.mgr.Load(ctx) + mgr := config.GetCfgManager(ctx) + err := mgr.Load(ctx) if err != nil { return err } @@ -116,7 +76,7 @@ func (c *controller) UpdateUserConfigs(ctx context.Context, conf map[string]inte } return err } - if err := c.mgr.UpdateConfig(ctx, conf); err != nil { + if err := mgr.UpdateConfig(ctx, conf); err != nil { log.Errorf("failed to upload configurations: %v", err) return fmt.Errorf("failed to validate configuration") } @@ -124,6 +84,7 @@ func (c *controller) UpdateUserConfigs(ctx context.Context, conf map[string]inte } func (c *controller) validateCfg(ctx context.Context, cfgs map[string]interface{}) (bool, error) { + mgr := config.GetCfgManager(ctx) flag, err := authModeCanBeModified(ctx) if err != nil { return true, err @@ -134,7 +95,7 @@ func (c *controller) validateCfg(ctx context.Context, cfgs map[string]interface{ WithMessage(fmt.Sprintf("the keys %v can not be modified as new users have been inserted into database", failedKeys)) } } - err = c.mgr.ValidateCfg(ctx, cfgs) + err = mgr.ValidateCfg(ctx, cfgs) if err != nil { return false, errors.BadRequestError(err) } @@ -142,11 +103,12 @@ func (c *controller) validateCfg(ctx context.Context, cfgs map[string]interface{ } func (c *controller) checkUnmodifiable(ctx context.Context, cfgs map[string]interface{}, keys ...string) (failed []string) { - if c.mgr == nil || cfgs == nil || keys == nil { + mgr := config.GetCfgManager(ctx) + if mgr == nil || cfgs == nil || keys == nil { return } for _, k := range keys { - v := c.mgr.Get(ctx, k).GetString() + v := mgr.Get(ctx, k).GetString() if nv, ok := cfgs[k]; ok { if v != fmt.Sprintf("%v", nv) { failed = append(failed, k) @@ -164,8 +126,8 @@ type ScanAllPolicy struct { } // ConvertForGet - delete sensitive attrs and add editable field to every attr -func ConvertForGet(ctx context.Context, cfg map[string]interface{}, internal bool) (map[string]*config.Value, error) { - result := map[string]*config.Value{} +func ConvertForGet(ctx context.Context, cfg map[string]interface{}, internal bool) (map[string]*models.Value, error) { + result := map[string]*models.Value{} mList := metadata.Instance().GetAll() @@ -191,7 +153,7 @@ func ConvertForGet(ctx context.Context, cfg map[string]interface{}, internal boo } val = string(valByte) } - result[item.Name] = &config.Value{ + result[item.Name] = &models.Value{ Val: val, Editable: true, } diff --git a/src/controller/config/test/controller_test.go b/src/controller/config/test/controller_test.go index c7352c0ec..bafc50938 100644 --- a/src/controller/config/test/controller_test.go +++ b/src/controller/config/test/controller_test.go @@ -19,6 +19,9 @@ import ( "github.com/goharbor/harbor/src/common" . "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/lib/errors" + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" + htesting "github.com/goharbor/harbor/src/testing" "github.com/stretchr/testify/suite" "testing" diff --git a/src/controller/config/userconfig.go b/src/controller/config/userconfig.go deleted file mode 100755 index 5b3d72929..000000000 --- a/src/controller/config/userconfig.go +++ /dev/null @@ -1,282 +0,0 @@ -// 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 provide config for core api and other modules -// Before accessing user settings, need to call Load() -// For system settings, no need to call Load() -package config - -import ( - "context" - "errors" - cfgModels "github.com/goharbor/harbor/src/lib/config/models" - "github.com/goharbor/harbor/src/lib/orm" - "github.com/goharbor/harbor/src/pkg/config" - "github.com/goharbor/harbor/src/pkg/encrypt" - "strings" - - "github.com/goharbor/harbor/src/common" - "github.com/goharbor/harbor/src/common/models" - "github.com/goharbor/harbor/src/common/secret" - "github.com/goharbor/harbor/src/lib/log" - "github.com/goharbor/harbor/src/pkg/ldap/model" -) - -const ( - defaultKeyPath = "/etc/core/key" - defaultRegistryTokenPrivateKeyPath = "/etc/core/private_key.pem" - - // SessionCookieName is the name of the cookie for session ID - SessionCookieName = "sid" -) - -var ( - // SecretStore manages secrets - SecretStore *secret.Store - keyProvider encrypt.KeyProvider - // defined as a var for testing. - defaultCACertPath = "/etc/core/ca/ca.crt" -) - -// Init configurations -func Init() { - // init key provider - initKeyProvider() - log.Info("init secret store") - // init secret store - initSecretStore() -} - -// InitWithSettings init config with predefined configs, and optionally overwrite the keyprovider -func InitWithSettings(cfgs map[string]interface{}, kp ...encrypt.KeyProvider) { - Init() - Ctl = NewInMemoryController() - mgr := Ctl.GetManager() - mgr.UpdateConfig(backgroundCtx, cfgs) - if len(kp) > 0 { - keyProvider = kp[0] - } -} - -// GetCfgManager return the current config manager -func GetCfgManager(ctx context.Context) config.Manager { - return Ctl.GetManager() -} - -// Load configurations -func Load(ctx context.Context) error { - return Ctl.Load(ctx) -} - -// Upload save all configurations, used by testing -func Upload(cfg map[string]interface{}) error { - mgr := Ctl.GetManager() - return mgr.UpdateConfig(orm.Context(), cfg) -} - -// GetSystemCfg returns the system configurations -func GetSystemCfg(ctx context.Context) (map[string]interface{}, error) { - sysCfg, err := Ctl.AllConfigs(ctx) - if err != nil { - return nil, err - } - if len(sysCfg) == 0 { - return nil, errors.New("can not load system config, the database might be down") - } - return sysCfg, nil -} - -// AuthMode ... -func AuthMode(ctx context.Context) (string, error) { - err := Ctl.Load(ctx) - if err != nil { - log.Errorf("failed to load config, error %v", err) - return "db_auth", err - } - return Ctl.GetString(ctx, common.AUTHMode), nil -} - -// LDAPConf returns the setting of ldap server -func LDAPConf(ctx context.Context) (*model.LdapConf, error) { - err := Ctl.Load(ctx) - if err != nil { - return nil, err - } - return &model.LdapConf{ - URL: Ctl.GetString(ctx, common.LDAPURL), - SearchDn: Ctl.GetString(ctx, common.LDAPSearchDN), - SearchPassword: Ctl.GetString(ctx, common.LDAPSearchPwd), - BaseDn: Ctl.GetString(ctx, common.LDAPBaseDN), - UID: Ctl.GetString(ctx, common.LDAPUID), - Filter: Ctl.GetString(ctx, common.LDAPFilter), - Scope: Ctl.GetInt(ctx, common.LDAPScope), - ConnectionTimeout: Ctl.GetInt(ctx, common.LDAPTimeout), - VerifyCert: Ctl.GetBool(ctx, common.LDAPVerifyCert), - }, nil -} - -// LDAPGroupConf returns the setting of ldap group search -func LDAPGroupConf(ctx context.Context) (*model.GroupConf, error) { - err := Ctl.Load(ctx) - if err != nil { - return nil, err - } - return &model.GroupConf{ - BaseDN: Ctl.GetString(ctx, common.LDAPGroupBaseDN), - Filter: Ctl.GetString(ctx, common.LDAPGroupSearchFilter), - NameAttribute: Ctl.GetString(ctx, common.LDAPGroupAttributeName), - SearchScope: Ctl.GetInt(ctx, common.LDAPGroupSearchScope), - AdminDN: Ctl.GetString(ctx, common.LDAPGroupAdminDn), - MembershipAttribute: Ctl.GetString(ctx, common.LDAPGroupMembershipAttribute), - }, nil -} - -// TokenExpiration returns the token expiration time (in minute) -func TokenExpiration(ctx context.Context) (int, error) { - return Ctl.GetInt(ctx, common.TokenExpiration), nil -} - -// RobotTokenDuration returns the token expiration time of robot account (in minute) -func RobotTokenDuration(ctx context.Context) int { - return Ctl.GetInt(ctx, common.RobotTokenDuration) -} - -// SelfRegistration returns the enablement of self registration -func SelfRegistration(ctx context.Context) (bool, error) { - return Ctl.GetBool(ctx, common.SelfRegistration), nil -} - -// OnlyAdminCreateProject returns the flag to restrict that only sys admin can create project -func OnlyAdminCreateProject(ctx context.Context) (bool, error) { - err := Ctl.Load(ctx) - if err != nil { - return true, err - } - return Ctl.GetString(ctx, common.ProjectCreationRestriction) == common.ProCrtRestrAdmOnly, nil -} - -// Email returns email server settings -func Email(ctx context.Context) (*cfgModels.Email, error) { - err := Ctl.Load(ctx) - if err != nil { - return nil, err - } - return &cfgModels.Email{ - Host: Ctl.GetString(ctx, common.EmailHost), - Port: Ctl.GetInt(ctx, common.EmailPort), - Username: Ctl.GetString(ctx, common.EmailUsername), - Password: Ctl.GetString(ctx, common.EmailPassword), - SSL: Ctl.GetBool(ctx, common.EmailSSL), - From: Ctl.GetString(ctx, common.EmailFrom), - Identity: Ctl.GetString(ctx, common.EmailIdentity), - Insecure: Ctl.GetBool(ctx, common.EmailInsecure), - }, nil -} - -// UAASettings returns the UAASettings to access UAA service. -func UAASettings(ctx context.Context) (*models.UAASettings, error) { - err := Ctl.Load(ctx) - if err != nil { - return nil, err - } - us := &models.UAASettings{ - Endpoint: Ctl.GetString(ctx, common.UAAEndpoint), - ClientID: Ctl.GetString(ctx, common.UAAClientID), - ClientSecret: Ctl.GetString(ctx, common.UAAClientSecret), - VerifyCert: Ctl.GetBool(ctx, common.UAAVerifyCert), - } - return us, nil -} - -// ReadOnly returns a bool to indicates if Harbor is in read only mode. -func ReadOnly(ctx context.Context) bool { - return Ctl.GetBool(ctx, common.ReadOnly) -} - -// HTTPAuthProxySetting returns the setting of HTTP Auth proxy. the settings are only meaningful when the auth_mode is -// set to http_auth -func HTTPAuthProxySetting(ctx context.Context) (*cfgModels.HTTPAuthProxy, error) { - if err := Ctl.Load(ctx); err != nil { - return nil, err - } - return &cfgModels.HTTPAuthProxy{ - Endpoint: Ctl.GetString(ctx, common.HTTPAuthProxyEndpoint), - TokenReviewEndpoint: Ctl.GetString(ctx, common.HTTPAuthProxyTokenReviewEndpoint), - AdminGroups: splitAndTrim(Ctl.GetString(ctx, common.HTTPAuthProxyAdminGroups), ","), - AdminUsernames: splitAndTrim(Ctl.GetString(ctx, common.HTTPAuthProxyAdminUsernames), ","), - VerifyCert: Ctl.GetBool(ctx, common.HTTPAuthProxyVerifyCert), - SkipSearch: Ctl.GetBool(ctx, common.HTTPAuthProxySkipSearch), - ServerCertificate: Ctl.GetString(ctx, common.HTTPAuthProxyServerCertificate), - }, nil -} - -// OIDCSetting returns the setting of OIDC provider, currently there's only one OIDC provider allowed for Harbor and it's -// only effective when auth_mode is set to oidc_auth -func OIDCSetting(ctx context.Context) (*cfgModels.OIDCSetting, error) { - if err := Ctl.Load(ctx); err != nil { - return nil, err - } - scopeStr := Ctl.GetString(ctx, common.OIDCScope) - extEndpoint := strings.TrimSuffix(Ctl.GetString(nil, common.ExtEndpoint), "/") - scope := splitAndTrim(scopeStr, ",") - return &cfgModels.OIDCSetting{ - Name: Ctl.GetString(ctx, common.OIDCName), - Endpoint: Ctl.GetString(ctx, common.OIDCEndpoint), - VerifyCert: Ctl.GetBool(ctx, common.OIDCVerifyCert), - AutoOnboard: Ctl.GetBool(ctx, common.OIDCAutoOnboard), - ClientID: Ctl.GetString(ctx, common.OIDCCLientID), - ClientSecret: Ctl.GetString(ctx, common.OIDCClientSecret), - GroupsClaim: Ctl.GetString(ctx, common.OIDCGroupsClaim), - AdminGroup: Ctl.GetString(ctx, common.OIDCAdminGroup), - RedirectURL: extEndpoint + common.OIDCCallbackPath, - Scope: scope, - UserClaim: Ctl.GetString(ctx, common.OIDCUserClaim), - ExtraRedirectParms: Ctl.Get(ctx, common.OIDCExtraRedirectParms).GetStringToStringMap(), - }, nil -} - -// NotificationEnable returns a bool to indicates if notification enabled in harbor -func NotificationEnable(ctx context.Context) bool { - return Ctl.GetBool(ctx, common.NotificationEnable) -} - -// QuotaPerProjectEnable returns a bool to indicates if quota per project enabled in harbor -func QuotaPerProjectEnable(ctx context.Context) bool { - return Ctl.GetBool(ctx, common.QuotaPerProjectEnable) -} - -// QuotaSetting returns the setting of quota. -func QuotaSetting(ctx context.Context) (*cfgModels.QuotaSetting, error) { - if err := Ctl.Load(ctx); err != nil { - return nil, err - } - return &cfgModels.QuotaSetting{ - StoragePerProject: Ctl.Get(ctx, common.StoragePerProject).GetInt64(), - }, nil -} - -// RobotPrefix user defined robot name prefix. -func RobotPrefix(ctx context.Context) string { - return Ctl.GetString(ctx, common.RobotNamePrefix) -} - -func splitAndTrim(s, sep string) []string { - res := make([]string, 0) - for _, s := range strings.Split(s, sep) { - if e := strings.TrimSpace(s); len(e) > 0 { - res = append(res, e) - } - } - return res -} diff --git a/src/controller/event/handler/util/util.go b/src/controller/event/handler/util/util.go index 381c73b02..cc43afbcc 100644 --- a/src/controller/event/handler/util/util.go +++ b/src/controller/event/handler/util/util.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/lib/log" diff --git a/src/controller/event/handler/util/util_test.go b/src/controller/event/handler/util/util_test.go index 96c519aec..b38515cf4 100644 --- a/src/controller/event/handler/util/util_test.go +++ b/src/controller/event/handler/util/util_test.go @@ -2,7 +2,8 @@ package util import ( "github.com/goharbor/harbor/src/common/utils/test" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "os" "testing" diff --git a/src/controller/event/handler/webhook/artifact/replication.go b/src/controller/event/handler/webhook/artifact/replication.go index 467eb7bda..87f489a07 100644 --- a/src/controller/event/handler/webhook/artifact/replication.go +++ b/src/controller/event/handler/webhook/artifact/replication.go @@ -6,7 +6,7 @@ import ( "fmt" "strings" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" commonModels "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/controller/event" diff --git a/src/controller/event/handler/webhook/artifact/replication_test.go b/src/controller/event/handler/webhook/artifact/replication_test.go index 534776757..6c7a0d35c 100644 --- a/src/controller/event/handler/webhook/artifact/replication_test.go +++ b/src/controller/event/handler/webhook/artifact/replication_test.go @@ -19,7 +19,7 @@ import ( "testing" "time" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" common_dao "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/models" @@ -27,6 +27,8 @@ import ( "github.com/goharbor/harbor/src/controller/project" repctl "github.com/goharbor/harbor/src/controller/replication" repctlmodel "github.com/goharbor/harbor/src/controller/replication/model" + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "github.com/goharbor/harbor/src/pkg/notification" policy_model "github.com/goharbor/harbor/src/pkg/notification/policy/model" projecttesting "github.com/goharbor/harbor/src/testing/controller/project" diff --git a/src/controller/event/handler/webhook/artifact/retention.go b/src/controller/event/handler/webhook/artifact/retention.go index f39f9b26f..7f1966be0 100644 --- a/src/controller/event/handler/webhook/artifact/retention.go +++ b/src/controller/event/handler/webhook/artifact/retention.go @@ -5,8 +5,8 @@ import ( "fmt" "strings" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/controller/retention" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/controller/event" diff --git a/src/controller/event/handler/webhook/artifact/retention_test.go b/src/controller/event/handler/webhook/artifact/retention_test.go index a2168cf93..1be73847b 100644 --- a/src/controller/event/handler/webhook/artifact/retention_test.go +++ b/src/controller/event/handler/webhook/artifact/retention_test.go @@ -7,7 +7,7 @@ import ( "time" "github.com/goharbor/harbor/src/common/dao" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/controller/event" "github.com/goharbor/harbor/src/controller/retention" diff --git a/src/controller/event/handler/webhook/chart/chart.go b/src/controller/event/handler/webhook/chart/chart.go index 2d4886b92..3f78f749d 100644 --- a/src/controller/event/handler/webhook/chart/chart.go +++ b/src/controller/event/handler/webhook/chart/chart.go @@ -18,7 +18,7 @@ import ( "context" "errors" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/controller/event" diff --git a/src/controller/event/handler/webhook/chart/chart_test.go b/src/controller/event/handler/webhook/chart/chart_test.go index f99fa5b26..e37c35544 100644 --- a/src/controller/event/handler/webhook/chart/chart_test.go +++ b/src/controller/event/handler/webhook/chart/chart_test.go @@ -17,7 +17,9 @@ package chart import ( "context" testutils "github.com/goharbor/harbor/src/common/utils/test" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "os" "testing" diff --git a/src/controller/event/handler/webhook/quota/quota_test.go b/src/controller/event/handler/webhook/quota/quota_test.go index b126a5345..9bbaf91e2 100644 --- a/src/controller/event/handler/webhook/quota/quota_test.go +++ b/src/controller/event/handler/webhook/quota/quota_test.go @@ -17,8 +17,9 @@ package quota import ( "context" common_dao "github.com/goharbor/harbor/src/common/dao" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/controller/event" + "github.com/goharbor/harbor/src/lib/config" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" policy_model "github.com/goharbor/harbor/src/pkg/notification/policy/model" "github.com/goharbor/harbor/src/testing/mock" "testing" diff --git a/src/controller/event/handler/webhook/scan/scan_test.go b/src/controller/event/handler/webhook/scan/scan_test.go index ecc5aee9b..8868088d3 100644 --- a/src/controller/event/handler/webhook/scan/scan_test.go +++ b/src/controller/event/handler/webhook/scan/scan_test.go @@ -17,8 +17,9 @@ package scan import ( "context" common_dao "github.com/goharbor/harbor/src/common/dao" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/controller/event" + "github.com/goharbor/harbor/src/lib/config" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" policy_model "github.com/goharbor/harbor/src/pkg/notification/policy/model" "testing" "time" diff --git a/src/controller/gc/callback.go b/src/controller/gc/callback.go index 900792b66..8e1f011e6 100644 --- a/src/controller/gc/callback.go +++ b/src/controller/gc/callback.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/controller/quota" "github.com/goharbor/harbor/src/jobservice/job" diff --git a/src/controller/ldap/controller.go b/src/controller/ldap/controller.go index 58354059e..897500bdb 100644 --- a/src/controller/ldap/controller.go +++ b/src/controller/ldap/controller.go @@ -17,7 +17,8 @@ package ldap import ( "context" "github.com/goharbor/harbor/src/common" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" + "github.com/goharbor/harbor/src/lib/config/models" "github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/pkg/ldap" "github.com/goharbor/harbor/src/pkg/ldap/model" @@ -31,7 +32,7 @@ var ( // Controller define the operations related to LDAP type Controller interface { // Ping test the ldap config - Ping(ctx context.Context, cfg model.LdapConf) (bool, error) + Ping(ctx context.Context, cfg models.LdapConf) (bool, error) // SearchUser search ldap user with name SearchUser(ctx context.Context, username string) ([]model.User, error) // ImportUser import ldap users to harbor @@ -59,7 +60,7 @@ func (c *controller) Session(ctx context.Context) (*ldap.Session, error) { return ldap.NewSession(*cfg, *groupCfg), nil } -func (c *controller) Ping(ctx context.Context, cfg model.LdapConf) (bool, error) { +func (c *controller) Ping(ctx context.Context, cfg models.LdapConf) (bool, error) { if len(cfg.SearchPassword) == 0 { pwd, err := defaultPassword(ctx) if err != nil { @@ -73,7 +74,7 @@ func (c *controller) Ping(ctx context.Context, cfg model.LdapConf) (bool, error) return c.mgr.Ping(ctx, cfg) } -func (c *controller) ldapConfigs(ctx context.Context) (*model.LdapConf, *model.GroupConf, error) { +func (c *controller) ldapConfigs(ctx context.Context) (*models.LdapConf, *models.GroupConf, error) { cfg, err := config.LDAPConf(ctx) if err != nil { return nil, nil, err @@ -81,7 +82,7 @@ func (c *controller) ldapConfigs(ctx context.Context) (*model.LdapConf, *model.G groupCfg, err := config.LDAPGroupConf(ctx) if err != nil { log.Warningf("failed to get the ldap group config, error %v", err) - groupCfg = &model.GroupConf{} + groupCfg = &models.GroupConf{} } return cfg, groupCfg, nil } diff --git a/src/controller/ldap/controller_test.go b/src/controller/ldap/controller_test.go index 9c15e2238..384fb91a5 100644 --- a/src/controller/ldap/controller_test.go +++ b/src/controller/ldap/controller_test.go @@ -16,8 +16,10 @@ package ldap import ( "github.com/goharbor/harbor/src/common" - "github.com/goharbor/harbor/src/controller/config" - "github.com/goharbor/harbor/src/pkg/ldap/model" + "github.com/goharbor/harbor/src/lib/config" + "github.com/goharbor/harbor/src/lib/config/models" + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" htesting "github.com/goharbor/harbor/src/testing" "github.com/goharbor/harbor/src/testing/mock" "github.com/goharbor/harbor/src/testing/pkg/ldap" @@ -65,7 +67,7 @@ var defaultConfigWithVerifyCert = map[string]interface{}{ common.WithNotary: false, } -var ldapCfg = model.LdapConf{ +var ldapCfg = models.LdapConf{ URL: "ldap://127.0.0.1", SearchDn: "cn=admin,dc=example,dc=com", SearchPassword: "admin", @@ -75,7 +77,7 @@ var ldapCfg = model.LdapConf{ ConnectionTimeout: 30, } -var ldapCfgNoPwd = model.LdapConf{ +var ldapCfgNoPwd = models.LdapConf{ URL: "ldap://127.0.0.1", SearchDn: "cn=admin,dc=example,dc=com", BaseDn: "dc=example,dc=com", @@ -84,7 +86,7 @@ var ldapCfgNoPwd = model.LdapConf{ ConnectionTimeout: 30, } -var groupCfg = model.GroupConf{ +var groupCfg = models.GroupConf{ BaseDN: "dc=example,dc=com", NameAttribute: "cn", SearchScope: 2, diff --git a/src/controller/p2p/preheat/controllor_test.go b/src/controller/p2p/preheat/controllor_test.go index 81d4b344b..2345dada0 100644 --- a/src/controller/p2p/preheat/controllor_test.go +++ b/src/controller/p2p/preheat/controllor_test.go @@ -4,7 +4,7 @@ import ( "context" "errors" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "net/http" "net/http/httptest" "testing" diff --git a/src/controller/p2p/preheat/enforcer.go b/src/controller/p2p/preheat/enforcer.go index ac0569396..dff603fd4 100644 --- a/src/controller/p2p/preheat/enforcer.go +++ b/src/controller/p2p/preheat/enforcer.go @@ -17,7 +17,7 @@ package preheat import ( "context" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "strings" diff --git a/src/controller/proxy/local.go b/src/controller/proxy/local.go index 45333dbd9..96b0ef0c2 100644 --- a/src/controller/proxy/local.go +++ b/src/controller/proxy/local.go @@ -18,10 +18,10 @@ import ( "context" "github.com/docker/distribution" "github.com/goharbor/harbor/src/controller/artifact" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/controller/event/metadata" "github.com/goharbor/harbor/src/lib" "github.com/goharbor/harbor/src/lib/cache" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/pkg/notifier/event" diff --git a/src/controller/robot/controller.go b/src/controller/robot/controller.go index 533eb06d7..930d73325 100644 --- a/src/controller/robot/controller.go +++ b/src/controller/robot/controller.go @@ -5,7 +5,7 @@ import ( "fmt" rbac_project "github.com/goharbor/harbor/src/common/rbac/project" "github.com/goharbor/harbor/src/common/utils" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/lib/q" diff --git a/src/controller/robot/controller_test.go b/src/controller/robot/controller_test.go index 98429c2a2..7732df1e0 100644 --- a/src/controller/robot/controller_test.go +++ b/src/controller/robot/controller_test.go @@ -6,8 +6,9 @@ import ( "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/common/utils/test" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/q" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "github.com/goharbor/harbor/src/pkg/permission/types" rbac_model "github.com/goharbor/harbor/src/pkg/rbac/model" "github.com/goharbor/harbor/src/pkg/robot/model" diff --git a/src/controller/scan/base_controller.go b/src/controller/scan/base_controller.go index 11b7ff73a..84a60e3d9 100644 --- a/src/controller/scan/base_controller.go +++ b/src/controller/scan/base_controller.go @@ -18,7 +18,7 @@ import ( "bytes" "context" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "strings" "sync" diff --git a/src/controller/scan/base_controller_test.go b/src/controller/scan/base_controller_test.go index eff1096dc..744370f6f 100644 --- a/src/controller/scan/base_controller_test.go +++ b/src/controller/scan/base_controller_test.go @@ -19,16 +19,15 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/goharbor/harbor/src/controller/config" - "testing" - "time" - "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/rbac" "github.com/goharbor/harbor/src/controller/artifact" "github.com/goharbor/harbor/src/controller/robot" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/lib/q" + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "github.com/goharbor/harbor/src/pkg/permission/types" "github.com/goharbor/harbor/src/pkg/robot/model" sca "github.com/goharbor/harbor/src/pkg/scan" @@ -48,6 +47,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "testing" + "time" ) // ControllerTestSuite is the test suite for scan controller. diff --git a/src/controller/systeminfo/controller.go b/src/controller/systeminfo/controller.go index f0e749719..d6309728e 100644 --- a/src/controller/systeminfo/controller.go +++ b/src/controller/systeminfo/controller.go @@ -17,7 +17,7 @@ package systeminfo import ( "context" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/config/models" "io" "os" diff --git a/src/controller/systeminfo/controller_test.go b/src/controller/systeminfo/controller_test.go index 983cd9000..4bf2105c5 100644 --- a/src/controller/systeminfo/controller_test.go +++ b/src/controller/systeminfo/controller_test.go @@ -2,7 +2,8 @@ package systeminfo import ( "context" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" htesting "github.com/goharbor/harbor/src/testing" "testing" diff --git a/src/controller/tag/controller_test.go b/src/controller/tag/controller_test.go index d0b917457..b13952bbb 100644 --- a/src/controller/tag/controller_test.go +++ b/src/controller/tag/controller_test.go @@ -16,10 +16,11 @@ package tag import ( "github.com/goharbor/harbor/src/common" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/orm" pkg_artifact "github.com/goharbor/harbor/src/pkg/artifact" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "github.com/goharbor/harbor/src/pkg/tag/model/tag" ormtesting "github.com/goharbor/harbor/src/testing/lib/orm" "github.com/goharbor/harbor/src/testing/pkg/artifact" diff --git a/src/controller/usergroup/test/controller_test.go b/src/controller/usergroup/test/controller_test.go index 623ab9b00..b9a9b90a3 100644 --- a/src/controller/usergroup/test/controller_test.go +++ b/src/controller/usergroup/test/controller_test.go @@ -16,9 +16,10 @@ package test import ( "github.com/goharbor/harbor/src/common" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/controller/usergroup" _ "github.com/goharbor/harbor/src/core/auth/ldap" + "github.com/goharbor/harbor/src/lib/config" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "github.com/goharbor/harbor/src/pkg/usergroup/model" htesting "github.com/goharbor/harbor/src/testing" "github.com/stretchr/testify/suite" diff --git a/src/core/api/base.go b/src/core/api/base.go index 90e158a4d..33c5c40eb 100644 --- a/src/core/api/base.go +++ b/src/core/api/base.go @@ -18,7 +18,7 @@ import ( "context" "encoding/json" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "net/http" "github.com/ghodss/yaml" diff --git a/src/core/api/chart_repository.go b/src/core/api/chart_repository.go index 75e1337ff..245c1373d 100755 --- a/src/core/api/chart_repository.go +++ b/src/core/api/chart_repository.go @@ -5,7 +5,7 @@ import ( "context" "errors" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "io" "io/ioutil" "mime/multipart" diff --git a/src/core/api/email.go b/src/core/api/email.go index e20d37364..573fda099 100644 --- a/src/core/api/email.go +++ b/src/core/api/email.go @@ -16,7 +16,7 @@ package api import ( "errors" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "net" "strconv" diff --git a/src/core/api/harborapi_test.go b/src/core/api/harborapi_test.go index bf5c35c13..748a8dd1a 100644 --- a/src/core/api/harborapi_test.go +++ b/src/core/api/harborapi_test.go @@ -35,10 +35,10 @@ import ( "github.com/goharbor/harbor/src/common/job/test" "github.com/goharbor/harbor/src/common/models" testutils "github.com/goharbor/harbor/src/common/utils/test" - "github.com/goharbor/harbor/src/controller/config" apimodels "github.com/goharbor/harbor/src/core/api/models" _ "github.com/goharbor/harbor/src/core/auth/db" _ "github.com/goharbor/harbor/src/core/auth/ldap" + "github.com/goharbor/harbor/src/lib/config" libOrm "github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/server/middleware" "github.com/goharbor/harbor/src/server/middleware/orm" diff --git a/src/core/api/health.go b/src/core/api/health.go index 694b5803a..1a1e524c1 100644 --- a/src/core/api/health.go +++ b/src/core/api/health.go @@ -17,7 +17,7 @@ package api import ( "errors" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "io/ioutil" "net/http" "sort" diff --git a/src/core/api/internal.go b/src/core/api/internal.go index 53048e99b..b895c301b 100644 --- a/src/core/api/internal.go +++ b/src/core/api/internal.go @@ -16,7 +16,7 @@ package api import ( "context" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" o "github.com/astaxie/beego/orm" "github.com/goharbor/harbor/src/common" diff --git a/src/core/auth/authenticator.go b/src/core/auth/authenticator.go index 56385ad7c..c39fb7886 100644 --- a/src/core/auth/authenticator.go +++ b/src/core/auth/authenticator.go @@ -19,7 +19,7 @@ import ( "fmt" "time" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/pkg/usergroup/model" diff --git a/src/core/auth/authproxy/auth.go b/src/core/auth/authproxy/auth.go index 7894d2c87..bd432aaf7 100644 --- a/src/core/auth/authproxy/auth.go +++ b/src/core/auth/authproxy/auth.go @@ -26,8 +26,8 @@ import ( "sync" "time" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/jobservice/logger" + "github.com/goharbor/harbor/src/lib/config" cfgModels "github.com/goharbor/harbor/src/lib/config/models" "github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/pkg/usergroup/model" diff --git a/src/core/auth/authproxy/auth_test.go b/src/core/auth/authproxy/auth_test.go index 72c6f5073..9ea6d5a97 100644 --- a/src/core/auth/authproxy/auth_test.go +++ b/src/core/auth/authproxy/auth_test.go @@ -19,11 +19,12 @@ import ( "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/models" cut "github.com/goharbor/harbor/src/common/utils/test" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/core/auth" "github.com/goharbor/harbor/src/core/auth/authproxy/test" + "github.com/goharbor/harbor/src/lib/config" cfgModels "github.com/goharbor/harbor/src/lib/config/models" "github.com/goharbor/harbor/src/lib/orm" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "github.com/goharbor/harbor/src/pkg/usergroup" "github.com/goharbor/harbor/src/pkg/usergroup/model" "github.com/stretchr/testify/assert" diff --git a/src/core/auth/db/db_test.go b/src/core/auth/db/db_test.go index 3ec8a76e2..7f7d22e7e 100644 --- a/src/core/auth/db/db_test.go +++ b/src/core/auth/db/db_test.go @@ -14,7 +14,9 @@ package db import ( - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "log" "os" "testing" diff --git a/src/core/auth/ldap/ldap.go b/src/core/auth/ldap/ldap.go index 66eed29c2..725b97707 100644 --- a/src/core/auth/ldap/ldap.go +++ b/src/core/auth/ldap/ldap.go @@ -20,7 +20,7 @@ import ( "regexp" "strings" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/pkg/ldap/model" ugModel "github.com/goharbor/harbor/src/pkg/usergroup/model" diff --git a/src/core/auth/ldap/ldap_test.go b/src/core/auth/ldap/ldap_test.go index 851924392..b7523e5aa 100644 --- a/src/core/auth/ldap/ldap_test.go +++ b/src/core/auth/ldap/ldap_test.go @@ -14,12 +14,14 @@ package ldap import ( - "github.com/goharbor/harbor/src/pkg/usergroup" "os" "testing" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" + "github.com/goharbor/harbor/src/pkg/usergroup" ugModel "github.com/goharbor/harbor/src/pkg/usergroup/model" "github.com/stretchr/testify/assert" diff --git a/src/core/auth/uaa/uaa.go b/src/core/auth/uaa/uaa.go index 06e496017..29106eddd 100644 --- a/src/core/auth/uaa/uaa.go +++ b/src/core/auth/uaa/uaa.go @@ -16,7 +16,7 @@ package uaa import ( "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "os" "strings" diff --git a/src/core/auth/uaa/uaa_test.go b/src/core/auth/uaa/uaa_test.go index 4684977ec..4c7ee017d 100644 --- a/src/core/auth/uaa/uaa_test.go +++ b/src/core/auth/uaa/uaa_test.go @@ -15,10 +15,13 @@ package uaa import ( - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "os" "testing" + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" + "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/common/utils/test" diff --git a/src/core/controllers/authproxy_redirect.go b/src/core/controllers/authproxy_redirect.go index 995daec78..6c6a680cb 100644 --- a/src/core/controllers/authproxy_redirect.go +++ b/src/core/controllers/authproxy_redirect.go @@ -2,7 +2,7 @@ package controllers import ( "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "net/http" diff --git a/src/core/controllers/base.go b/src/core/controllers/base.go index 4d8155918..095f50962 100644 --- a/src/core/controllers/base.go +++ b/src/core/controllers/base.go @@ -17,7 +17,7 @@ package controllers import ( "bytes" "context" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "html/template" "net" diff --git a/src/core/controllers/controllers_test.go b/src/core/controllers/controllers_test.go index e1640a2b0..865db5ae0 100644 --- a/src/core/controllers/controllers_test.go +++ b/src/core/controllers/controllers_test.go @@ -15,9 +15,9 @@ package controllers import ( "fmt" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/core/middlewares" "github.com/goharbor/harbor/src/lib" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "net/http" "net/http/httptest" @@ -31,6 +31,8 @@ import ( "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/models" utilstest "github.com/goharbor/harbor/src/common/utils/test" + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "github.com/stretchr/testify/assert" ) diff --git a/src/core/controllers/oidc.go b/src/core/controllers/oidc.go index 958e2d28a..57ccc8a75 100644 --- a/src/core/controllers/oidc.go +++ b/src/core/controllers/oidc.go @@ -17,7 +17,7 @@ package controllers import ( "encoding/json" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "net/http" "strings" diff --git a/src/core/main.go b/src/core/main.go index bbb5e8ac7..2fe9ff7f1 100755 --- a/src/core/main.go +++ b/src/core/main.go @@ -18,7 +18,7 @@ import ( "context" "encoding/gob" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "net/url" "os" "os/signal" diff --git a/src/core/service/token/authutils.go b/src/core/service/token/authutils.go index 1b2f86fb6..508103aee 100644 --- a/src/core/service/token/authutils.go +++ b/src/core/service/token/authutils.go @@ -17,7 +17,7 @@ package token import ( "context" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "strings" "time" diff --git a/src/core/service/token/creator.go b/src/core/service/token/creator.go index 8b7481ba9..f2b8a2f98 100644 --- a/src/core/service/token/creator.go +++ b/src/core/service/token/creator.go @@ -18,7 +18,7 @@ import ( "context" "fmt" rbac_project "github.com/goharbor/harbor/src/common/rbac/project" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "net/http" "net/url" "strings" diff --git a/src/core/service/token/token_test.go b/src/core/service/token/token_test.go index a6aa19039..eb618975d 100644 --- a/src/core/service/token/token_test.go +++ b/src/core/service/token/token_test.go @@ -21,8 +21,10 @@ import ( "fmt" "github.com/goharbor/harbor/src/common/rbac/project" "github.com/goharbor/harbor/src/common/utils/test" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "io/ioutil" "net/url" "os" diff --git a/src/core/utils/job.go b/src/core/utils/job.go index 4976c3850..c68ed3f63 100644 --- a/src/core/utils/job.go +++ b/src/core/utils/job.go @@ -17,7 +17,7 @@ package utils import ( "github.com/goharbor/harbor/src/common/job" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "sync" ) diff --git a/src/lib/config/config.go b/src/lib/config/config.go index 77af92cfc..7ff18c417 100644 --- a/src/lib/config/config.go +++ b/src/lib/config/config.go @@ -15,16 +15,34 @@ package config import ( + "context" "errors" + "github.com/goharbor/harbor/src/common" + "github.com/goharbor/harbor/src/lib/config/models" + "github.com/goharbor/harbor/src/lib/encrypt" "github.com/goharbor/harbor/src/lib/log" + "github.com/goharbor/harbor/src/lib/orm" "sync" ) -var ( - managersMU sync.RWMutex - managers = make(map[string]Manager) +const ( + // SessionCookieName is the name of the cookie for session ID + SessionCookieName = "sid" + + defaultKeyPath = "/etc/core/key" + defaultRegistryTokenPrivateKeyPath = "/etc/core/private_key.pem" ) +var ( + // DefaultCfgManager the default change manager, default is DBCfgManager. If InMemoryConfigManager is used, need to set to InMemoryCfgManager in test code + DefaultCfgManager = common.DBCfgManager + managersMU sync.RWMutex + managers = make(map[string]Manager) +) + +// InternalCfg internal configure response model +type InternalCfg map[string]*models.Value + // Register register the config manager func Register(name string, mgr Manager) { managersMU.Lock() @@ -46,3 +64,50 @@ func GetManager(name string) (Manager, error) { } return mgr, nil } + +func defaultMgr() Manager { + manager, err := GetManager(DefaultCfgManager) + if err != nil { + log.Error("failed to get config manager") + } + return manager +} + +// Init configurations +// need to import following package before calling it +// _ "github.com/goharbor/harbor/src/pkg/config/db" +func Init() { + // init key provider + initKeyProvider() + log.Info("init secret store") + // init secret store + initSecretStore() +} + +// InitWithSettings init config with predefined configs, and optionally overwrite the keyprovider +// need to import following package before calling it +// _ "github.com/goharbor/harbor/src/pkg/config/inmemory" +func InitWithSettings(cfgs map[string]interface{}, kp ...encrypt.KeyProvider) { + Init() + DefaultCfgManager = common.InMemoryCfgManager + mgr := defaultMgr() + mgr.UpdateConfig(backgroundCtx, cfgs) + if len(kp) > 0 { + keyProvider = kp[0] + } +} + +// GetCfgManager return the current config manager +func GetCfgManager(ctx context.Context) Manager { + return defaultMgr() +} + +// Load configurations +func Load(ctx context.Context) error { + return defaultMgr().Load(ctx) +} + +// Upload save all configurations, used by testing +func Upload(cfg map[string]interface{}) error { + return defaultMgr().UpdateConfig(orm.Context(), cfg) +} diff --git a/src/lib/config/model.go b/src/lib/config/model.go deleted file mode 100644 index a486d37b7..000000000 --- a/src/lib/config/model.go +++ /dev/null @@ -1,24 +0,0 @@ -// 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 - -// Value ... -type Value struct { - Val interface{} `json:"value"` - Editable bool `json:"editable"` -} - -// InternalCfg internal configure response model -type InternalCfg map[string]*Value diff --git a/src/lib/config/models/model.go b/src/lib/config/models/model.go index 4dcc2db3e..7f9adac2a 100644 --- a/src/lib/config/models/model.go +++ b/src/lib/config/models/model.go @@ -77,3 +77,32 @@ type ConfigEntry struct { func (ce *ConfigEntry) TableName() string { return "properties" } + +// Value ... +type Value struct { + Val interface{} `json:"value"` + Editable bool `json:"editable"` +} + +// LdapConf holds information about ldap configuration +type LdapConf struct { + URL string `json:"ldap_url"` + SearchDn string `json:"ldap_search_dn"` + SearchPassword string `json:"ldap_search_password"` + BaseDn string `json:"ldap_base_dn"` + Filter string `json:"ldap_filter"` + UID string `json:"ldap_uid"` + Scope int `json:"ldap_scope"` + ConnectionTimeout int `json:"ldap_connection_timeout"` + VerifyCert bool `json:"ldap_verify_cert"` +} + +// GroupConf holds information about ldap group +type GroupConf struct { + BaseDN string `json:"ldap_group_base_dn,omitempty"` + Filter string `json:"ldap_group_filter,omitempty"` + NameAttribute string `json:"ldap_group_name_attribute,omitempty"` + SearchScope int `json:"ldap_group_search_scope"` + AdminDN string `json:"ldap_group_admin_dn,omitempty"` + MembershipAttribute string `json:"ldap_group_membership_attribute,omitempty"` +} diff --git a/src/controller/config/systemcfg.go b/src/lib/config/systemconfig.go similarity index 70% rename from src/controller/config/systemcfg.go rename to src/lib/config/systemconfig.go index a8b1b2af9..d942a7adb 100644 --- a/src/controller/config/systemcfg.go +++ b/src/lib/config/systemconfig.go @@ -12,6 +12,20 @@ // See the License for the specific language governing permissions and // limitations under the License. +// 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 ( @@ -20,22 +34,22 @@ import ( "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/common/secret" + "github.com/goharbor/harbor/src/lib/encrypt" "github.com/goharbor/harbor/src/lib/log" - "github.com/goharbor/harbor/src/pkg/encrypt" "os" "strconv" "strings" ) var ( + // SecretStore manages secrets + SecretStore *secret.Store + keyProvider encrypt.KeyProvider // Use backgroundCtx to access system scope config backgroundCtx context.Context = context.Background() ) // It contains all system settings -// If the config is set in env, just get it from env -// If the config might not be set in env, and may have a default value, get it in this way: -// Ctl.GetString(backgroundCtx, "xxxx") // TokenPrivateKeyPath returns the path to the key for signing token for registry func TokenPrivateKeyPath() string { @@ -129,23 +143,23 @@ func GetGCTimeWindow() int64 { // WithNotary returns a bool value to indicate if Harbor's deployed with Notary func WithNotary() bool { - return Ctl.GetBool(backgroundCtx, common.WithNotary) + return defaultMgr().Get(backgroundCtx, common.WithNotary).GetBool() } // WithTrivy returns a bool value to indicate if Harbor's deployed with Trivy. func WithTrivy() bool { - return Ctl.GetBool(backgroundCtx, common.WithTrivy) + return defaultMgr().Get(backgroundCtx, common.WithTrivy).GetBool() } // WithChartMuseum returns a bool to indicate if chartmuseum is deployed with Harbor. func WithChartMuseum() bool { - return Ctl.GetBool(backgroundCtx, common.WithChartMuseum) + return defaultMgr().Get(backgroundCtx, common.WithChartMuseum).GetBool() } // GetChartMuseumEndpoint returns the endpoint of the chartmuseum service // otherwise an non nil error is returned func GetChartMuseumEndpoint() (string, error) { - chartEndpoint := strings.TrimSpace(Ctl.GetString(backgroundCtx, common.ChartRepoURL)) + chartEndpoint := strings.TrimSpace(defaultMgr().Get(backgroundCtx, common.ChartRepoURL).GetString()) if len(chartEndpoint) == 0 { return "", errors.New("empty chartmuseum endpoint") } @@ -154,7 +168,7 @@ func GetChartMuseumEndpoint() (string, error) { // ExtEndpoint returns the external URL of Harbor: protocol://host:port func ExtEndpoint() (string, error) { - return Ctl.GetString(backgroundCtx, common.ExtEndpoint), nil + return defaultMgr().Get(backgroundCtx, common.ExtEndpoint).GetString(), nil } // ExtURL returns the external URL: host:port @@ -192,12 +206,12 @@ func initSecretStore() { // InternalCoreURL returns the local harbor core url func InternalCoreURL() string { - return strings.TrimSuffix(Ctl.GetString(backgroundCtx, common.CoreURL), "/") + return strings.TrimSuffix(defaultMgr().Get(backgroundCtx, common.CoreURL).GetString(), "/") } // LocalCoreURL returns the local harbor core url func LocalCoreURL() string { - return Ctl.GetString(backgroundCtx, common.CoreLocalURL) + return defaultMgr().Get(backgroundCtx, common.CoreLocalURL).GetString() } // InternalTokenServiceEndpoint returns token service endpoint for internal communication between Harbor containers @@ -208,41 +222,41 @@ func InternalTokenServiceEndpoint() string { // InternalNotaryEndpoint returns notary server endpoint for internal communication between Harbor containers // This is currently a conventional value and can be unaccessible when Harbor is not deployed with Notary. func InternalNotaryEndpoint() string { - return Ctl.GetString(backgroundCtx, common.NotaryURL) + return defaultMgr().Get(backgroundCtx, common.NotaryURL).GetString() } // TrivyAdapterURL returns the endpoint URL of a Trivy adapter instance, by default it's the one deployed within Harbor. func TrivyAdapterURL() string { - return Ctl.GetString(backgroundCtx, common.TrivyAdapterURL) + return defaultMgr().Get(backgroundCtx, common.TrivyAdapterURL).GetString() } // Metric returns the overall metric settings func Metric() *models.Metric { return &models.Metric{ - Enabled: Ctl.GetBool(backgroundCtx, common.MetricEnable), - Port: Ctl.GetInt(backgroundCtx, common.MetricPort), - Path: Ctl.GetString(backgroundCtx, common.MetricPath), + Enabled: defaultMgr().Get(backgroundCtx, common.MetricEnable).GetBool(), + Port: defaultMgr().Get(backgroundCtx, common.MetricPort).GetInt(), + Path: defaultMgr().Get(backgroundCtx, common.MetricPath).GetString(), } } // InitialAdminPassword returns the initial password for administrator func InitialAdminPassword() (string, error) { - return Ctl.GetString(backgroundCtx, common.AdminInitialPassword), nil + return defaultMgr().Get(backgroundCtx, common.AdminInitialPassword).GetString(), nil } // Database returns database settings func Database() (*models.Database, error) { database := &models.Database{} - database.Type = Ctl.GetString(backgroundCtx, common.DatabaseType) + database.Type = defaultMgr().Get(backgroundCtx, common.DatabaseType).GetString() postgresql := &models.PostGreSQL{ - Host: Ctl.GetString(backgroundCtx, common.PostGreSQLHOST), - Port: Ctl.GetInt(backgroundCtx, common.PostGreSQLPort), - Username: Ctl.GetString(backgroundCtx, common.PostGreSQLUsername), - Password: Ctl.GetString(backgroundCtx, common.PostGreSQLPassword), - Database: Ctl.GetString(backgroundCtx, common.PostGreSQLDatabase), - SSLMode: Ctl.GetString(backgroundCtx, common.PostGreSQLSSLMode), - MaxIdleConns: Ctl.GetInt(backgroundCtx, common.PostGreSQLMaxIdleConns), - MaxOpenConns: Ctl.GetInt(backgroundCtx, common.PostGreSQLMaxOpenConns), + Host: defaultMgr().Get(backgroundCtx, common.PostGreSQLHOST).GetString(), + Port: defaultMgr().Get(backgroundCtx, common.PostGreSQLPort).GetInt(), + Username: defaultMgr().Get(backgroundCtx, common.PostGreSQLUsername).GetString(), + Password: defaultMgr().Get(backgroundCtx, common.PostGreSQLPassword).GetPassword(), + Database: defaultMgr().Get(backgroundCtx, common.PostGreSQLDatabase).GetString(), + SSLMode: defaultMgr().Get(backgroundCtx, common.PostGreSQLSSLMode).GetString(), + MaxIdleConns: defaultMgr().Get(backgroundCtx, common.PostGreSQLMaxIdleConns).GetInt(), + MaxOpenConns: defaultMgr().Get(backgroundCtx, common.PostGreSQLMaxOpenConns).GetInt(), } database.PostGreSQL = postgresql diff --git a/src/controller/config/userconfig_test.go b/src/lib/config/test/userconfig_test.go similarity index 97% rename from src/controller/config/userconfig_test.go rename to src/lib/config/test/userconfig_test.go index da27ff8da..ef4c1935a 100644 --- a/src/controller/config/userconfig_test.go +++ b/src/lib/config/test/userconfig_test.go @@ -11,6 +11,7 @@ // 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 ( @@ -24,11 +25,17 @@ import ( "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/utils/test" + . "github.com/goharbor/harbor/src/lib/config" + _ "github.com/goharbor/harbor/src/pkg/config/db" _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "github.com/stretchr/testify/assert" ) -// test functions under package core/config +var ( + // defined as a var for testing. + defaultCACertPath = "/etc/core/ca/ca.crt" +) + func TestConfig(t *testing.T) { test.InitDatabaseFromEnv() dao.PrepareTestData([]string{"delete from properties where k='scan_all_policy'"}, []string{}) @@ -312,6 +319,6 @@ func TestSplitAndTrim(t *testing.T) { }, } for _, c := range cases { - assert.Equal(t, c.expect, splitAndTrim(c.s, c.sep)) + assert.Equal(t, c.expect, SplitAndTrim(c.s, c.sep)) } } diff --git a/src/lib/config/userconfig.go b/src/lib/config/userconfig.go new file mode 100644 index 000000000..163461d7f --- /dev/null +++ b/src/lib/config/userconfig.go @@ -0,0 +1,228 @@ +// 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 ( + "context" + "github.com/goharbor/harbor/src/common" + "github.com/goharbor/harbor/src/common/models" + cfgModels "github.com/goharbor/harbor/src/lib/config/models" + "github.com/goharbor/harbor/src/lib/errors" + "github.com/goharbor/harbor/src/lib/log" + "strings" +) + +// It contains all user related configurations, each of user related settings requires a context provided + +// GetSystemCfg returns the all configurations +func GetSystemCfg(ctx context.Context) (map[string]interface{}, error) { + sysCfg := defaultMgr().GetAll(ctx) + if len(sysCfg) == 0 { + return nil, errors.New("can not load system config, the database might be down") + } + return sysCfg, nil +} + +// AuthMode ... +func AuthMode(ctx context.Context) (string, error) { + mgr := defaultMgr() + err := mgr.Load(ctx) + if err != nil { + log.Errorf("failed to load config, error %v", err) + return "db_auth", err + } + return mgr.Get(ctx, common.AUTHMode).GetString(), nil +} + +// LDAPConf returns the setting of ldap server +func LDAPConf(ctx context.Context) (*cfgModels.LdapConf, error) { + mgr := defaultMgr() + err := mgr.Load(ctx) + if err != nil { + return nil, err + } + return &cfgModels.LdapConf{ + URL: mgr.Get(ctx, common.LDAPURL).GetString(), + SearchDn: mgr.Get(ctx, common.LDAPSearchDN).GetString(), + SearchPassword: mgr.Get(ctx, common.LDAPSearchPwd).GetString(), + BaseDn: mgr.Get(ctx, common.LDAPBaseDN).GetString(), + UID: mgr.Get(ctx, common.LDAPUID).GetString(), + Filter: mgr.Get(ctx, common.LDAPFilter).GetString(), + Scope: mgr.Get(ctx, common.LDAPScope).GetInt(), + ConnectionTimeout: mgr.Get(ctx, common.LDAPTimeout).GetInt(), + VerifyCert: mgr.Get(ctx, common.LDAPVerifyCert).GetBool(), + }, nil +} + +// LDAPGroupConf returns the setting of ldap group search +func LDAPGroupConf(ctx context.Context) (*cfgModels.GroupConf, error) { + mgr := defaultMgr() + err := mgr.Load(ctx) + if err != nil { + return nil, err + } + return &cfgModels.GroupConf{ + BaseDN: mgr.Get(ctx, common.LDAPGroupBaseDN).GetString(), + Filter: mgr.Get(ctx, common.LDAPGroupSearchFilter).GetString(), + NameAttribute: mgr.Get(ctx, common.LDAPGroupAttributeName).GetString(), + SearchScope: mgr.Get(ctx, common.LDAPGroupSearchScope).GetInt(), + AdminDN: mgr.Get(ctx, common.LDAPGroupAdminDn).GetString(), + MembershipAttribute: mgr.Get(ctx, common.LDAPGroupMembershipAttribute).GetString(), + }, nil +} + +// TokenExpiration returns the token expiration time (in minute) +func TokenExpiration(ctx context.Context) (int, error) { + return defaultMgr().Get(ctx, common.TokenExpiration).GetInt(), nil +} + +// RobotTokenDuration returns the token expiration time of robot account (in minute) +func RobotTokenDuration(ctx context.Context) int { + return defaultMgr().Get(ctx, common.RobotTokenDuration).GetInt() +} + +// SelfRegistration returns the enablement of self registration +func SelfRegistration(ctx context.Context) (bool, error) { + return defaultMgr().Get(ctx, common.SelfRegistration).GetBool(), nil +} + +// OnlyAdminCreateProject returns the flag to restrict that only sys admin can create project +func OnlyAdminCreateProject(ctx context.Context) (bool, error) { + err := defaultMgr().Load(ctx) + if err != nil { + return true, err + } + return defaultMgr().Get(ctx, common.ProjectCreationRestriction).GetString() == common.ProCrtRestrAdmOnly, nil +} + +// Email returns email server settings +func Email(ctx context.Context) (*cfgModels.Email, error) { + mgr := defaultMgr() + err := mgr.Load(ctx) + if err != nil { + return nil, err + } + return &cfgModels.Email{ + Host: mgr.Get(ctx, common.EmailHost).GetString(), + Port: mgr.Get(ctx, common.EmailPort).GetInt(), + Username: mgr.Get(ctx, common.EmailUsername).GetString(), + Password: mgr.Get(ctx, common.EmailPassword).GetString(), + SSL: mgr.Get(ctx, common.EmailSSL).GetBool(), + From: mgr.Get(ctx, common.EmailFrom).GetString(), + Identity: mgr.Get(ctx, common.EmailIdentity).GetString(), + Insecure: mgr.Get(ctx, common.EmailInsecure).GetBool(), + }, nil +} + +// UAASettings returns the UAASettings to access UAA service. +func UAASettings(ctx context.Context) (*models.UAASettings, error) { + mgr := defaultMgr() + err := mgr.Load(ctx) + if err != nil { + return nil, err + } + us := &models.UAASettings{ + Endpoint: mgr.Get(ctx, common.UAAEndpoint).GetString(), + ClientID: mgr.Get(ctx, common.UAAClientID).GetString(), + ClientSecret: mgr.Get(ctx, common.UAAClientSecret).GetString(), + VerifyCert: mgr.Get(ctx, common.UAAVerifyCert).GetBool(), + } + return us, nil +} + +// ReadOnly returns a bool to indicates if Harbor is in read only mode. +func ReadOnly(ctx context.Context) bool { + return defaultMgr().Get(ctx, common.ReadOnly).GetBool() +} + +// HTTPAuthProxySetting returns the setting of HTTP Auth proxy. the settings are only meaningful when the auth_mode is +// set to http_auth +func HTTPAuthProxySetting(ctx context.Context) (*cfgModels.HTTPAuthProxy, error) { + mgr := defaultMgr() + if err := mgr.Load(ctx); err != nil { + return nil, err + } + return &cfgModels.HTTPAuthProxy{ + Endpoint: mgr.Get(ctx, common.HTTPAuthProxyEndpoint).GetString(), + TokenReviewEndpoint: mgr.Get(ctx, common.HTTPAuthProxyTokenReviewEndpoint).GetString(), + AdminGroups: SplitAndTrim(mgr.Get(ctx, common.HTTPAuthProxyAdminGroups).GetString(), ","), + AdminUsernames: SplitAndTrim(mgr.Get(ctx, common.HTTPAuthProxyAdminUsernames).GetString(), ","), + VerifyCert: mgr.Get(ctx, common.HTTPAuthProxyVerifyCert).GetBool(), + SkipSearch: mgr.Get(ctx, common.HTTPAuthProxySkipSearch).GetBool(), + ServerCertificate: mgr.Get(ctx, common.HTTPAuthProxyServerCertificate).GetString(), + }, nil +} + +// OIDCSetting returns the setting of OIDC provider, currently there's only one OIDC provider allowed for Harbor and it's +// only effective when auth_mode is set to oidc_auth +func OIDCSetting(ctx context.Context) (*cfgModels.OIDCSetting, error) { + mgr := defaultMgr() + if err := mgr.Load(ctx); err != nil { + return nil, err + } + scopeStr := mgr.Get(ctx, common.OIDCScope).GetString() + extEndpoint := strings.TrimSuffix(mgr.Get(nil, common.ExtEndpoint).GetString(), "/") + scope := SplitAndTrim(scopeStr, ",") + return &cfgModels.OIDCSetting{ + Name: mgr.Get(ctx, common.OIDCName).GetString(), + Endpoint: mgr.Get(ctx, common.OIDCEndpoint).GetString(), + VerifyCert: mgr.Get(ctx, common.OIDCVerifyCert).GetBool(), + AutoOnboard: mgr.Get(ctx, common.OIDCAutoOnboard).GetBool(), + ClientID: mgr.Get(ctx, common.OIDCCLientID).GetString(), + ClientSecret: mgr.Get(ctx, common.OIDCClientSecret).GetString(), + GroupsClaim: mgr.Get(ctx, common.OIDCGroupsClaim).GetString(), + AdminGroup: mgr.Get(ctx, common.OIDCAdminGroup).GetString(), + RedirectURL: extEndpoint + common.OIDCCallbackPath, + Scope: scope, + UserClaim: mgr.Get(ctx, common.OIDCUserClaim).GetString(), + ExtraRedirectParms: mgr.Get(ctx, common.OIDCExtraRedirectParms).GetStringToStringMap(), + }, nil +} + +// NotificationEnable returns a bool to indicates if notification enabled in harbor +func NotificationEnable(ctx context.Context) bool { + return defaultMgr().Get(ctx, common.NotificationEnable).GetBool() +} + +// QuotaPerProjectEnable returns a bool to indicates if quota per project enabled in harbor +func QuotaPerProjectEnable(ctx context.Context) bool { + return defaultMgr().Get(ctx, common.QuotaPerProjectEnable).GetBool() +} + +// QuotaSetting returns the setting of quota. +func QuotaSetting(ctx context.Context) (*cfgModels.QuotaSetting, error) { + if err := defaultMgr().Load(ctx); err != nil { + return nil, err + } + return &cfgModels.QuotaSetting{ + StoragePerProject: defaultMgr().Get(ctx, common.StoragePerProject).GetInt64(), + }, nil +} + +// RobotPrefix user defined robot name prefix. +func RobotPrefix(ctx context.Context) string { + return defaultMgr().Get(ctx, common.RobotNamePrefix).GetString() +} + +// SplitAndTrim ... +func SplitAndTrim(s, sep string) []string { + res := make([]string, 0) + for _, s := range strings.Split(s, sep) { + if e := strings.TrimSpace(s); len(e) > 0 { + res = append(res, e) + } + } + return res +} diff --git a/src/pkg/encrypt/encrypt.go b/src/lib/encrypt/encrypt.go similarity index 100% rename from src/pkg/encrypt/encrypt.go rename to src/lib/encrypt/encrypt.go diff --git a/src/pkg/encrypt/encrypt_test.go b/src/lib/encrypt/encrypt_test.go similarity index 100% rename from src/pkg/encrypt/encrypt_test.go rename to src/lib/encrypt/encrypt_test.go diff --git a/src/pkg/encrypt/keyprovider.go b/src/lib/encrypt/keyprovider.go similarity index 100% rename from src/pkg/encrypt/keyprovider.go rename to src/lib/encrypt/keyprovider.go diff --git a/src/pkg/encrypt/keyprovider_test.go b/src/lib/encrypt/keyprovider_test.go similarity index 100% rename from src/pkg/encrypt/keyprovider_test.go rename to src/lib/encrypt/keyprovider_test.go diff --git a/src/pkg/config/db/db.go b/src/pkg/config/db/db.go index a2a696887..b331ed10c 100644 --- a/src/pkg/config/db/db.go +++ b/src/pkg/config/db/db.go @@ -17,8 +17,8 @@ package db import ( "context" "github.com/goharbor/harbor/src/lib/config/models" + "github.com/goharbor/harbor/src/lib/encrypt" "github.com/goharbor/harbor/src/pkg/config/db/dao" - "github.com/goharbor/harbor/src/pkg/encrypt" "os" "github.com/goharbor/harbor/src/common/utils" diff --git a/src/pkg/config/manager.go b/src/pkg/config/manager.go index f8602ee97..fa8a99fa3 100644 --- a/src/pkg/config/manager.go +++ b/src/pkg/config/manager.go @@ -20,16 +20,12 @@ import ( "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/common/utils" - libCfg "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/config/metadata" "github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/pkg/config/store" "os" ) -// Manager ... -type Manager libCfg.Manager - // CfgManager ... Configure Manager type CfgManager struct { Store *store.ConfigStore diff --git a/src/pkg/ldap/ldap.go b/src/pkg/ldap/ldap.go index b5ce0b974..f8941e6ff 100644 --- a/src/pkg/ldap/ldap.go +++ b/src/pkg/ldap/ldap.go @@ -18,6 +18,7 @@ import ( "crypto/tls" "errors" "fmt" + "github.com/goharbor/harbor/src/lib/config/models" "github.com/goharbor/harbor/src/pkg/ldap/model" "net/url" "strconv" @@ -54,13 +55,13 @@ var ErrEmptyBaseDN = errors.New("empty base dn") // Session - define a LDAP session type Session struct { - basicCfg model.LdapConf - groupCfg model.GroupConf + basicCfg models.LdapConf + groupCfg models.GroupConf ldapConn *goldap.Conn } // NewSession create session with configs -func NewSession(basicCfg model.LdapConf, groupCfg model.GroupConf) *Session { +func NewSession(basicCfg models.LdapConf, groupCfg models.GroupConf) *Session { return &Session{ basicCfg: basicCfg, groupCfg: groupCfg, @@ -113,8 +114,8 @@ func formatURL(ldapURL string) (string, error) { } // TestConfig - test ldap session connection, out of the scope of normal session create/close -func TestConfig(ldapConfig model.LdapConf) (bool, error) { - ts := NewSession(ldapConfig, model.GroupConf{}) +func TestConfig(ldapConfig models.LdapConf) (bool, error) { + ts := NewSession(ldapConfig, models.GroupConf{}) if err := ts.Open(); err != nil { if goldap.IsErrorWithCode(err, goldap.ErrorNetwork) { return false, ErrLDAPServerTimeout diff --git a/src/pkg/ldap/ldap_test.go b/src/pkg/ldap/ldap_test.go index 6f1b4836f..045d9f2f2 100644 --- a/src/pkg/ldap/ldap_test.go +++ b/src/pkg/ldap/ldap_test.go @@ -17,6 +17,7 @@ package ldap import ( "context" goldap "github.com/go-ldap/ldap/v3" + "github.com/goharbor/harbor/src/lib/config/models" "github.com/goharbor/harbor/src/pkg/ldap/model" "github.com/stretchr/testify/assert" "reflect" @@ -25,7 +26,7 @@ import ( "testing" ) -var ldapCfg = model.LdapConf{ +var ldapCfg = models.LdapConf{ URL: "ldap://127.0.0.1", SearchDn: "cn=admin,dc=example,dc=com", SearchPassword: "admin", @@ -35,7 +36,7 @@ var ldapCfg = model.LdapConf{ ConnectionTimeout: 30, } -var groupCfg = model.GroupConf{ +var groupCfg = models.GroupConf{ BaseDN: "dc=example,dc=com", NameAttribute: "cn", SearchScope: 2, @@ -149,7 +150,7 @@ func Test_createGroupSearchFilter(t *testing.T) { func TestSession_SearchGroup(t *testing.T) { type fields struct { - ldapConfig model.LdapConf + ldapConfig models.LdapConf ldapConn *goldap.Conn } type args struct { @@ -159,7 +160,7 @@ func TestSession_SearchGroup(t *testing.T) { groupNameAttribute string } - ldapConfig := model.LdapConf{ + ldapConfig := models.LdapConf{ URL: "ldap://127.0.0.1:389", SearchDn: "cn=admin,dc=example,dc=com", Scope: 2, @@ -200,31 +201,31 @@ func TestSession_SearchGroup(t *testing.T) { } func TestSession_SearchGroupByDN(t *testing.T) { - ldapGroupConfig := model.GroupConf{ + ldapGroupConfig := models.GroupConf{ BaseDN: "dc=example,dc=com", Filter: "objectclass=groupOfNames", NameAttribute: "cn", SearchScope: 2, } - ldapGroupConfig2 := model.GroupConf{ + ldapGroupConfig2 := models.GroupConf{ BaseDN: "dc=example,dc=com", Filter: "objectclass=groupOfNames", NameAttribute: "o", SearchScope: 2, } - groupConfigWithEmptyBaseDN := model.GroupConf{ + groupConfigWithEmptyBaseDN := models.GroupConf{ BaseDN: "", Filter: "(objectclass=groupOfNames)", NameAttribute: "cn", SearchScope: 2, } - groupConfigWithFilter := model.GroupConf{ + groupConfigWithFilter := models.GroupConf{ BaseDN: "dc=example,dc=com", Filter: "(cn=*admin*)", NameAttribute: "cn", SearchScope: 2, } - groupConfigWithDifferentGroupDN := model.GroupConf{ + groupConfigWithDifferentGroupDN := models.GroupConf{ BaseDN: "dc=harbor,dc=example,dc=com", Filter: "(objectclass=groupOfNames)", NameAttribute: "cn", @@ -232,8 +233,8 @@ func TestSession_SearchGroupByDN(t *testing.T) { } type fields struct { - ldapConfig model.LdapConf - ldapGroupConfig model.GroupConf + ldapConfig models.LdapConf + ldapGroupConfig models.GroupConf ldapConn *goldap.Conn } type args struct { @@ -309,25 +310,25 @@ func TestSession_SearchGroupByDN(t *testing.T) { } func TestSession_SearchGroupByName(t *testing.T) { - ldapGroupConfig := model.GroupConf{ + ldapGroupConfig := models.GroupConf{ BaseDN: "dc=example,dc=com", Filter: "objectclass=groupOfNames", NameAttribute: "cn", SearchScope: 2, } - ldapGroupConfig2 := model.GroupConf{ + ldapGroupConfig2 := models.GroupConf{ BaseDN: "dc=example,dc=com", Filter: "objectclass=groupOfNames", NameAttribute: "o", SearchScope: 2, } - groupConfigWithFilter := model.GroupConf{ + groupConfigWithFilter := models.GroupConf{ BaseDN: "dc=example,dc=com", Filter: "(cn=*admin*)", NameAttribute: "cn", SearchScope: 2, } - groupConfigWithDifferentGroupDN := model.GroupConf{ + groupConfigWithDifferentGroupDN := models.GroupConf{ BaseDN: "dc=harbor,dc=example,dc=com", Filter: "(objectclass=groupOfNames)", NameAttribute: "cn", @@ -335,8 +336,8 @@ func TestSession_SearchGroupByName(t *testing.T) { } type fields struct { - ldapConfig model.LdapConf - ldapGroupConfig model.GroupConf + ldapConfig models.LdapConf + ldapGroupConfig models.GroupConf ldapConn *goldap.Conn } type args struct { diff --git a/src/pkg/ldap/manager.go b/src/pkg/ldap/manager.go index fc2fbf906..77418d254 100644 --- a/src/pkg/ldap/manager.go +++ b/src/pkg/ldap/manager.go @@ -6,6 +6,7 @@ import ( goldap "github.com/go-ldap/ldap/v3" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/core/auth" + cfgModels "github.com/goharbor/harbor/src/lib/config/models" "github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/pkg/ldap/model" ) @@ -18,7 +19,7 @@ var ( // Manager is used for ldap management type Manager interface { // Ping ldap test - Ping(ctx context.Context, cfg model.LdapConf) (bool, error) + Ping(ctx context.Context, cfg cfgModels.LdapConf) (bool, error) SearchUser(ctx context.Context, sess *Session, username string) ([]model.User, error) ImportUser(ctx context.Context, sess *Session, ldapImportUsers []string) ([]model.FailedImportUser, error) SearchGroup(ctx context.Context, sess *Session, groupName, groupDN string) ([]model.Group, error) @@ -32,7 +33,7 @@ func New() Manager { type manager struct { } -func (m *manager) Ping(ctx context.Context, cfg model.LdapConf) (bool, error) { +func (m *manager) Ping(ctx context.Context, cfg cfgModels.LdapConf) (bool, error) { return TestConfig(cfg) } diff --git a/src/pkg/ldap/manager_test.go b/src/pkg/ldap/manager_test.go index e1cf28bcb..04db6824e 100644 --- a/src/pkg/ldap/manager_test.go +++ b/src/pkg/ldap/manager_test.go @@ -15,6 +15,8 @@ package ldap import ( + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" htesting "github.com/goharbor/harbor/src/testing" "github.com/stretchr/testify/suite" "testing" diff --git a/src/pkg/ldap/model/ldap.go b/src/pkg/ldap/model/ldap.go index ee899add2..89ae1ef44 100644 --- a/src/pkg/ldap/model/ldap.go +++ b/src/pkg/ldap/model/ldap.go @@ -14,29 +14,6 @@ package model -// LdapConf holds information about ldap configuration -type LdapConf struct { - URL string `json:"ldap_url"` - SearchDn string `json:"ldap_search_dn"` - SearchPassword string `json:"ldap_search_password"` - BaseDn string `json:"ldap_base_dn"` - Filter string `json:"ldap_filter"` - UID string `json:"ldap_uid"` - Scope int `json:"ldap_scope"` - ConnectionTimeout int `json:"ldap_connection_timeout"` - VerifyCert bool `json:"ldap_verify_cert"` -} - -// GroupConf holds information about ldap group -type GroupConf struct { - BaseDN string `json:"ldap_group_base_dn,omitempty"` - Filter string `json:"ldap_group_filter,omitempty"` - NameAttribute string `json:"ldap_group_name_attribute,omitempty"` - SearchScope int `json:"ldap_group_search_scope"` - AdminDN string `json:"ldap_group_admin_dn,omitempty"` - MembershipAttribute string `json:"ldap_group_membership_attribute,omitempty"` -} - // User ... type User struct { Username string `json:"ldap_username"` diff --git a/src/pkg/notification/hook/hook.go b/src/pkg/notification/hook/hook.go index 06cd5fdb8..d9699e2a3 100755 --- a/src/pkg/notification/hook/hook.go +++ b/src/pkg/notification/hook/hook.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "time" cJob "github.com/goharbor/harbor/src/common/job" diff --git a/src/pkg/oidc/helper.go b/src/pkg/oidc/helper.go index 8749895b4..056fdf035 100644 --- a/src/pkg/oidc/helper.go +++ b/src/pkg/oidc/helper.go @@ -25,7 +25,7 @@ import ( "sync/atomic" "time" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" cfgModels "github.com/goharbor/harbor/src/lib/config/models" "github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/pkg/usergroup" diff --git a/src/pkg/oidc/helper_test.go b/src/pkg/oidc/helper_test.go index 19882f81f..cdf3e57c5 100644 --- a/src/pkg/oidc/helper_test.go +++ b/src/pkg/oidc/helper_test.go @@ -17,10 +17,12 @@ package oidc import ( "encoding/json" "github.com/goharbor/harbor/src/common/utils/test" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" cfgModels "github.com/goharbor/harbor/src/lib/config/models" + "github.com/goharbor/harbor/src/lib/encrypt" "github.com/goharbor/harbor/src/lib/orm" - "github.com/goharbor/harbor/src/pkg/encrypt" + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "net/url" "os" "strings" diff --git a/src/pkg/oidc/secret.go b/src/pkg/oidc/secret.go index 8bfefe7dc..fd81feac5 100644 --- a/src/pkg/oidc/secret.go +++ b/src/pkg/oidc/secret.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "sync" "github.com/goharbor/harbor/src/common/dao" diff --git a/src/pkg/reg/manager.go b/src/pkg/reg/manager.go index 14ab2d831..7f378172b 100644 --- a/src/pkg/reg/manager.go +++ b/src/pkg/reg/manager.go @@ -17,7 +17,7 @@ package reg import ( "context" commonthttp "github.com/goharbor/harbor/src/common/http" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" // register the Harbor adapter _ "github.com/goharbor/harbor/src/pkg/reg/adapter/harbor" diff --git a/src/pkg/registry/client.go b/src/pkg/registry/client.go index dbbf7332d..5acbab838 100644 --- a/src/pkg/registry/client.go +++ b/src/pkg/registry/client.go @@ -18,7 +18,7 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "io" "io/ioutil" "net/http" diff --git a/src/pkg/signature/manager.go b/src/pkg/signature/manager.go index df9664f6a..ac5cf4dd0 100644 --- a/src/pkg/signature/manager.go +++ b/src/pkg/signature/manager.go @@ -16,7 +16,7 @@ package signature import ( "github.com/goharbor/harbor/src/common/security" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/pkg/signature/notary" "github.com/goharbor/harbor/src/pkg/signature/notary/model" diff --git a/src/pkg/signature/manager_test.go b/src/pkg/signature/manager_test.go index 6f3ecc44a..f57b95a22 100644 --- a/src/pkg/signature/manager_test.go +++ b/src/pkg/signature/manager_test.go @@ -3,7 +3,9 @@ package signature import ( "github.com/goharbor/harbor/src/common" testutils "github.com/goharbor/harbor/src/common/utils/test" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "github.com/goharbor/harbor/src/pkg/signature/notary/test" "github.com/stretchr/testify/assert" "golang.org/x/net/context" diff --git a/src/pkg/signature/notary/helper.go b/src/pkg/signature/notary/helper.go index eac7c5b03..dfd8f3cf8 100644 --- a/src/pkg/signature/notary/helper.go +++ b/src/pkg/signature/notary/helper.go @@ -18,7 +18,7 @@ import ( "context" "encoding/hex" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "net/http" "os" "path" diff --git a/src/pkg/signature/notary/helper_test.go b/src/pkg/signature/notary/helper_test.go index 53ca70d0a..1807642b7 100644 --- a/src/pkg/signature/notary/helper_test.go +++ b/src/pkg/signature/notary/helper_test.go @@ -16,8 +16,10 @@ package notary import ( "encoding/json" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" model2 "github.com/goharbor/harbor/src/pkg/signature/notary/model" test2 "github.com/goharbor/harbor/src/pkg/signature/notary/test" diff --git a/src/pkg/task/task.go b/src/pkg/task/task.go index b5a1b2e96..4b82ce2cd 100644 --- a/src/pkg/task/task.go +++ b/src/pkg/task/task.go @@ -18,7 +18,7 @@ import ( "context" "encoding/json" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "time" cjob "github.com/goharbor/harbor/src/common/job" diff --git a/src/pkg/token/options.go b/src/pkg/token/options.go index 4058f913d..d498a68dd 100644 --- a/src/pkg/token/options.go +++ b/src/pkg/token/options.go @@ -3,7 +3,7 @@ package token import ( "crypto/rsa" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "io/ioutil" "github.com/dgrijalva/jwt-go" diff --git a/src/pkg/token/token_test.go b/src/pkg/token/token_test.go index 8e975ab85..5add92b92 100644 --- a/src/pkg/token/token_test.go +++ b/src/pkg/token/token_test.go @@ -1,7 +1,7 @@ package token import ( - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "os" "testing" "time" diff --git a/src/server/middleware/blob/head_blob.go b/src/server/middleware/blob/head_blob.go index 8079dd8ee..06fe21d2f 100644 --- a/src/server/middleware/blob/head_blob.go +++ b/src/server/middleware/blob/head_blob.go @@ -3,8 +3,8 @@ package blob import ( "fmt" "github.com/goharbor/harbor/src/controller/blob" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/lib" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/errors" lib_http "github.com/goharbor/harbor/src/lib/http" "github.com/goharbor/harbor/src/lib/log" diff --git a/src/server/middleware/blob/util.go b/src/server/middleware/blob/util.go index b77b4f1da..8fb7e7d5d 100644 --- a/src/server/middleware/blob/util.go +++ b/src/server/middleware/blob/util.go @@ -3,7 +3,7 @@ package blob import ( "fmt" "github.com/goharbor/harbor/src/controller/blob" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/pkg/blob/models" diff --git a/src/server/middleware/csrf/csrf.go b/src/server/middleware/csrf/csrf.go index 62f71d9a3..b96bf5f5e 100644 --- a/src/server/middleware/csrf/csrf.go +++ b/src/server/middleware/csrf/csrf.go @@ -1,7 +1,7 @@ package csrf import ( - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" lib_http "github.com/goharbor/harbor/src/lib/http" "net/http" "os" diff --git a/src/server/middleware/csrf/csrf_test.go b/src/server/middleware/csrf/csrf_test.go index c87f7065b..180600843 100644 --- a/src/server/middleware/csrf/csrf_test.go +++ b/src/server/middleware/csrf/csrf_test.go @@ -3,7 +3,8 @@ package csrf import ( "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/utils/test" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "github.com/stretchr/testify/assert" "net/http" "net/http/httptest" diff --git a/src/server/middleware/metric/metric.go b/src/server/middleware/metric/metric.go index 2478c074f..9d7c7f27d 100644 --- a/src/server/middleware/metric/metric.go +++ b/src/server/middleware/metric/metric.go @@ -2,7 +2,7 @@ package metric import ( "context" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "net/http" "strconv" "strings" diff --git a/src/server/middleware/readonly/readonly.go b/src/server/middleware/readonly/readonly.go index ec05f49bf..cfa5d26a9 100644 --- a/src/server/middleware/readonly/readonly.go +++ b/src/server/middleware/readonly/readonly.go @@ -15,7 +15,7 @@ package readonly import ( - config "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" lib_http "github.com/goharbor/harbor/src/lib/http" "github.com/goharbor/harbor/src/lib/orm" "net/http" diff --git a/src/server/middleware/security/auth_proxy.go b/src/server/middleware/security/auth_proxy.go index 74fa2745e..5c06c8529 100644 --- a/src/server/middleware/security/auth_proxy.go +++ b/src/server/middleware/security/auth_proxy.go @@ -15,7 +15,7 @@ package security import ( - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "net/http" "strings" diff --git a/src/server/middleware/security/auth_proxy_test.go b/src/server/middleware/security/auth_proxy_test.go index ad92951ae..cef78f685 100644 --- a/src/server/middleware/security/auth_proxy_test.go +++ b/src/server/middleware/security/auth_proxy_test.go @@ -19,11 +19,13 @@ import ( "fmt" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/utils/test" - "github.com/goharbor/harbor/src/controller/config" _ "github.com/goharbor/harbor/src/core/auth/authproxy" "github.com/goharbor/harbor/src/lib" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/config/models" "github.com/goharbor/harbor/src/lib/orm" + _ "github.com/goharbor/harbor/src/pkg/config/db" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "io/ioutil" diff --git a/src/server/middleware/security/idtoken.go b/src/server/middleware/security/idtoken.go index 918124fb4..9444852bb 100644 --- a/src/server/middleware/security/idtoken.go +++ b/src/server/middleware/security/idtoken.go @@ -15,7 +15,7 @@ package security import ( - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "net/http" "strings" diff --git a/src/server/middleware/security/robot2.go b/src/server/middleware/security/robot2.go index ae4ceaf5b..accd18dda 100644 --- a/src/server/middleware/security/robot2.go +++ b/src/server/middleware/security/robot2.go @@ -5,8 +5,8 @@ import ( "github.com/goharbor/harbor/src/common/security" robotCtx "github.com/goharbor/harbor/src/common/security/robot" "github.com/goharbor/harbor/src/common/utils" - "github.com/goharbor/harbor/src/controller/config" robot_ctl "github.com/goharbor/harbor/src/controller/robot" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/lib/q" "github.com/goharbor/harbor/src/pkg/permission/types" diff --git a/src/server/middleware/security/robot2_test.go b/src/server/middleware/security/robot2_test.go index a36195068..134bce2c2 100644 --- a/src/server/middleware/security/robot2_test.go +++ b/src/server/middleware/security/robot2_test.go @@ -2,7 +2,7 @@ package security import ( "github.com/goharbor/harbor/src/common" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "net/http" diff --git a/src/server/middleware/security/secret.go b/src/server/middleware/security/secret.go index a2a7c85e8..e839e5f75 100644 --- a/src/server/middleware/security/secret.go +++ b/src/server/middleware/security/secret.go @@ -15,7 +15,7 @@ package security import ( - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "net/http" commonsecret "github.com/goharbor/harbor/src/common/secret" diff --git a/src/server/middleware/security/security.go b/src/server/middleware/security/security.go index 60c99814b..f436373a7 100644 --- a/src/server/middleware/security/security.go +++ b/src/server/middleware/security/security.go @@ -15,7 +15,7 @@ package security import ( - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "net/http" diff --git a/src/server/middleware/security/v2_token_test.go b/src/server/middleware/security/v2_token_test.go index 63ee3c74c..25d492d9d 100644 --- a/src/server/middleware/security/v2_token_test.go +++ b/src/server/middleware/security/v2_token_test.go @@ -2,7 +2,7 @@ package security import ( "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/orm" "net/http" "testing" diff --git a/src/server/middleware/session/session.go b/src/server/middleware/session/session.go index 4c9e9046b..c3447a059 100644 --- a/src/server/middleware/session/session.go +++ b/src/server/middleware/session/session.go @@ -15,8 +15,8 @@ package session import ( - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/lib" + "github.com/goharbor/harbor/src/lib/config" "net/http" ) diff --git a/src/server/middleware/session/session_test.go b/src/server/middleware/session/session_test.go index 683083ca7..775c0ad88 100644 --- a/src/server/middleware/session/session_test.go +++ b/src/server/middleware/session/session_test.go @@ -17,8 +17,8 @@ package session import ( "github.com/astaxie/beego" beegosession "github.com/astaxie/beego/session" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/lib" + "github.com/goharbor/harbor/src/lib/config" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "net/http" diff --git a/src/server/middleware/v2auth/auth.go b/src/server/middleware/v2auth/auth.go index 7edf12878..d6d24ed63 100644 --- a/src/server/middleware/v2auth/auth.go +++ b/src/server/middleware/v2auth/auth.go @@ -19,7 +19,7 @@ import ( "fmt" rbac_project "github.com/goharbor/harbor/src/common/rbac/project" "github.com/goharbor/harbor/src/common/rbac/system" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "net/http" "net/url" "strings" diff --git a/src/server/middleware/v2auth/auth_test.go b/src/server/middleware/v2auth/auth_test.go index 564a70b37..9fcdcc7e8 100644 --- a/src/server/middleware/v2auth/auth_test.go +++ b/src/server/middleware/v2auth/auth_test.go @@ -18,7 +18,8 @@ import ( "context" "fmt" testutils "github.com/goharbor/harbor/src/common/utils/test" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" + "net/http" "net/http/httptest" "os" @@ -32,6 +33,7 @@ import ( "github.com/goharbor/harbor/src/common/security" "github.com/goharbor/harbor/src/controller/project" "github.com/goharbor/harbor/src/lib" + _ "github.com/goharbor/harbor/src/pkg/config/inmemory" "github.com/goharbor/harbor/src/pkg/permission/types" securitytesting "github.com/goharbor/harbor/src/testing/common/security" projecttesting "github.com/goharbor/harbor/src/testing/controller/project" diff --git a/src/server/registry/proxy.go b/src/server/registry/proxy.go index 67fcd8a33..4b59d8fc4 100644 --- a/src/server/registry/proxy.go +++ b/src/server/registry/proxy.go @@ -16,7 +16,7 @@ package registry import ( "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "net/http" "net/http/httputil" "net/url" diff --git a/src/server/route.go b/src/server/route.go index 4f00364c8..5e73943d4 100644 --- a/src/server/route.go +++ b/src/server/route.go @@ -15,7 +15,7 @@ package server import ( - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "net/http" "github.com/astaxie/beego" diff --git a/src/server/v2.0/handler/config.go b/src/server/v2.0/handler/config.go index 7fc6dd416..11e423b7b 100644 --- a/src/server/v2.0/handler/config.go +++ b/src/server/v2.0/handler/config.go @@ -21,7 +21,7 @@ import ( "github.com/goharbor/harbor/src/common/rbac" "github.com/goharbor/harbor/src/common/security" "github.com/goharbor/harbor/src/controller/config" - libCfg "github.com/goharbor/harbor/src/lib/config" + cfgModels "github.com/goharbor/harbor/src/lib/config/models" "github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/server/v2.0/models" "github.com/goharbor/harbor/src/server/v2.0/restapi/operations/configure" @@ -97,7 +97,7 @@ func (c *configAPI) GetInternalconfig(ctx context.Context, params configure.GetI return configure.NewGetInternalconfigOK().WithPayload(resultCfg) } -func toResponseModel(cfg map[string]*libCfg.Value) (*models.ConfigurationsResponse, error) { +func toResponseModel(cfg map[string]*cfgModels.Value) (*models.ConfigurationsResponse, error) { var result []byte result, err := json.Marshal(cfg) if err != nil { diff --git a/src/server/v2.0/handler/gc.go b/src/server/v2.0/handler/gc.go index 5f74237bf..762c44842 100644 --- a/src/server/v2.0/handler/gc.go +++ b/src/server/v2.0/handler/gc.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "os" "strings" diff --git a/src/server/v2.0/handler/ldap.go b/src/server/v2.0/handler/ldap.go index f4216fd01..a6898d42b 100644 --- a/src/server/v2.0/handler/ldap.go +++ b/src/server/v2.0/handler/ldap.go @@ -6,6 +6,7 @@ import ( "github.com/go-openapi/runtime/middleware" "github.com/goharbor/harbor/src/common/rbac" "github.com/goharbor/harbor/src/controller/ldap" + cfgModels "github.com/goharbor/harbor/src/lib/config/models" "github.com/goharbor/harbor/src/lib/errors" ldapModel "github.com/goharbor/harbor/src/pkg/ldap/model" "github.com/goharbor/harbor/src/server/v2.0/models" @@ -25,7 +26,7 @@ func (l *ldapAPI) PingLdap(ctx context.Context, params operation.PingLdapParams) if err := l.RequireSystemAccess(ctx, rbac.ActionRead, rbac.ResourceConfiguration); err != nil { return l.SendError(ctx, err) } - basicCfg := ldapModel.LdapConf{ + basicCfg := cfgModels.LdapConf{ URL: params.Ldapconf.LdapURL, BaseDn: params.Ldapconf.LdapBaseDn, SearchDn: params.Ldapconf.LdapSearchDn, diff --git a/src/server/v2.0/handler/project.go b/src/server/v2.0/handler/project.go index 7ff8db799..25fc0eb48 100644 --- a/src/server/v2.0/handler/project.go +++ b/src/server/v2.0/handler/project.go @@ -17,11 +17,11 @@ package handler import ( "context" "fmt" + "github.com/goharbor/harbor/src/lib/config" "strconv" "strings" "sync" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/pkg/member" "github.com/go-openapi/runtime/middleware" diff --git a/src/server/v2.0/handler/robot.go b/src/server/v2.0/handler/robot.go index 5487b71e7..27a8d447d 100644 --- a/src/server/v2.0/handler/robot.go +++ b/src/server/v2.0/handler/robot.go @@ -7,9 +7,9 @@ import ( "github.com/go-openapi/strfmt" "github.com/goharbor/harbor/src/common/rbac" "github.com/goharbor/harbor/src/common/utils" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/controller/robot" "github.com/goharbor/harbor/src/lib" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/errors" pkg "github.com/goharbor/harbor/src/pkg/robot/model" "github.com/goharbor/harbor/src/server/v2.0/handler/model" diff --git a/src/server/v2.0/handler/search.go b/src/server/v2.0/handler/search.go index b736b101a..f28b0b45f 100644 --- a/src/server/v2.0/handler/search.go +++ b/src/server/v2.0/handler/search.go @@ -26,11 +26,11 @@ import ( "github.com/goharbor/harbor/src/common/security/local" "github.com/goharbor/harbor/src/common/utils" "github.com/goharbor/harbor/src/controller/artifact" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/controller/project" "github.com/goharbor/harbor/src/controller/repository" "github.com/goharbor/harbor/src/core/api" "github.com/goharbor/harbor/src/lib" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/lib/q" diff --git a/src/server/v2.0/handler/user.go b/src/server/v2.0/handler/user.go index 78ee9dbab..0442c1573 100644 --- a/src/server/v2.0/handler/user.go +++ b/src/server/v2.0/handler/user.go @@ -27,9 +27,9 @@ import ( "github.com/goharbor/harbor/src/common/security" "github.com/goharbor/harbor/src/common/security/local" "github.com/goharbor/harbor/src/common/utils" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/controller/user" "github.com/goharbor/harbor/src/lib" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/lib/q" diff --git a/src/server/v2.0/handler/usergroup.go b/src/server/v2.0/handler/usergroup.go index e8d68ee0a..34e61e0b7 100644 --- a/src/server/v2.0/handler/usergroup.go +++ b/src/server/v2.0/handler/usergroup.go @@ -20,8 +20,8 @@ import ( "github.com/go-openapi/runtime/middleware" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/rbac" - "github.com/goharbor/harbor/src/controller/config" ugCtl "github.com/goharbor/harbor/src/controller/usergroup" + "github.com/goharbor/harbor/src/lib/config" "github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/pkg/usergroup/model" "github.com/goharbor/harbor/src/server/v2.0/models" diff --git a/src/server/v2.0/route/legacy.go b/src/server/v2.0/route/legacy.go index cb22218a7..d8ac5528d 100755 --- a/src/server/v2.0/route/legacy.go +++ b/src/server/v2.0/route/legacy.go @@ -16,8 +16,8 @@ package route import ( "github.com/astaxie/beego" - "github.com/goharbor/harbor/src/controller/config" "github.com/goharbor/harbor/src/core/api" + "github.com/goharbor/harbor/src/lib/config" ) // RegisterRoutes for Harbor legacy APIs diff --git a/src/testing/controller/config/controller.go b/src/testing/controller/config/controller.go index 61259ce90..34526c2d5 100644 --- a/src/testing/controller/config/controller.go +++ b/src/testing/controller/config/controller.go @@ -5,9 +5,7 @@ package config import ( context "context" - libconfig "github.com/goharbor/harbor/src/lib/config" - metadata "github.com/goharbor/harbor/src/lib/config/metadata" - + models "github.com/goharbor/harbor/src/lib/config/models" mock "github.com/stretchr/testify/mock" ) @@ -39,94 +37,6 @@ func (_m *Controller) AllConfigs(ctx context.Context) (map[string]interface{}, e return r0, r1 } -// Get provides a mock function with given fields: ctx, item -func (_m *Controller) Get(ctx context.Context, item string) *metadata.ConfigureValue { - ret := _m.Called(ctx, item) - - var r0 *metadata.ConfigureValue - if rf, ok := ret.Get(0).(func(context.Context, string) *metadata.ConfigureValue); ok { - r0 = rf(ctx, item) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*metadata.ConfigureValue) - } - } - - return r0 -} - -// GetBool provides a mock function with given fields: ctx, item -func (_m *Controller) GetBool(ctx context.Context, item string) bool { - ret := _m.Called(ctx, item) - - var r0 bool - if rf, ok := ret.Get(0).(func(context.Context, string) bool); ok { - r0 = rf(ctx, item) - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// GetInt provides a mock function with given fields: ctx, item -func (_m *Controller) GetInt(ctx context.Context, item string) int { - ret := _m.Called(ctx, item) - - var r0 int - if rf, ok := ret.Get(0).(func(context.Context, string) int); ok { - r0 = rf(ctx, item) - } else { - r0 = ret.Get(0).(int) - } - - return r0 -} - -// GetManager provides a mock function with given fields: -func (_m *Controller) GetManager() libconfig.Manager { - ret := _m.Called() - - var r0 libconfig.Manager - if rf, ok := ret.Get(0).(func() libconfig.Manager); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(libconfig.Manager) - } - } - - return r0 -} - -// GetString provides a mock function with given fields: ctx, item -func (_m *Controller) GetString(ctx context.Context, item string) string { - ret := _m.Called(ctx, item) - - var r0 string - if rf, ok := ret.Get(0).(func(context.Context, string) string); ok { - r0 = rf(ctx, item) - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// Load provides a mock function with given fields: ctx -func (_m *Controller) Load(ctx context.Context) error { - ret := _m.Called(ctx) - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context) error); ok { - r0 = rf(ctx) - } else { - r0 = ret.Error(0) - } - - return r0 -} - // UpdateUserConfigs provides a mock function with given fields: ctx, conf func (_m *Controller) UpdateUserConfigs(ctx context.Context, conf map[string]interface{}) error { ret := _m.Called(ctx, conf) @@ -142,15 +52,15 @@ func (_m *Controller) UpdateUserConfigs(ctx context.Context, conf map[string]int } // UserConfigs provides a mock function with given fields: ctx -func (_m *Controller) UserConfigs(ctx context.Context) (map[string]*libconfig.Value, error) { +func (_m *Controller) UserConfigs(ctx context.Context) (map[string]*models.Value, error) { ret := _m.Called(ctx) - var r0 map[string]*libconfig.Value - if rf, ok := ret.Get(0).(func(context.Context) map[string]*libconfig.Value); ok { + var r0 map[string]*models.Value + if rf, ok := ret.Get(0).(func(context.Context) map[string]*models.Value); ok { r0 = rf(ctx) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(map[string]*libconfig.Value) + r0 = ret.Get(0).(map[string]*models.Value) } } diff --git a/src/testing/pkg/ldap/manager.go b/src/testing/pkg/ldap/manager.go index 991cf5ee7..2d79817b4 100644 --- a/src/testing/pkg/ldap/manager.go +++ b/src/testing/pkg/ldap/manager.go @@ -9,6 +9,8 @@ import ( mock "github.com/stretchr/testify/mock" model "github.com/goharbor/harbor/src/pkg/ldap/model" + + models "github.com/goharbor/harbor/src/lib/config/models" ) // Manager is an autogenerated mock type for the Manager type @@ -40,18 +42,18 @@ func (_m *Manager) ImportUser(ctx context.Context, sess *ldap.Session, ldapImpor } // Ping provides a mock function with given fields: ctx, cfg -func (_m *Manager) Ping(ctx context.Context, cfg model.LdapConf) (bool, error) { +func (_m *Manager) Ping(ctx context.Context, cfg models.LdapConf) (bool, error) { ret := _m.Called(ctx, cfg) var r0 bool - if rf, ok := ret.Get(0).(func(context.Context, model.LdapConf) bool); ok { + if rf, ok := ret.Get(0).(func(context.Context, models.LdapConf) bool); ok { r0 = rf(ctx, cfg) } else { r0 = ret.Get(0).(bool) } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, model.LdapConf) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, models.LdapConf) error); ok { r1 = rf(ctx, cfg) } else { r1 = ret.Error(1) diff --git a/src/testing/suite.go b/src/testing/suite.go index 6e02394d6..832179adb 100644 --- a/src/testing/suite.go +++ b/src/testing/suite.go @@ -16,7 +16,7 @@ package testing import ( "context" - "github.com/goharbor/harbor/src/controller/config" + "github.com/goharbor/harbor/src/lib/config" "io" "math/rand" "net/http"