mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 18:25:56 +01:00
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 <yinw@vmware.com>
This commit is contained in:
parent
0921beaf4c
commit
e9ce631aa3
@ -606,6 +606,8 @@ paths:
|
||||
$ref: '#/responses/403'
|
||||
'404':
|
||||
$ref: '#/responses/404'
|
||||
'405':
|
||||
$ref: '#/responses/405'
|
||||
'409':
|
||||
$ref: '#/responses/409'
|
||||
'500':
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user