Skip to content

Commit

Permalink
refactor immutable rule (#14371)
Browse files Browse the repository at this point in the history
Migrate immutable realted APIs to v2 swagger

Signed-off-by: wang yan <wangyan@vmware.com>
  • Loading branch information
wy65701436 committed Mar 8, 2021
1 parent f0dd9e5 commit 85254cc
Show file tree
Hide file tree
Showing 41 changed files with 1,011 additions and 1,193 deletions.
159 changes: 0 additions & 159 deletions api/v2.0/legacy_swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2069,126 +2069,6 @@ paths:
description: User have no permission to list webhook jobs of the project.
'500':
description: Unexpected internal errors.
'/projects/{project_id}/immutabletagrules':
get:
summary: List all immutable tag rules of current project
description: |
This endpoint returns the immutable tag rules of a project
parameters:
- name: project_id
in: path
type: integer
format: int64
required: true
description: Relevant project ID.
tags:
- Products
responses:
'200':
description: List project immutable tag rules successfully.
schema:
type: array
items:
$ref: '#/definitions/ImmutableRule'
'400':
description: Illegal format of provided ID value.
'401':
description: User need to log in first.
'403':
description: User have no permission to list immutable tag rules of the project.
'500':
description: Unexpected internal errors.
post:
summary: Add an immutable tag rule to current project
description: |
This endpoint add an immutable tag rule to the project
parameters:
- name: project_id
in: path
type: integer
format: int64
required: true
description: Relevant project ID.
- name: ImmutableRule
in: body
required: true
schema:
$ref: '#/definitions/ImmutableRule'
tags:
- Products
responses:
'200':
description: Add the immutable tag rule successfully.
'400':
description: Illegal format of provided ID value.
'401':
description: User need to log in first.
'403':
description: User have no permission to get immutable tag rule of the project.
'500':
description: Internal server errors.
'/projects/{project_id}/immutabletagrules/{id}':
put:
summary: Update the immutable tag rule or enable or disable the rule
parameters:
- name: project_id
in: path
type: integer
format: int64
required: true
description: Relevant project ID.
- name: id
in: path
type: integer
format: int64
required: true
description: Immutable tag rule ID.
- name: ImmutableRule
in: body
required: true
schema:
$ref: '#/definitions/ImmutableRule'
tags:
- Products
responses:
'200':
description: Update the immutable tag rule successfully.
'400':
description: Illegal format of provided ID value.
'401':
description: User need to log in first.
'403':
description: User have no permission to update the immutable tag rule of the project.
'500':
description: Internal server errors.
delete:
summary: Delete the immutable tag rule.
parameters:
- name: project_id
in: path
type: integer
format: int64
required: true
description: Relevant project ID.
- name: id
in: path
type: integer
format: int64
required: true
description: Immutable tag rule ID.
tags:
- Products
responses:
'200':
description: Delete the immutable tag rule successfully.
'400':
description: Illegal format of provided ID value.
'401':
description: User need to log in first.
'403':
description: User have no permission to delete immutable tags of the project.
'500':
description: Internal server errors.
responses:
OK:
description: 'Success'
Expand Down Expand Up @@ -3422,45 +3302,6 @@ definitions:
type: string
description: Webhook supportted notify type.
example: 'http'
ImmutableRule:
type: object
properties:
id:
type: integer
priority:
type: integer
disabled:
type: boolean
action:
type: string
template:
type: string
params:
type: object
additionalProperties:
type: object
tag_selectors:
type: array
items:
$ref: '#/definitions/ImmutableSelector'
scope_selectors:
type: object
additionalProperties:
type: array
items:
$ref: '#/definitions/ImmutableSelector'

ImmutableSelector:
type: object
properties:
kind:
type: string
decoration:
type: string
pattern:
type: string
extras:
type: string

parameters:
query:
Expand Down
161 changes: 161 additions & 0 deletions api/v2.0/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,120 @@ paths:
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'
'/projects/{project_name_or_id}/immutabletagrules':
get:
summary: List all immutable tag rules of current project
description: |
This endpoint returns the immutable tag rules of a project
tags:
- immutable
operationId: ListImmuRules
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/isResourceName'
- $ref: '#/parameters/projectNameOrId'
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- $ref: '#/parameters/query'
responses:
'200':
description: Success
headers:
X-Total-Count:
description: The total count of immutable tag
type: integer
Link:
description: Link refers to the previous page and next page
type: string
schema:
type: array
items:
$ref: '#/definitions/ImmutableRule'
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'403':
$ref: '#/responses/403'
'500':
$ref: '#/responses/500'
post:
summary: Add an immutable tag rule to current project
description: |
This endpoint add an immutable tag rule to the project
tags:
- immutable
operationId: CreateImmuRule
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/isResourceName'
- $ref: '#/parameters/projectNameOrId'
- name: ImmutableRule
in: body
required: true
schema:
$ref: '#/definitions/ImmutableRule'
responses:
'201':
$ref: '#/responses/201'
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'403':
$ref: '#/responses/403'
'404':
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'
'/projects/{project_name_or_id}/immutabletagrules/{immutable_rule_id}':
put:
summary: Update the immutable tag rule or enable or disable the rule
tags:
- immutable
operationId: UpdateImmuRule
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/isResourceName'
- $ref: '#/parameters/projectNameOrId'
- $ref: '#/parameters/immutableRuleId'
- name: ImmutableRule
in: body
required: true
schema:
$ref: '#/definitions/ImmutableRule'
responses:
'200':
$ref: '#/responses/200'
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'403':
$ref: '#/responses/403'
'500':
$ref: '#/responses/500'
delete:
summary: Delete the immutable tag rule.
tags:
- immutable
operationId: DeleteImmuRule
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/isResourceName'
- $ref: '#/parameters/projectNameOrId'
- $ref: '#/parameters/immutableRuleId'
responses:
'200':
$ref: '#/responses/200'
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'403':
$ref: '#/responses/403'
'500':
$ref: '#/responses/500'
/icons/{digest}:
get:
summary: Get artifact icon
Expand Down Expand Up @@ -3251,6 +3365,14 @@ parameters:
required: true
type: integer
format: int64
immutableRuleId:
name: immutable_rule_id
in: path
description: The ID of the immutable rule
required: true
type: integer
format: int64

responses:
'200':
description: Success
Expand Down Expand Up @@ -5046,3 +5168,42 @@ definitions:
import:
package: "github.com/goharbor/harbor/src/pkg/scan/rest/v1"
alias: v1

ImmutableRule:
type: object
properties:
id:
type: integer
priority:
type: integer
disabled:
type: boolean
action:
type: string
template:
type: string
params:
type: object
additionalProperties:
type: object
tag_selectors:
type: array
items:
$ref: '#/definitions/ImmutableSelector'
scope_selectors:
type: object
additionalProperties:
type: array
items:
$ref: '#/definitions/ImmutableSelector'
ImmutableSelector:
type: object
properties:
kind:
type: string
decoration:
type: string
pattern:
type: string
extras:
type: string
4 changes: 2 additions & 2 deletions src/controller/artifact/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import (
"github.com/goharbor/harbor/src/pkg/artifactrash"
"github.com/goharbor/harbor/src/pkg/artifactrash/model"
"github.com/goharbor/harbor/src/pkg/blob"
"github.com/goharbor/harbor/src/pkg/immutabletag/match"
"github.com/goharbor/harbor/src/pkg/immutabletag/match/rule"
"github.com/goharbor/harbor/src/pkg/immutable/match"
"github.com/goharbor/harbor/src/pkg/immutable/match/rule"
"github.com/goharbor/harbor/src/pkg/label"
"github.com/goharbor/harbor/src/pkg/notification"
"github.com/goharbor/harbor/src/pkg/notifier/event"
Expand Down
6 changes: 3 additions & 3 deletions src/controller/artifact/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package artifact

import (
"context"
"github.com/goharbor/harbor/src/testing/pkg/immutable"
"testing"
"time"

Expand All @@ -36,7 +37,6 @@ import (
arttesting "github.com/goharbor/harbor/src/testing/pkg/artifact"
artrashtesting "github.com/goharbor/harbor/src/testing/pkg/artifactrash"
"github.com/goharbor/harbor/src/testing/pkg/blob"
immutesting "github.com/goharbor/harbor/src/testing/pkg/immutabletag"
"github.com/goharbor/harbor/src/testing/pkg/label"
"github.com/goharbor/harbor/src/testing/pkg/registry"
repotesting "github.com/goharbor/harbor/src/testing/pkg/repository"
Expand Down Expand Up @@ -66,7 +66,7 @@ type controllerTestSuite struct {
tagCtl *tagtesting.FakeController
labelMgr *label.FakeManager
abstractor *fakeAbstractor
immutableMtr *immutesting.FakeMatcher
immutableMtr *immutable.FakeMatcher
regCli *registry.FakeClient
}

Expand All @@ -78,7 +78,7 @@ func (c *controllerTestSuite) SetupTest() {
c.tagCtl = &tagtesting.FakeController{}
c.labelMgr = &label.FakeManager{}
c.abstractor = &fakeAbstractor{}
c.immutableMtr = &immutesting.FakeMatcher{}
c.immutableMtr = &immutable.FakeMatcher{}
c.regCli = &registry.FakeClient{}
c.ctl = &controller{
repoMgr: c.repoMgr,
Expand Down
Loading

0 comments on commit 85254cc

Please sign in to comment.