Skip to content

Commit

Permalink
Api refactor label (#14650)
Browse files Browse the repository at this point in the history
* Refactor labl api

move to the new program model

Signed-off-by: wang yan <wangyan@vmware.com>

* continue resolve review comments

Signed-off-by: Wang Yan <wangyan@vmware.com>
  • Loading branch information
wy65701436 authored Apr 15, 2021
1 parent 45663e0 commit 6e3c9e2
Show file tree
Hide file tree
Showing 39 changed files with 1,226 additions and 1,476 deletions.
167 changes: 0 additions & 167 deletions api/v2.0/legacy_swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,173 +180,6 @@ paths:
description: User need to log in first.
'500':
description: Unexpected internal errors.
/labels:
get:
summary: List labels according to the query strings.
description: |
This endpoint let user list labels by name, scope and project_id
parameters:
- name: name
in: query
type: string
required: false
description: The label name.
- name: scope
in: query
type: string
required: true
description: The label scope. Valid values are g and p. g for global labels and p for project labels.
- name: project_id
in: query
type: integer
format: int64
required: false
description: 'Relevant project ID, required when scope is p.'
- name: page
in: query
type: integer
format: int32
required: false
description: The page number.
- name: page_size
in: query
type: integer
format: int32
required: false
description: The size of per page.
tags:
- Products
responses:
'200':
description: Get successfully.
schema:
type: array
items:
$ref: '#/definitions/Label'
headers:
X-Total-Count:
description: The total count of available items
type: integer
Link:
description: Link to previous page and next page
type: string
'400':
description: Invalid parameters.
'401':
description: User need to log in first.
'500':
description: Unexpected internal errors.
post:
summary: Post creates a label
description: |
This endpoint let user creates a label.
parameters:
- name: label
in: body
description: The json object of label.
required: true
schema:
$ref: '#/definitions/Label'
tags:
- Products
responses:
'201':
description: Create successfully.
headers:
Location:
type: string
description: The URL of the created resource
'400':
description: Invalid parameters.
'401':
description: User need to log in first.
'409':
description: Label with the same name and same scope already exists.
'415':
$ref: '#/responses/UnsupportedMediaType'
'500':
description: Unexpected internal errors.
'/labels/{id}':
get:
summary: Get the label specified by ID.
description: |
This endpoint let user get the label by specific ID.
parameters:
- name: id
in: path
type: integer
format: int64
required: true
description: Label ID
tags:
- Products
responses:
'200':
description: Get successfully.
schema:
$ref: '#/definitions/Label'
'401':
description: User need to log in first.
'404':
description: The resource does not exist.
'500':
description: Unexpected internal errors.
put:
summary: Update the label properties.
description: |
This endpoint let user update label properties.
parameters:
- name: id
in: path
type: integer
format: int64
required: true
description: Label ID
- name: label
in: body
description: The updated label json object.
required: true
schema:
$ref: '#/definitions/Label'
tags:
- Products
responses:
'200':
description: Update successfully.
'400':
description: Invalid parameters.
'401':
description: User need to log in first.
'404':
description: The resource does not exist.
'409':
description: The label with the same name already exists.
'500':
description: Unexpected internal errors.
delete:
summary: Delete the label specified by ID.
description: |
Delete the label specified by ID.
parameters:
- name: id
in: path
type: integer
format: int64
required: true
description: Label ID
tags:
- Products
responses:
'200':
description: Delete successfully.
'400':
description: Invalid parameters.
'401':
description: User need to log in first.
'404':
description: The resource does not exist.
'500':
description: Unexpected internal errors.
/email/ping:
post:
summary: Test connection and authentication with email server.
Expand Down
167 changes: 167 additions & 0 deletions api/v2.0/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4815,6 +4815,158 @@ paths:
description: The auth mode of the system is not "oidc_auth", or the user is not onboarded via OIDC AuthN.
'500':
$ref: '#/responses/500'

/labels:
get:
summary: List labels according to the query strings.
description: |
This endpoint let user list labels by name, scope and project_id
tags:
- label
operationId: ListLabels
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/query'
- $ref: '#/parameters/sort'
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- name: name
in: query
type: string
required: false
description: The label name.
- name: scope
in: query
type: string
required: false
description: The label scope. Valid values are g and p. g for global labels and p for project labels.
- name: project_id
in: query
type: integer
format: int64
required: false
description: Relevant project ID, required when scope is p.
responses:
'200':
description: Get successfully.
schema:
type: array
items:
$ref: '#/definitions/Label'
headers:
X-Total-Count:
description: The total count of available items
type: integer
Link:
description: Link to previous page and next page
type: string
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'500':
$ref: '#/responses/500'
post:
summary: Post creates a label
description: |
This endpoint let user creates a label.
tags:
- label
operationId: CreateLabel
parameters:
- name: label
in: body
description: The json object of label.
required: true
schema:
$ref: '#/definitions/Label'
responses:
'201':
description: Create successfully.
headers:
Location:
type: string
description: The URL of the created resource
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'409':
$ref: '#/responses/409'
'415':
$ref: '#/responses/415'
'500':
$ref: '#/responses/500'
'/labels/{label_id}':
get:
summary: Get the label specified by ID.
description: |
This endpoint let user get the label by specific ID.
tags:
- label
operationId: GetLabelByID
parameters:
- $ref: '#/parameters/labelId'
responses:
'200':
description: Get successfully.
schema:
$ref: '#/definitions/Label'
'401':
$ref: '#/responses/401'
'404':
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'
put:
summary: Update the label properties.
description: |
This endpoint let user update label properties.
tags:
- label
operationId: UpdateLabel
parameters:
- $ref: '#/parameters/labelId'
- name: label
in: body
description: The updated label json object.
required: true
schema:
$ref: '#/definitions/Label'
responses:
'200':
$ref: '#/responses/200'
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'404':
$ref: '#/responses/404'
'409':
$ref: '#/responses/409'
'500':
$ref: '#/responses/500'
delete:
summary: Delete the label specified by ID.
description: |
Delete the label specified by ID.
tags:
- label
operationId: DeleteLabel
parameters:
- $ref: '#/parameters/labelId'
responses:
'200':
$ref: '#/responses/200'
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'404':
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'

parameters:
query:
name: q
Expand Down Expand Up @@ -4947,6 +5099,13 @@ parameters:
required: true
type: integer
format: int64
labelId:
name: label_id
in: path
description: Label ID
required: true
type: integer
format: int64
webhookPolicyId:
name: webhook_policy_id
in: path
Expand Down Expand Up @@ -5040,6 +5199,14 @@ responses:
type: string
schema:
$ref: '#/definitions/Errors'
'415':
description: Unsupported MediaType
headers:
X-Request-Id:
description: The ID of the corresponding request for the response
type: string
schema:
$ref: '#/definitions/Errors'
'500':
description: Internal server error
headers:
Expand Down
6 changes: 3 additions & 3 deletions src/chartserver/chart_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"time"

"github.com/Masterminds/semver"
"github.com/goharbor/harbor/src/pkg/label/model"

"github.com/goharbor/harbor/src/common/models"
hlog "github.com/goharbor/harbor/src/lib/log"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"
Expand All @@ -27,7 +27,7 @@ const (
// ChartVersion extends the helm ChartVersion with additional labels
type ChartVersion struct {
helm_repo.ChartVersion
Labels []*models.Label `json:"labels"`
Labels []*model.Label `json:"labels"`
}

// ChartVersions is an array of extended ChartVersion
Expand All @@ -40,7 +40,7 @@ type ChartVersionDetails struct {
Values map[string]interface{} `json:"values"`
Files map[string]string `json:"files"`
Security *SecurityReport `json:"security"`
Labels []*models.Label `json:"labels"`
Labels []*model.Label `json:"labels"`
}

// SecurityReport keeps the info related with security
Expand Down
Loading

0 comments on commit 6e3c9e2

Please sign in to comment.