Skip to content

Commit

Permalink
Merge pull request #10756 from ywk253100/200218_repo_api
Browse files Browse the repository at this point in the history
Implement delete/update repository API
  • Loading branch information
ywk253100 committed Feb 20, 2020
2 parents e5a4f49 + 1db0077 commit beddef6
Show file tree
Hide file tree
Showing 27 changed files with 451 additions and 155 deletions.
153 changes: 128 additions & 25 deletions api/v2.0/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,100 @@ securityDefinitions:
basicAuth:
type: basic
paths:
/projects/{project_name}/repositories:
get:
summary: List repositories
description: List repositories of the specified project
tags:
- repository
operationId: listRepositories
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/projectName'
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- name: name
in: query
description: Query the repositories by name
type: string
required: false
responses:
'200':
description: Success
headers:
X-Total-Count:
description: The total count of repositories
type: integer
Link:
description: Link refers to the previous page and next page
type: string
schema:
type: array
items:
$ref: '#/definitions/Repository'
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'403':
$ref: '#/responses/403'
'404':
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'
/projects/{project_name}/repositories/{repository_name}:
put:
summary: Update repository
description: Update the repository specified by name
tags:
- repository
operationId: updateRepository
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/projectName'
- $ref: '#/parameters/repositoryName'
- name: repository
in: body
description: The JSON object of repository.
required: true
schema:
$ref: '#/definitions/Repository'
responses:
'200':
$ref: '#/responses/200'
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'403':
$ref: '#/responses/403'
'404':
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'
delete:
summary: Delete repository
description: Delete the repository specified by name
tags:
- repository
operationId: deleteRepository
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/projectName'
- $ref: '#/parameters/repositoryName'
responses:
'200':
$ref: '#/responses/200'
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'403':
$ref: '#/responses/403'
'404':
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'
/projects/{project_name}/repositories/{repository_name}/artifacts:
get:
summary: List artifacts
Expand Down Expand Up @@ -57,10 +151,9 @@ paths:
type: boolean
required: false
default: false
# should be in tag level
- name: with_signature
in: query
description: Specify whether the signature is inclued inside the returning artifacts
description: Specify whether the signature is inclued inside the tags of the returning artifacts. Only works when setting "with_tag=true"
type: boolean
required: false
default: false
Expand All @@ -70,7 +163,6 @@ paths:
type: boolean
required: false
default: false
# TODO add other query string: type, ....
responses:
'200':
description: Success
Expand Down Expand Up @@ -234,28 +326,6 @@ paths:
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'
/projects/{project_name}/repositories/{repository_name}:
delete:
summary: Delete repository
description: Delete the repository specified by name
tags:
- repository
operationId: deleteRepository
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/projectName'
- $ref: '#/parameters/repositoryName'
responses:
'200':
$ref: '#/responses/200'
'401':
$ref: '#/responses/401'
'403':
$ref: '#/responses/403'
'404':
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'
/projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/additions/{addition}:
get:
summary: Get the addition of the specific artifact
Expand Down Expand Up @@ -476,6 +546,39 @@ definitions:
message:
type: string
description: The error message
Repository:
type: object
properties:
id:
type: integer
format: int64
description: The ID of the repository
project_id:
type: integer
format: int64
description: The ID of the project that the repository belongs to
name:
type: string
description: The name of the repository
description:
type: string
description: The description of the repository
artifact_count:
type: integer
format: int64
description: The count of the artifacts inside the repository
pull_count:
type: integer
format: int64
description: The count that the artifact inside the repository pulled
creation_time:
type: string
format: date-time
description: The creation time of the repository
update_time:
type: string
format: date-time
description: The update time of the repository
Artifact:
type: object
x-go-type:
Expand Down
35 changes: 22 additions & 13 deletions src/api/artifact/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ type Controller interface {
// and are attached to the artifact. If the tags don't exist, create them first.
// The "created" will be set as true when the artifact is created
Ensure(ctx context.Context, repositoryID int64, digest string, tags ...string) (created bool, id int64, err error)
// Count returns the total count of artifacts according to the query.
// The artifacts that referenced by others and without tags are not counted
Count(ctx context.Context, query *q.Query) (total int64, err error)
// List artifacts according to the query, specify the properties returned with option
List(ctx context.Context, query *q.Query, option *Option) (total int64, artifacts []*Artifact, err error)
// The artifacts that referenced by others and without tags are not returned
List(ctx context.Context, query *q.Query, option *Option) (artifacts []*Artifact, err error)
// Get the artifact specified by ID, specify the properties returned with option
Get(ctx context.Context, id int64, option *Option) (artifact *Artifact, err error)
// Get the artifact specified by repository name and reference, the reference can be tag or digest,
Expand All @@ -68,7 +72,7 @@ type Controller interface {
// Delete the artifact specified by ID. All tags attached to the artifact are deleted as well
Delete(ctx context.Context, id int64) (err error)
// ListTags lists the tags according to the query, specify the properties returned with option
ListTags(ctx context.Context, query *q.Query, option *TagOption) (total int64, tags []*Tag, err error)
ListTags(ctx context.Context, query *q.Query, option *TagOption) (tags []*Tag, err error)
// CreateTag creates a tag
CreateTag(ctx context.Context, tag *Tag) (id int64, err error)
// DeleteTag deletes the tag specified by tagID
Expand Down Expand Up @@ -185,7 +189,7 @@ func (c *controller) ensureTag(ctx context.Context, repositoryID, artifactID int
"name": name,
},
}
_, tags, err := c.tagMgr.List(ctx, query)
tags, err := c.tagMgr.List(ctx, query)
if err != nil {
return err
}
Expand Down Expand Up @@ -216,17 +220,22 @@ func (c *controller) ensureTag(ctx context.Context, repositoryID, artifactID int
return err
}

func (c *controller) List(ctx context.Context, query *q.Query, option *Option) (int64, []*Artifact, error) {
total, arts, err := c.artMgr.List(ctx, query)
func (c *controller) Count(ctx context.Context, query *q.Query) (int64, error) {
return c.artMgr.Count(ctx, query)
}

func (c *controller) List(ctx context.Context, query *q.Query, option *Option) ([]*Artifact, error) {
arts, err := c.artMgr.List(ctx, query)
if err != nil {
return 0, nil, err
return nil, err
}
var artifacts []*Artifact
for _, art := range arts {
artifacts = append(artifacts, c.assembleArtifact(ctx, art, option))
}
return total, artifacts, nil
return artifacts, nil
}

func (c *controller) Get(ctx context.Context, id int64, option *Option) (*Artifact, error) {
art, err := c.artMgr.Get(ctx, id)
if err != nil {
Expand Down Expand Up @@ -261,7 +270,7 @@ func (c *controller) getByTag(ctx context.Context, repository, tag string, optio
if err != nil {
return nil, err
}
_, tags, err := c.tagMgr.List(ctx, &q.Query{
tags, err := c.tagMgr.List(ctx, &q.Query{
Keywords: map[string]interface{}{
"RepositoryID": repo.RepositoryID,
"Name": tag,
Expand Down Expand Up @@ -369,16 +378,16 @@ func (c *controller) CreateTag(ctx context.Context, tag *Tag) (int64, error) {
// TODO fire event
return c.tagMgr.Create(ctx, &(tag.Tag))
}
func (c *controller) ListTags(ctx context.Context, query *q.Query, option *TagOption) (int64, []*Tag, error) {
total, tgs, err := c.tagMgr.List(ctx, query)
func (c *controller) ListTags(ctx context.Context, query *q.Query, option *TagOption) ([]*Tag, error) {
tgs, err := c.tagMgr.List(ctx, query)
if err != nil {
return 0, nil, err
return nil, err
}
var tags []*Tag
for _, tg := range tgs {
tags = append(tags, c.assembleTag(ctx, tg, option))
}
return total, tags, nil
return tags, nil
}

func (c *controller) DeleteTag(ctx context.Context, tagID int64) error {
Expand Down Expand Up @@ -442,7 +451,7 @@ func (c *controller) assembleArtifact(ctx context.Context, art *artifact.Artifac
}

func (c *controller) populateTags(ctx context.Context, art *Artifact, option *TagOption) {
_, tags, err := c.tagMgr.List(ctx, &q.Query{
tags, err := c.tagMgr.List(ctx, &q.Query{
Keywords: map[string]interface{}{
"artifact_id": art.ID,
},
Expand Down
Loading

0 comments on commit beddef6

Please sign in to comment.