Merge pull request #3692 from ywk253100/171127_repo_desc

Add update repository API to support description of repository
This commit is contained in:
Qian Deng 2017-12-04 17:25:38 +08:00 committed by GitHub
commit 5de872486c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 2 deletions

View File

@ -961,6 +961,33 @@ paths:
description: Forbidden.
'404':
description: Repository not found.
put:
summary: Update description of the repository.
description: |
This endpoint is used to update description of the repository.
parameters:
- name: repo_name
in: path
type: string
required: true
description: The name of repository which will be deleted.
- name: description
in: body
description: The description of the repository.
required: true
schema:
$ref: '#/definitions/RepositoryDescription'
tags:
- Products
responses:
'200':
description: Update successfully.
'401':
description: Unauthorized.
'403':
description: Forbidden.
'404':
description: Repository not found.
'/repositories/{repo_name}/tags/{tag}':
get:
summary: Get the tag of the repository.
@ -1158,7 +1185,7 @@ paths:
schema:
type: array
items:
$ref: '#definitions/VulnerabilityItem'
$ref: '#/definitions/VulnerabilityItem'
'401':
description: User needs to login or call the API with correct credentials.
'403':
@ -2920,6 +2947,12 @@ definitions:
type: integer
description: The offest in seconds of UTC 0 o'clock, only valid when the policy type is "daily"
description: The parameters of the policy, the values are dependant on the type of the policy.
RepositoryDescription:
type: object
properties:
description:
type: string
description: The description of the repository.

View File

@ -605,6 +605,43 @@ func (ra *RepositoryAPI) GetTopRepos() {
ra.ServeJSON()
}
// Put updates description info for the repository
func (ra *RepositoryAPI) Put() {
name := ra.GetString(":splat")
repository, err := dao.GetRepositoryByName(name)
if err != nil {
ra.HandleInternalServerError(fmt.Sprintf("failed to get repository %s: %v", name, err))
return
}
if repository == nil {
ra.HandleNotFound(fmt.Sprintf("repository %s not found", name))
return
}
if !ra.SecurityCtx.IsAuthenticated() {
ra.HandleUnauthorized()
return
}
project, _ := utils.ParseRepository(name)
if !ra.SecurityCtx.HasAllPerm(project) {
ra.HandleForbidden(ra.SecurityCtx.GetUsername())
return
}
desc := struct {
Description string `json:"description"`
}{}
ra.DecodeJSONReq(&desc)
repository.Description = desc.Description
if err = dao.UpdateRepository(*repository); err != nil {
ra.HandleInternalServerError(fmt.Sprintf("failed to update repository %s: %v", name, err))
return
}
}
//GetSignatures returns signatures of a repository
func (ra *RepositoryAPI) GetSignatures() {
repoName := ra.GetString(":splat")

View File

@ -93,7 +93,7 @@ func initRouters() {
beego.Router("/api/internal/syncregistry", &api.InternalAPI{}, "post:SyncRegistry")
beego.Router("/api/repositories", &api.RepositoryAPI{}, "get:Get")
beego.Router("/api/repositories/scanAll", &api.RepositoryAPI{}, "post:ScanAll")
beego.Router("/api/repositories/*", &api.RepositoryAPI{}, "delete:Delete")
beego.Router("/api/repositories/*", &api.RepositoryAPI{}, "delete:Delete;put:Put")
beego.Router("/api/repositories/*/tags/:tag", &api.RepositoryAPI{}, "delete:Delete;get:GetTag")
beego.Router("/api/repositories/*/tags", &api.RepositoryAPI{}, "get:GetTags")
beego.Router("/api/repositories/*/tags/:tag/scan", &api.RepositoryAPI{}, "post:ScanImage")