Merge pull request #12793 from ywk253100/200816_disable_tag

Disable the tag creation for the artifact under a proxy cache project
This commit is contained in:
stonezdj(Daojun Zhang) 2020-08-18 16:15:33 +08:00 committed by GitHub
commit 716625a769
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -605,6 +605,8 @@ paths:
$ref: '#/responses/403' $ref: '#/responses/403'
'404': '404':
$ref: '#/responses/404' $ref: '#/responses/404'
'405':
$ref: '#/responses/405'
'409': '409':
$ref: '#/responses/409' $ref: '#/responses/409'
'500': '500':

View File

@ -155,14 +155,9 @@ func (a *artifactAPI) CopyArtifact(ctx context.Context, params operation.CopyArt
return a.SendError(ctx, err) return a.SendError(ctx, err)
} }
pro, err := a.proCtl.GetByName(ctx, params.ProjectName) if err := a.requireNonProxyCacheProject(ctx, params.ProjectName); err != nil {
if err != nil {
return a.SendError(ctx, err) 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) srcRepo, ref, err := parse(params.From)
if err != nil { 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 { if err := a.RequireProjectAccess(ctx, params.ProjectName, rbac.ActionCreate, rbac.ResourceTag); err != nil {
return a.SendError(ctx, err) 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), art, err := a.artCtl.GetByReference(ctx, fmt.Sprintf("%s/%s", params.ProjectName, params.RepositoryName),
params.Reference, &artifact.Option{ params.Reference, &artifact.Option{
WithTag: true, WithTag: true,
@ -239,6 +239,18 @@ func (a *artifactAPI) CreateTag(ctx context.Context, params operation.CreateTagP
return operation.NewCreateTagCreated() 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 { 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 { if err := a.RequireProjectAccess(ctx, params.ProjectName, rbac.ActionDelete, rbac.ResourceTag); err != nil {
return a.SendError(ctx, err) return a.SendError(ctx, err)