diff --git a/api/v2.0/swagger.yaml b/api/v2.0/swagger.yaml index 0db6279b8..c436d34e8 100644 --- a/api/v2.0/swagger.yaml +++ b/api/v2.0/swagger.yaml @@ -605,6 +605,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)