From e9ce631aa3a4e1663beaa6cf79c33cd57d30fb3d Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Sun, 16 Aug 2020 22:02:30 +0800 Subject: [PATCH] Disable the tag creation for the artifact under a proxy cache project Disable the tag creation for the artifact under a proxy cache project Fixes #12713 Signed-off-by: Wenkai Yin --- api/v2.0/swagger.yaml | 2 ++ src/server/v2.0/handler/artifact.go | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/api/v2.0/swagger.yaml b/api/v2.0/swagger.yaml index 8dfd3df76..92a60ff30 100644 --- a/api/v2.0/swagger.yaml +++ b/api/v2.0/swagger.yaml @@ -606,6 +606,8 @@ paths: $ref: '#/responses/403' '404': $ref: '#/responses/404' + '405': + $ref: '#/responses/405' '409': $ref: '#/responses/409' '500': diff --git a/src/server/v2.0/handler/artifact.go b/src/server/v2.0/handler/artifact.go index 7818b6fa3..53a56f279 100644 --- a/src/server/v2.0/handler/artifact.go +++ b/src/server/v2.0/handler/artifact.go @@ -155,14 +155,9 @@ func (a *artifactAPI) CopyArtifact(ctx context.Context, params operation.CopyArt return a.SendError(ctx, err) } - pro, err := a.proCtl.GetByName(ctx, params.ProjectName) - if err != nil { + if err := a.requireNonProxyCacheProject(ctx, params.ProjectName); err != nil { return a.SendError(ctx, err) } - if pro.RegistryID > 0 { - return a.SendError(ctx, errors.New(nil).WithCode(errors.MethodNotAllowedCode). - WithMessage("cannot copy the artifact to a proxy cache project")) - } srcRepo, ref, err := parse(params.From) if err != nil { @@ -212,6 +207,11 @@ func (a *artifactAPI) CreateTag(ctx context.Context, params operation.CreateTagP if err := a.RequireProjectAccess(ctx, params.ProjectName, rbac.ActionCreate, rbac.ResourceTag); err != nil { return a.SendError(ctx, err) } + + if err := a.requireNonProxyCacheProject(ctx, params.ProjectName); err != nil { + return a.SendError(ctx, err) + } + art, err := a.artCtl.GetByReference(ctx, fmt.Sprintf("%s/%s", params.ProjectName, params.RepositoryName), params.Reference, &artifact.Option{ WithTag: true, @@ -239,6 +239,18 @@ func (a *artifactAPI) CreateTag(ctx context.Context, params operation.CreateTagP return operation.NewCreateTagCreated() } +func (a *artifactAPI) requireNonProxyCacheProject(ctx context.Context, name string) error { + pro, err := a.proCtl.GetByName(ctx, name) + if err != nil { + return err + } + if pro.RegistryID > 0 { + return errors.New(nil).WithCode(errors.MethodNotAllowedCode). + WithMessage("the operation isn't supported for a proxy cache project") + } + return nil +} + func (a *artifactAPI) DeleteTag(ctx context.Context, params operation.DeleteTagParams) middleware.Responder { if err := a.RequireProjectAccess(ctx, params.ProjectName, rbac.ActionDelete, rbac.ResourceTag); err != nil { return a.SendError(ctx, err)