feat(preheat): add list providers under project level handler

Signed-off-by: chlins <chlins.zhang@gmail.com>
This commit is contained in:
chlins 2020-07-13 21:53:50 +08:00
parent 3b43162b6d
commit 7322d0ac7c
2 changed files with 59 additions and 6 deletions

View File

@ -1158,6 +1158,33 @@ paths:
$ref: '#/responses/403'
'500':
$ref: '#/responses/500'
/projects/{project_name}/preheat/providers:
get:
summary: Get all providers at project level
description: Get all providers at project level
tags:
- preheat
operationId: ListProvidersUnderProject
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/projectName'
responses:
'200':
description: Success
schema:
type: array
items:
$ref: '#/definitions/ProviderUnderProject'
'400':
$ref: '#/responses/400'
'401':
$ref: '#/responses/401'
'403':
$ref: '#/responses/403'
'404':
$ref: '#/responses/404'
'500':
$ref: '#/responses/500'
parameters:
query:
name: q
@ -1844,3 +1871,10 @@ definitions:
end_time:
type: string
description: The end time of task
ProviderUnderProject:
type: object
properties:
id:
type: integer
provider:
type: string

View File

@ -8,22 +8,19 @@ import (
"regexp"
"time"
"github.com/goharbor/harbor/src/lib/q"
"github.com/goharbor/harbor/src/jobservice/job"
"github.com/goharbor/harbor/src/pkg/task"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/strfmt"
"github.com/goharbor/harbor/src/common/rbac"
preheatCtl "github.com/goharbor/harbor/src/controller/p2p/preheat"
projectCtl "github.com/goharbor/harbor/src/controller/project"
taskCtl "github.com/goharbor/harbor/src/controller/task"
"github.com/goharbor/harbor/src/jobservice/job"
liberrors "github.com/goharbor/harbor/src/lib/errors"
"github.com/goharbor/harbor/src/lib/q"
"github.com/goharbor/harbor/src/pkg/p2p/preheat/models/policy"
instanceModel "github.com/goharbor/harbor/src/pkg/p2p/preheat/models/provider"
"github.com/goharbor/harbor/src/pkg/p2p/preheat/provider"
"github.com/goharbor/harbor/src/pkg/task"
"github.com/goharbor/harbor/src/server/v2.0/models"
"github.com/goharbor/harbor/src/server/v2.0/restapi"
operation "github.com/goharbor/harbor/src/server/v2.0/restapi/operations/preheat"
@ -659,3 +656,25 @@ func (api *preheatAPI) GetLog(ctx context.Context, params operation.GetLogParams
return operation.NewGetLogOK().WithPayload(string(l))
}
// ListProvidersUnderProject is Get all providers at project level
func (api *preheatAPI) ListProvidersUnderProject(ctx context.Context, params operation.ListProvidersUnderProjectParams) middleware.Responder {
if err := api.RequireProjectAccess(ctx, params.ProjectName, rbac.ActionList, rbac.ResourcePreatPolicy); err != nil {
return api.SendError(ctx, err)
}
instances, err := api.preheatCtl.ListInstance(ctx, &q.Query{})
if err != nil {
return api.SendError(ctx, err)
}
var providers []*models.ProviderUnderProject
for _, instance := range instances {
providers = append(providers, &models.ProviderUnderProject{
ID: instance.ID,
Provider: fmt.Sprintf("%s %s-%s", instance.Vendor, instance.Name, instance.Endpoint),
})
}
return operation.NewListProvidersUnderProjectOK().WithPayload(providers)
}