mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 04:05:40 +01:00
Implement the API to get the specified repository
Implement the API to get the specified repository Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
parent
aa71fc43cf
commit
bb3ff0d752
@ -58,6 +58,37 @@ paths:
|
||||
'500':
|
||||
$ref: '#/responses/500'
|
||||
/projects/{project_name}/repositories/{repository_name}:
|
||||
get:
|
||||
summary: Get repository
|
||||
description: Get the repository specified by name
|
||||
tags:
|
||||
- repository
|
||||
operationId: getRepository
|
||||
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':
|
||||
description: Success
|
||||
schema:
|
||||
$ref: '#/definitions/Repository'
|
||||
'400':
|
||||
$ref: '#/responses/400'
|
||||
'401':
|
||||
$ref: '#/responses/401'
|
||||
'403':
|
||||
$ref: '#/responses/403'
|
||||
'404':
|
||||
$ref: '#/responses/404'
|
||||
'500':
|
||||
$ref: '#/responses/500'
|
||||
put:
|
||||
summary: Update repository
|
||||
description: Update the repository specified by name
|
||||
|
@ -79,23 +79,38 @@ func (r *repositoryAPI) ListRepositories(ctx context.Context, params operation.L
|
||||
}
|
||||
var repos []*models.Repository
|
||||
for _, repository := range repositories {
|
||||
repo := repository.ToSwagger()
|
||||
total, err := r.artCtl.Count(ctx, &q.Query{
|
||||
Keywords: map[string]interface{}{
|
||||
"RepositoryID": repo.ID,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("failed to get the count of artifacts under the repository %s: %v",
|
||||
repo.Name, err)
|
||||
}
|
||||
repo.ArtifactCount = total
|
||||
repos = append(repos, repo)
|
||||
repos = append(repos, r.assembleRepository(ctx, repository))
|
||||
}
|
||||
// TODO add link header
|
||||
return operation.NewListRepositoriesOK().WithXTotalCount(total).WithLink("").WithPayload(repos)
|
||||
}
|
||||
|
||||
func (r *repositoryAPI) GetRepository(ctx context.Context, params operation.GetRepositoryParams) middleware.Responder {
|
||||
if err := r.RequireProjectAccess(ctx, params.ProjectName, rbac.ActionList, rbac.ResourceRepository); err != nil {
|
||||
return r.SendError(ctx, err)
|
||||
}
|
||||
repository, err := r.repoCtl.GetByName(ctx, fmt.Sprintf("%s/%s", params.ProjectName, params.RepositoryName))
|
||||
if err != nil {
|
||||
return r.SendError(ctx, err)
|
||||
}
|
||||
return operation.NewGetRepositoryOK().WithPayload(r.assembleRepository(ctx, repository))
|
||||
}
|
||||
|
||||
func (r *repositoryAPI) assembleRepository(ctx context.Context, repository *cmodels.RepoRecord) *models.Repository {
|
||||
repo := repository.ToSwagger()
|
||||
total, err := r.artCtl.Count(ctx, &q.Query{
|
||||
Keywords: map[string]interface{}{
|
||||
"RepositoryID": repo.ID,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("failed to get the count of artifacts under the repository %s: %v",
|
||||
repo.Name, err)
|
||||
}
|
||||
repo.ArtifactCount = total
|
||||
return repo
|
||||
}
|
||||
|
||||
func (r *repositoryAPI) UpdateRepository(ctx context.Context, params operation.UpdateRepositoryParams) middleware.Responder {
|
||||
if err := r.RequireProjectAccess(ctx, params.ProjectName, rbac.ActionUpdate, rbac.ResourceRepository); err != nil {
|
||||
return r.SendError(ctx, err)
|
||||
|
Loading…
Reference in New Issue
Block a user