mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 18:25:56 +01:00
add with details option for list project (#13634)
default is true and doesn't break any existing api, and when to set it to false, the api only return the basic project infor without meta, CVE settings and etc of the project. Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
parent
b80b1a7abf
commit
8cbfa6f382
@ -46,6 +46,12 @@ paths:
|
||||
description: The name of project owner.
|
||||
required: false
|
||||
type: string
|
||||
- name: with_detail
|
||||
in: query
|
||||
description: Bool value indicating whether return detailed information of the project
|
||||
type: boolean
|
||||
required: false
|
||||
default: true
|
||||
responses:
|
||||
'200':
|
||||
description: Return all matched projects.
|
||||
|
@ -251,6 +251,9 @@ func (c *controller) ListRoles(ctx context.Context, projectID int64, u *user.Use
|
||||
|
||||
func (c *controller) assembleProjects(ctx context.Context, projects models.Projects, options ...Option) error {
|
||||
opts := newOptions(options...)
|
||||
if !opts.WithDetail {
|
||||
return nil
|
||||
}
|
||||
if opts.WithMetadata {
|
||||
if err := c.loadMetadatas(ctx, projects); err != nil {
|
||||
return err
|
||||
|
@ -19,12 +19,20 @@ type Option func(*Options)
|
||||
|
||||
// Options options used by `Get` method of `Controller`
|
||||
type Options struct {
|
||||
WithDetail bool
|
||||
WithCVEAllowlist bool // get project with cve allowlist
|
||||
WithEffectCVEAllowlist bool // get project with effect cve allowlist
|
||||
WithMetadata bool // get project with metadata
|
||||
WithOwner bool // get project with owner name
|
||||
}
|
||||
|
||||
// Detail set WithDetail for the Options
|
||||
func Detail(detail bool) Option {
|
||||
return func(opts *Options) {
|
||||
opts.WithDetail = detail
|
||||
}
|
||||
}
|
||||
|
||||
// WithCVEAllowlist set WithCVEAllowlist for the Options
|
||||
func WithCVEAllowlist() Option {
|
||||
return func(opts *Options) {
|
||||
@ -56,6 +64,7 @@ func WithOwner() Option {
|
||||
|
||||
func newOptions(options ...Option) *Options {
|
||||
opts := &Options{
|
||||
WithDetail: true, // default get project details
|
||||
WithMetadata: true, // default get project with metadata
|
||||
}
|
||||
|
||||
|
@ -409,7 +409,7 @@ func (a *projectAPI) ListProjects(ctx context.Context, params operation.ListProj
|
||||
return operation.NewListProjectsOK().WithXTotalCount(0).WithPayload([]*models.Project{})
|
||||
}
|
||||
|
||||
projects, err := a.projectCtl.List(ctx, query, project.WithCVEAllowlist(), project.WithOwner())
|
||||
projects, err := a.projectCtl.List(ctx, query, project.Detail(lib.BoolValue(params.WithDetail)), project.WithCVEAllowlist(), project.WithOwner())
|
||||
if err != nil {
|
||||
return a.SendError(ctx, err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user