mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-18 22:57:38 +01:00
Merge pull request #12454 from chlins/feat/list-providers-at-project-level
feat(preheat): add list providers under project level handler
This commit is contained in:
commit
f187509a90
@ -1158,6 +1158,33 @@ paths:
|
|||||||
$ref: '#/responses/403'
|
$ref: '#/responses/403'
|
||||||
'500':
|
'500':
|
||||||
$ref: '#/responses/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:
|
parameters:
|
||||||
query:
|
query:
|
||||||
name: q
|
name: q
|
||||||
@ -1844,3 +1871,10 @@ definitions:
|
|||||||
end_time:
|
end_time:
|
||||||
type: string
|
type: string
|
||||||
description: The end time of task
|
description: The end time of task
|
||||||
|
ProviderUnderProject:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
provider:
|
||||||
|
type: string
|
||||||
|
@ -8,22 +8,19 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"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/runtime/middleware"
|
||||||
"github.com/go-openapi/strfmt"
|
"github.com/go-openapi/strfmt"
|
||||||
"github.com/goharbor/harbor/src/common/rbac"
|
"github.com/goharbor/harbor/src/common/rbac"
|
||||||
preheatCtl "github.com/goharbor/harbor/src/controller/p2p/preheat"
|
preheatCtl "github.com/goharbor/harbor/src/controller/p2p/preheat"
|
||||||
projectCtl "github.com/goharbor/harbor/src/controller/project"
|
projectCtl "github.com/goharbor/harbor/src/controller/project"
|
||||||
taskCtl "github.com/goharbor/harbor/src/controller/task"
|
taskCtl "github.com/goharbor/harbor/src/controller/task"
|
||||||
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
liberrors "github.com/goharbor/harbor/src/lib/errors"
|
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"
|
"github.com/goharbor/harbor/src/pkg/p2p/preheat/models/policy"
|
||||||
instanceModel "github.com/goharbor/harbor/src/pkg/p2p/preheat/models/provider"
|
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/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/models"
|
||||||
"github.com/goharbor/harbor/src/server/v2.0/restapi"
|
"github.com/goharbor/harbor/src/server/v2.0/restapi"
|
||||||
operation "github.com/goharbor/harbor/src/server/v2.0/restapi/operations/preheat"
|
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))
|
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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user