From dc4f2ece722cac4c93dcb374306e60f9af332aee Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Wed, 20 Sep 2017 14:30:26 +0800 Subject: [PATCH] readjust package structure --- src/common/security/admiral/context.go | 6 ++--- src/common/security/local/context.go | 6 ++--- src/common/security/local/context_test.go | 4 +-- src/ui/api/base.go | 4 +-- src/ui/api/utils.go | 8 +++--- src/ui/config/config.go | 16 ++++++------ src/ui/filter/security.go | 26 +++++++++---------- src/ui/filter/security_test.go | 8 +++--- .../pmsdriver/admiral/admiral.go} | 2 +- .../pmsdriver/admiral/admiral_test.go} | 2 +- .../pms => promgr/pmsdriver/admiral}/token.go | 2 +- .../pmsdriver/admiral}/token_test.go | 2 +- .../pm.go => promgr/pmsdriver/local/local.go} | 2 +- .../pmsdriver/local/local_test.go} | 2 +- .../pm.go => promgr/promgr.go} | 6 ++--- src/ui/proxy/interceptor_test.go | 6 ++--- src/ui/proxy/interceptors.go | 6 ++--- src/ui/service/token/authutils.go | 4 +-- src/ui/service/token/creator.go | 8 +++--- 19 files changed, 60 insertions(+), 60 deletions(-) rename src/ui/{projectmanager/pms/pm.go => promgr/pmsdriver/admiral/admiral.go} (99%) rename src/ui/{projectmanager/pms/pm_test.go => promgr/pmsdriver/admiral/admiral_test.go} (99%) rename src/ui/{projectmanager/pms => promgr/pmsdriver/admiral}/token.go (98%) rename src/ui/{projectmanager/pms => promgr/pmsdriver/admiral}/token_test.go (98%) rename src/ui/{projectmanager/db/pm.go => promgr/pmsdriver/local/local.go} (99%) rename src/ui/{projectmanager/db/pm_test.go => promgr/pmsdriver/local/local_test.go} (99%) rename src/ui/{projectmanager/pm.go => promgr/promgr.go} (91%) diff --git a/src/common/security/admiral/context.go b/src/common/security/admiral/context.go index c10370c33..85e20a4de 100644 --- a/src/common/security/admiral/context.go +++ b/src/common/security/admiral/context.go @@ -19,18 +19,18 @@ import ( "github.com/vmware/harbor/src/common/models" "github.com/vmware/harbor/src/common/security/admiral/authcontext" "github.com/vmware/harbor/src/common/utils/log" - "github.com/vmware/harbor/src/ui/projectmanager" + "github.com/vmware/harbor/src/ui/promgr" ) // SecurityContext implements security.Context interface based on // auth context and project manager type SecurityContext struct { ctx *authcontext.AuthContext - pm projectmanager.ProjectManager + pm promgr.ProMgr } // NewSecurityContext ... -func NewSecurityContext(ctx *authcontext.AuthContext, pm projectmanager.ProjectManager) *SecurityContext { +func NewSecurityContext(ctx *authcontext.AuthContext, pm promgr.ProMgr) *SecurityContext { return &SecurityContext{ ctx: ctx, pm: pm, diff --git a/src/common/security/local/context.go b/src/common/security/local/context.go index a70cc989c..22ab07080 100644 --- a/src/common/security/local/context.go +++ b/src/common/security/local/context.go @@ -19,17 +19,17 @@ import ( "github.com/vmware/harbor/src/common/dao" "github.com/vmware/harbor/src/common/models" "github.com/vmware/harbor/src/common/utils/log" - "github.com/vmware/harbor/src/ui/projectmanager" + "github.com/vmware/harbor/src/ui/promgr" ) // SecurityContext implements security.Context interface based on database type SecurityContext struct { user *models.User - pm projectmanager.ProjectManager + pm promgr.ProMgr } // NewSecurityContext ... -func NewSecurityContext(user *models.User, pm projectmanager.ProjectManager) *SecurityContext { +func NewSecurityContext(user *models.User, pm promgr.ProMgr) *SecurityContext { return &SecurityContext{ user: user, pm: pm, diff --git a/src/common/security/local/context_test.go b/src/common/security/local/context_test.go index 742379f31..7e46a24cd 100644 --- a/src/common/security/local/context_test.go +++ b/src/common/security/local/context_test.go @@ -25,7 +25,7 @@ import ( "github.com/vmware/harbor/src/common/dao" "github.com/vmware/harbor/src/common/models" "github.com/vmware/harbor/src/common/utils/log" - "github.com/vmware/harbor/src/ui/projectmanager/db" + "github.com/vmware/harbor/src/ui/promgr/pmsdriver/local" ) var ( @@ -47,7 +47,7 @@ var ( Email: "guestUser@vmware.com", } - pm = &db.ProjectManager{} + pm = &local.ProjectManager{} ) func TestMain(m *testing.M) { diff --git a/src/ui/api/base.go b/src/ui/api/base.go index f33967926..5f567a355 100644 --- a/src/ui/api/base.go +++ b/src/ui/api/base.go @@ -21,7 +21,7 @@ import ( "github.com/vmware/harbor/src/common/security" "github.com/vmware/harbor/src/common/utils/log" "github.com/vmware/harbor/src/ui/filter" - "github.com/vmware/harbor/src/ui/projectmanager" + "github.com/vmware/harbor/src/ui/promgr" ) // BaseController ... @@ -31,7 +31,7 @@ type BaseController struct { SecurityCtx security.Context // ProjectMgr is the project manager which abstracts the operations // related to projects - ProjectMgr projectmanager.ProjectManager + ProjectMgr promgr.ProMgr } const ( diff --git a/src/ui/api/utils.go b/src/ui/api/utils.go index 0b9fd2047..bf9013289 100644 --- a/src/ui/api/utils.go +++ b/src/ui/api/utils.go @@ -33,7 +33,7 @@ import ( "github.com/vmware/harbor/src/common/utils/registry" "github.com/vmware/harbor/src/common/utils/registry/auth" "github.com/vmware/harbor/src/ui/config" - "github.com/vmware/harbor/src/ui/projectmanager" + "github.com/vmware/harbor/src/ui/promgr" "github.com/vmware/harbor/src/ui/service/token" uiutils "github.com/vmware/harbor/src/ui/utils" ) @@ -166,7 +166,7 @@ func postReplicationAction(policyID int64, acton string) error { } // SyncRegistry syncs the repositories of registry with database. -func SyncRegistry(pm projectmanager.ProjectManager) error { +func SyncRegistry(pm promgr.ProMgr) error { log.Infof("Start syncing repositories from registry to DB... ") @@ -254,7 +254,7 @@ func catalog() ([]string, error) { } func diffRepos(reposInRegistry []string, reposInDB []string, - pm projectmanager.ProjectManager) ([]string, []string, error) { + pm promgr.ProMgr) ([]string, []string, error) { var needsAdd []string var needsDel []string @@ -359,7 +359,7 @@ func diffRepos(reposInRegistry []string, reposInDB []string, return needsAdd, needsDel, nil } -func projectExists(pm projectmanager.ProjectManager, repository string) (bool, error) { +func projectExists(pm promgr.ProMgr, repository string) (bool, error) { project, _ := utils.ParseRepository(repository) return pm.Exist(project) } diff --git a/src/ui/config/config.go b/src/ui/config/config.go index 47aeabe8b..f1207b73c 100644 --- a/src/ui/config/config.go +++ b/src/ui/config/config.go @@ -29,9 +29,9 @@ import ( "github.com/vmware/harbor/src/common/models" "github.com/vmware/harbor/src/common/secret" "github.com/vmware/harbor/src/common/utils/log" - "github.com/vmware/harbor/src/ui/projectmanager" - "github.com/vmware/harbor/src/ui/projectmanager/db" - "github.com/vmware/harbor/src/ui/projectmanager/pms" + "github.com/vmware/harbor/src/ui/promgr" + "github.com/vmware/harbor/src/ui/promgr/pmsdriver/admiral" + "github.com/vmware/harbor/src/ui/promgr/pmsdriver/local" ) const ( @@ -46,14 +46,14 @@ var ( // AdminserverClient is a client for adminserver AdminserverClient client.Client // GlobalProjectMgr is initialized based on the deploy mode - GlobalProjectMgr projectmanager.ProjectManager + GlobalProjectMgr promgr.ProMgr mg *comcfg.Manager keyProvider comcfg.KeyProvider // AdmiralClient is initialized only under integration deploy mode // and can be passed to project manager as a parameter AdmiralClient *http.Client // TokenReader is used in integration mode to read token - TokenReader pms.TokenReader + TokenReader admiral.TokenReader ) // Init configurations @@ -108,7 +108,7 @@ func initProjectManager() { if !WithAdmiral() { // standalone log.Info("initializing the project manager based on database...") - GlobalProjectMgr = &db.ProjectManager{} + GlobalProjectMgr = &local.ProjectManager{} return } @@ -128,10 +128,10 @@ func initProjectManager() { path = defaultTokenFilePath } log.Infof("service token file path: %s", path) - TokenReader = &pms.FileTokenReader{ + TokenReader = &admiral.FileTokenReader{ Path: path, } - GlobalProjectMgr = pms.NewProjectManager(AdmiralClient, + GlobalProjectMgr = admiral.NewProjectManager(AdmiralClient, AdmiralEndpoint(), TokenReader) } diff --git a/src/ui/filter/security.go b/src/ui/filter/security.go index 9d92757ad..116298ce8 100644 --- a/src/ui/filter/security.go +++ b/src/ui/filter/security.go @@ -25,15 +25,15 @@ import ( "github.com/vmware/harbor/src/common/models" secstore "github.com/vmware/harbor/src/common/secret" "github.com/vmware/harbor/src/common/security" - "github.com/vmware/harbor/src/common/security/admiral" + admr "github.com/vmware/harbor/src/common/security/admiral" "github.com/vmware/harbor/src/common/security/admiral/authcontext" "github.com/vmware/harbor/src/common/security/local" "github.com/vmware/harbor/src/common/security/secret" "github.com/vmware/harbor/src/common/utils/log" "github.com/vmware/harbor/src/ui/auth" "github.com/vmware/harbor/src/ui/config" - "github.com/vmware/harbor/src/ui/projectmanager" - "github.com/vmware/harbor/src/ui/projectmanager/pms" + "github.com/vmware/harbor/src/ui/promgr" + "github.com/vmware/harbor/src/ui/promgr/pmsdriver/admiral" ) type key string @@ -192,7 +192,7 @@ func (b *basicAuthReqCtxModifier) Modify(ctx *beegoctx.Context) bool { log.Debug("using global project manager...") pm := config.GlobalProjectMgr log.Debug("creating admiral security context...") - securCtx := admiral.NewSecurityContext(authCtx, pm) + securCtx := admr.NewSecurityContext(authCtx, pm) setSecurCtxAndPM(ctx.Request, securCtx, pm) return true @@ -265,12 +265,12 @@ func (t *tokenReqCtxModifier) Modify(ctx *beegoctx.Context) bool { } log.Debug("creating PMS project manager...") - pm := pms.NewProjectManager(config.AdmiralClient, - config.AdmiralEndpoint(), &pms.RawTokenReader{ + pm := admiral.NewProjectManager(config.AdmiralClient, + config.AdmiralEndpoint(), &admiral.RawTokenReader{ Token: token, }) log.Debug("creating admiral security context...") - securCtx := admiral.NewSecurityContext(authContext, pm) + securCtx := admr.NewSecurityContext(authContext, pm) setSecurCtxAndPM(ctx.Request, securCtx, pm) return true @@ -283,14 +283,14 @@ func (u *unauthorizedReqCtxModifier) Modify(ctx *beegoctx.Context) bool { log.Debug("user information is nil") var securCtx security.Context - var pm projectmanager.ProjectManager + var pm promgr.ProMgr if config.WithAdmiral() { // integration with admiral log.Debug("creating PMS project manager...") - pm = pms.NewProjectManager(config.AdmiralClient, + pm = admiral.NewProjectManager(config.AdmiralClient, config.AdmiralEndpoint(), nil) log.Debug("creating admiral security context...") - securCtx = admiral.NewSecurityContext(nil, pm) + securCtx = admr.NewSecurityContext(nil, pm) } else { // standalone log.Debug("using local database project manager") @@ -302,7 +302,7 @@ func (u *unauthorizedReqCtxModifier) Modify(ctx *beegoctx.Context) bool { return true } -func setSecurCtxAndPM(req *http.Request, ctx security.Context, pm projectmanager.ProjectManager) { +func setSecurCtxAndPM(req *http.Request, ctx security.Context, pm promgr.ProMgr) { addToReqContext(req, securCtxKey, ctx) addToReqContext(req, pmKey, pm) } @@ -331,7 +331,7 @@ func GetSecurityContext(req *http.Request) (security.Context, error) { } // GetProjectManager tries to get project manager from request and returns it -func GetProjectManager(req *http.Request) (projectmanager.ProjectManager, error) { +func GetProjectManager(req *http.Request) (promgr.ProMgr, error) { if req == nil { return nil, fmt.Errorf("request is nil") } @@ -341,7 +341,7 @@ func GetProjectManager(req *http.Request) (projectmanager.ProjectManager, error) return nil, fmt.Errorf("the project manager got from request is nil") } - p, ok := pm.(projectmanager.ProjectManager) + p, ok := pm.(promgr.ProMgr) if !ok { return nil, fmt.Errorf("the variable got from request is not project manager type") } diff --git a/src/ui/filter/security_test.go b/src/ui/filter/security_test.go index 9d08209cb..84acefcbd 100644 --- a/src/ui/filter/security_test.go +++ b/src/ui/filter/security_test.go @@ -37,8 +37,8 @@ import ( _ "github.com/vmware/harbor/src/ui/auth/db" _ "github.com/vmware/harbor/src/ui/auth/ldap" "github.com/vmware/harbor/src/ui/config" - "github.com/vmware/harbor/src/ui/projectmanager" - "github.com/vmware/harbor/src/ui/projectmanager/db" + "github.com/vmware/harbor/src/ui/promgr" + driver_local "github.com/vmware/harbor/src/ui/promgr/pmsdriver/local" ) func TestMain(m *testing.M) { @@ -316,9 +316,9 @@ func TestGetProjectManager(t *testing.T) { req, err = http.NewRequest("", "", nil) assert.Nil(t, err) req = req.WithContext(context.WithValue(req.Context(), - pmKey, &db.ProjectManager{})) + pmKey, &driver_local.ProjectManager{})) pm, err = GetProjectManager(req) assert.Nil(t, err) - _, ok := pm.(projectmanager.ProjectManager) + _, ok := pm.(promgr.ProMgr) assert.True(t, ok) } diff --git a/src/ui/projectmanager/pms/pm.go b/src/ui/promgr/pmsdriver/admiral/admiral.go similarity index 99% rename from src/ui/projectmanager/pms/pm.go rename to src/ui/promgr/pmsdriver/admiral/admiral.go index 14944248b..05fc6fce3 100644 --- a/src/ui/projectmanager/pms/pm.go +++ b/src/ui/promgr/pmsdriver/admiral/admiral.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package pms +package admiral import ( "bytes" diff --git a/src/ui/projectmanager/pms/pm_test.go b/src/ui/promgr/pmsdriver/admiral/admiral_test.go similarity index 99% rename from src/ui/projectmanager/pms/pm_test.go rename to src/ui/promgr/pmsdriver/admiral/admiral_test.go index c8965699a..2c37c2b90 100644 --- a/src/ui/projectmanager/pms/pm_test.go +++ b/src/ui/promgr/pmsdriver/admiral/admiral_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package pms +package admiral import ( "net/http" diff --git a/src/ui/projectmanager/pms/token.go b/src/ui/promgr/pmsdriver/admiral/token.go similarity index 98% rename from src/ui/projectmanager/pms/token.go rename to src/ui/promgr/pmsdriver/admiral/token.go index 1ecb60895..f04a8a2ed 100644 --- a/src/ui/projectmanager/pms/token.go +++ b/src/ui/promgr/pmsdriver/admiral/token.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package pms +package admiral import ( "io/ioutil" diff --git a/src/ui/projectmanager/pms/token_test.go b/src/ui/promgr/pmsdriver/admiral/token_test.go similarity index 98% rename from src/ui/projectmanager/pms/token_test.go rename to src/ui/promgr/pmsdriver/admiral/token_test.go index 642a45d06..43e2bae91 100644 --- a/src/ui/projectmanager/pms/token_test.go +++ b/src/ui/promgr/pmsdriver/admiral/token_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package pms +package admiral import ( "io/ioutil" diff --git a/src/ui/projectmanager/db/pm.go b/src/ui/promgr/pmsdriver/local/local.go similarity index 99% rename from src/ui/projectmanager/db/pm.go rename to src/ui/promgr/pmsdriver/local/local.go index f723d4516..177a10c13 100644 --- a/src/ui/projectmanager/db/pm.go +++ b/src/ui/promgr/pmsdriver/local/local.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package db +package local import ( "fmt" diff --git a/src/ui/projectmanager/db/pm_test.go b/src/ui/promgr/pmsdriver/local/local_test.go similarity index 99% rename from src/ui/projectmanager/db/pm_test.go rename to src/ui/promgr/pmsdriver/local/local_test.go index 8e7148fe0..96f29850a 100644 --- a/src/ui/projectmanager/db/pm_test.go +++ b/src/ui/promgr/pmsdriver/local/local_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package db +package local import ( "os" diff --git a/src/ui/projectmanager/pm.go b/src/ui/promgr/promgr.go similarity index 91% rename from src/ui/projectmanager/pm.go rename to src/ui/promgr/promgr.go index 4a66966e1..a5b5802a2 100644 --- a/src/ui/projectmanager/pm.go +++ b/src/ui/promgr/promgr.go @@ -12,15 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -package projectmanager +package promgr import ( "github.com/vmware/harbor/src/common/models" ) -// ProjectManager is the project mamager which abstracts the operations related +// ProMgr is the project mamager which abstracts the operations related // to projects -type ProjectManager interface { +type ProMgr interface { Get(projectIDOrName interface{}) (*models.Project, error) IsPublic(projectIDOrName interface{}) (bool, error) Exist(projectIDOrName interface{}) (bool, error) diff --git a/src/ui/proxy/interceptor_test.go b/src/ui/proxy/interceptor_test.go index dc382d090..e6e431dd0 100644 --- a/src/ui/proxy/interceptor_test.go +++ b/src/ui/proxy/interceptor_test.go @@ -9,7 +9,7 @@ import ( notarytest "github.com/vmware/harbor/src/common/utils/notary/test" utilstest "github.com/vmware/harbor/src/common/utils/test" "github.com/vmware/harbor/src/ui/config" - "github.com/vmware/harbor/src/ui/projectmanager/pms" + "github.com/vmware/harbor/src/ui/promgr/pmsdriver/admiral" "net/http" "net/http/httptest" @@ -148,8 +148,8 @@ func TestPMSPolicyChecker(t *testing.T) { panic(err) } - pm := pms.NewProjectManager(http.DefaultClient, - admiralEndpoint, &pms.RawTokenReader{ + pm := admiral.NewProjectManager(http.DefaultClient, + admiralEndpoint, &admiral.RawTokenReader{ Token: "token", }) name := "project_for_test_get_sev_low" diff --git a/src/ui/proxy/interceptors.go b/src/ui/proxy/interceptors.go index 03046667a..09bf10570 100644 --- a/src/ui/proxy/interceptors.go +++ b/src/ui/proxy/interceptors.go @@ -9,7 +9,7 @@ import ( "github.com/vmware/harbor/src/common/utils/log" "github.com/vmware/harbor/src/common/utils/notary" "github.com/vmware/harbor/src/ui/config" - "github.com/vmware/harbor/src/ui/projectmanager" + "github.com/vmware/harbor/src/ui/promgr" uiutils "github.com/vmware/harbor/src/ui/utils" "context" @@ -88,7 +88,7 @@ func (ec envPolicyChecker) vulnerablePolicy(name string) (bool, models.Severity) } type pmsPolicyChecker struct { - pm projectmanager.ProjectManager + pm promgr.ProMgr } func (pc pmsPolicyChecker) contentTrustEnabled(name string) bool { @@ -109,7 +109,7 @@ func (pc pmsPolicyChecker) vulnerablePolicy(name string) (bool, models.Severity) } // newPMSPolicyChecker returns an instance of an pmsPolicyChecker -func newPMSPolicyChecker(pm projectmanager.ProjectManager) policyChecker { +func newPMSPolicyChecker(pm promgr.ProMgr) policyChecker { return &pmsPolicyChecker{ pm: pm, } diff --git a/src/ui/service/token/authutils.go b/src/ui/service/token/authutils.go index 22069fd89..a6bdcf84c 100644 --- a/src/ui/service/token/authutils.go +++ b/src/ui/service/token/authutils.go @@ -29,7 +29,7 @@ import ( "github.com/vmware/harbor/src/common/security" "github.com/vmware/harbor/src/common/utils/log" "github.com/vmware/harbor/src/ui/config" - promgr "github.com/vmware/harbor/src/ui/projectmanager" + "github.com/vmware/harbor/src/ui/promgr" ) const ( @@ -81,7 +81,7 @@ func GetResourceActions(scopes []string) []*token.ResourceActions { //filterAccess iterate a list of resource actions and try to use the filter that matches the resource type to filter the actions. func filterAccess(access []*token.ResourceActions, ctx security.Context, - pm promgr.ProjectManager, filters map[string]accessFilter) error { + pm promgr.ProMgr, filters map[string]accessFilter) error { var err error for _, a := range access { f, ok := filters[a.Type] diff --git a/src/ui/service/token/creator.go b/src/ui/service/token/creator.go index c9ece13b3..3194cdb2d 100644 --- a/src/ui/service/token/creator.go +++ b/src/ui/service/token/creator.go @@ -26,7 +26,7 @@ import ( "github.com/vmware/harbor/src/common/utils/log" "github.com/vmware/harbor/src/ui/config" "github.com/vmware/harbor/src/ui/filter" - promgr "github.com/vmware/harbor/src/ui/projectmanager" + "github.com/vmware/harbor/src/ui/promgr" ) var creatorMap map[string]Creator @@ -127,13 +127,13 @@ func parseImg(s string) (*image, error) { // An accessFilter will filter access based on userinfo type accessFilter interface { - filter(ctx security.Context, pm promgr.ProjectManager, a *token.ResourceActions) error + filter(ctx security.Context, pm promgr.ProMgr, a *token.ResourceActions) error } type registryFilter struct { } -func (reg registryFilter) filter(ctx security.Context, pm promgr.ProjectManager, +func (reg registryFilter) filter(ctx security.Context, pm promgr.ProMgr, a *token.ResourceActions) error { //Do not filter if the request is to access registry catalog if a.Name != "catalog" { @@ -151,7 +151,7 @@ type repositoryFilter struct { parser imageParser } -func (rep repositoryFilter) filter(ctx security.Context, pm promgr.ProjectManager, +func (rep repositoryFilter) filter(ctx security.Context, pm promgr.ProMgr, a *token.ResourceActions) error { //clear action list to assign to new acess element after perm check. img, err := rep.parser.parse(a.Name)