mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-16 20:01:35 +01:00
Merge pull request #14635 from stonezdj/21apr13_move_config_exp
Move common config api to lib/config
This commit is contained in:
commit
d1426fb0c5
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
}
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/goharbor/harbor/src/controller/config"
|
||||
"github.com/goharbor/harbor/src/lib/config"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
@ -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"`
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
228
src/lib/config/userconfig.go
Normal file
228
src/lib/config/userconfig.go
Normal file
@ -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
|
||||
}
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"`
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package token
|
||||
|
||||
import (
|
||||
"github.com/goharbor/harbor/src/controller/config"
|
||||
"github.com/goharbor/harbor/src/lib/config"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -15,7 +15,7 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"github.com/goharbor/harbor/src/controller/config"
|
||||
"github.com/goharbor/harbor/src/lib/config"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user