Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion cmd/harbor/root/artifact/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ import (
)

func ListArtifactCommand() *cobra.Command {
var opts api.ListFlags

var (
opts api.ListFlags
// For querying, opts.Q
fuzzy []string
match []string
ranges []string
)

cmd := &cobra.Command{
Use: "list",
Expand Down Expand Up @@ -70,6 +77,18 @@ Supports pagination, search queries, and sorting using flags.`,
repoName = prompt.GetRepoNameFromUser(projectName)
}

if len(fuzzy) != 0 || len(match) != 0 || len(ranges) != 0 {
q, qErr := utils.BuildQueryParam(fuzzy, match, ranges,
[]string{"id", "type", "media_type", "artifact_id", "artifact_type", "project_id", "repository_id", "repository_name",
"manifest_media_type", "digest"},
)
if qErr != nil {
return qErr
}

opts.Q = q
Comment thread
Mujib-Ahasan marked this conversation as resolved.
Comment thread
Mujib-Ahasan marked this conversation as resolved.
}

artifacts, err = api.ListArtifact(projectName, repoName, opts)

if err != nil {
Expand All @@ -94,6 +113,9 @@ Supports pagination, search queries, and sorting using flags.`,
flags.Int64VarP(&opts.PageSize, "page-size", "n", 10, "Size of per page")
flags.StringVarP(&opts.Q, "query", "q", "", "Query string to query resources")
flags.StringVarP(&opts.Sort, "sort", "s", "", "Sort the resource list in ascending or descending order")
flags.StringSliceVar(&fuzzy, "fuzzy", nil, "Fuzzy match filter (key=value)")
flags.StringSliceVar(&match, "match", nil, "exact match filter (key=value)")
flags.StringSliceVar(&ranges, "range", nil, "range filter (key=min~max)")

return cmd
}
24 changes: 22 additions & 2 deletions cmd/harbor/root/instance/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ import (
)

func ListInstanceCommand() *cobra.Command {
var opts api.ListFlags

var (
opts api.ListFlags
// For querying, opts.Q
fuzzy []string
match []string
ranges []string
)

cmd := &cobra.Command{
Use: "list",
Expand All @@ -45,8 +52,18 @@ This command provides an easy way to view all instances along with their details
return fmt.Errorf("page size should be less than or equal to 100")
}

instance, err := api.ListAllInstance(opts)
if len(fuzzy) != 0 || len(match) != 0 || len(ranges) != 0 {
q, qErr := utils.BuildQueryParam(fuzzy, match, ranges,
[]string{"id", "name", "description", "endpoint", "vendor", "status", "enabled", "auth_mode"},
)
if qErr != nil {
return qErr
}
Comment thread
Mujib-Ahasan marked this conversation as resolved.

opts.Q = q
Comment thread
Mujib-Ahasan marked this conversation as resolved.
}
Comment thread
Mujib-Ahasan marked this conversation as resolved.

instance, err := api.ListAllInstance(opts)
if err != nil {
return fmt.Errorf("failed to get instance list: %v", err)
}
Expand All @@ -68,6 +85,9 @@ This command provides an easy way to view all instances along with their details
flags.Int64VarP(&opts.PageSize, "page-size", "", 10, "Size of per page")
flags.StringVarP(&opts.Q, "query", "q", "", "Query string to query resources")
flags.StringVarP(&opts.Sort, "sort", "", "", "Sort the resource list in ascending or descending order")
flags.StringSliceVar(&fuzzy, "fuzzy", nil, "Fuzzy match filter (key=value)")
flags.StringSliceVar(&match, "match", nil, "exact match filter (key=value)")
flags.StringSliceVar(&ranges, "range", nil, "range filter (key=min~max)")

return cmd
}
33 changes: 25 additions & 8 deletions cmd/harbor/root/project/robot/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ import (

// ListRobotCommand creates a new `harbor project robot list` command
func ListRobotCommand() *cobra.Command {
var opts api.ListFlags

var (
opts api.ListFlags
// For querying, opts.Q
fuzzy []string
match []string
ranges []string
)

projectQString := constants.ProjectQString
cmd := &cobra.Command{
Expand Down Expand Up @@ -102,6 +109,19 @@ Examples:
opts.Q = projectQString + strconv.FormatInt(projectID, 10)
}

if len(fuzzy) != 0 || len(match) != 0 || len(ranges) != 0 {
q, qErr := utils.BuildQueryParam(fuzzy, match, ranges,
[]string{"id", "secret", "description", "name", "disable", "level", "duration", "editable"},
)
if qErr != nil {
return qErr
}
if opts.Q != "" {
opts.Q += ","
}
opts.Q += q
Comment thread
Mujib-Ahasan marked this conversation as resolved.
}

robots, err := api.ListRobot(opts)
if err != nil {
return fmt.Errorf("failed to get robots list: %v", utils.ParseHarborErrorMsg(err))
Expand All @@ -126,13 +146,10 @@ Examples:
flags.Int64VarP(&opts.PageSize, "page-size", "", 10, "Size of per page")
flags.Int64VarP(&opts.ProjectID, "project-id", "", 0, "Project ID")
flags.StringVarP(&opts.Q, "query", "q", "", "Query string to query resources")
Comment on lines 147 to 148
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No query conversion here

flags.StringVarP(
&opts.Sort,
"sort",
"",
"",
"Sort the resource list in ascending or descending order",
)
flags.StringSliceVar(&fuzzy, "fuzzy", nil, "Fuzzy match filter (key=value)")
flags.StringSliceVar(&match, "match", nil, "exact match filter (key=value)")
flags.StringSliceVar(&ranges, "range", nil, "range filter (key=min~max)")
flags.StringVarP(&opts.Sort, "sort", "", "", "Sort the resource list in ascending or descending order")

return cmd
}
8 changes: 1 addition & 7 deletions cmd/harbor/root/quota/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ func ListQuotaCommand() *cobra.Command {
flags.Int64VarP(&opts.PageSize, "page-size", "", 0, "Size of per page (use 0 to fetch all)")
flags.StringVarP(&opts.Reference, "ref", "", "", "Reference type of quota")
flags.StringVarP(&opts.ReferenceID, "refid", "", "", "Reference ID of quota")
flags.StringVarP(
&opts.Sort,
"sort",
"",
"",
"Sort the resource list in ascending or descending order",
)
flags.StringVarP(&opts.Sort, "sort", "", "", "Sort the resource list in ascending or descending order")

return cmd
}
23 changes: 22 additions & 1 deletion cmd/harbor/root/registry/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ import (

// NewListRegistryCommand creates a new `harbor list registry` command
func ListRegistryCommand() *cobra.Command {
var opts api.ListFlags

var (
opts api.ListFlags
// For querying, opts.Q
fuzzy []string
match []string
ranges []string
)

cmd := &cobra.Command{
Use: "list",
Expand All @@ -43,6 +50,17 @@ func ListRegistryCommand() *cobra.Command {
if opts.PageSize > 100 {
return fmt.Errorf("page size should be less than or equal to 100")
}

if len(fuzzy) != 0 || len(match) != 0 || len(ranges) != 0 {
q, qErr := utils.BuildQueryParam(fuzzy, match, ranges,
[]string{"id", "url", "name", "type", "description", "status", "creation_time"},
)
if qErr != nil {
return qErr
}

opts.Q = q
}
Comment thread
Mujib-Ahasan marked this conversation as resolved.
registry, err := api.ListRegistries(opts)

if err != nil {
Expand Down Expand Up @@ -70,6 +88,9 @@ func ListRegistryCommand() *cobra.Command {
flags.Int64VarP(&opts.PageSize, "page-size", "", 10, "Size of per page")
flags.StringVarP(&opts.Q, "query", "q", "", "Query string to query resources")
flags.StringVarP(&opts.Sort, "sort", "", "", "Sort the resource list in ascending or descending order")
flags.StringSliceVar(&fuzzy, "fuzzy", nil, "Fuzzy match filter (key=value)")
flags.StringSliceVar(&match, "match", nil, "exact match filter (key=value)")
flags.StringSliceVar(&ranges, "range", nil, "range filter (key=min~max)")

return cmd
}
23 changes: 22 additions & 1 deletion cmd/harbor/root/replication/executions/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ import (
)

func ListCommand() *cobra.Command {
var opts api.ListFlags

var (
opts api.ListFlags
// For querying, opts.Q
fuzzy []string
match []string
ranges []string
)
cmd := &cobra.Command{
Use: "list",
Short: "List replication executions",
Expand Down Expand Up @@ -60,6 +67,17 @@ func ListCommand() *cobra.Command {
rpolicyID = prompt.GetReplicationPolicyFromUser()
}

if len(fuzzy) != 0 || len(match) != 0 || len(ranges) != 0 {
q, qErr := utils.BuildQueryParam(fuzzy, match, ranges,
[]string{"id", "policy_id", "trigger", "status", "status_text", "start_time", "end_time"},
)
if qErr != nil {
return qErr
}

opts.Q = q
Comment thread
Mujib-Ahasan marked this conversation as resolved.
}

log.Debug("Fetching executions...")
executions, err := api.ListReplicationExecutions(rpolicyID, opts)
if err != nil {
Expand Down Expand Up @@ -92,6 +110,9 @@ func ListCommand() *cobra.Command {
flags.Int64VarP(&opts.PageSize, "page-size", "", 0, "Size of per page (0 to fetch all)")
flags.StringVarP(&opts.Q, "query", "q", "", "Query string to query resources")
flags.StringVarP(&opts.Sort, "sort", "", "", "Sort the resource list in ascending or descending order")
flags.StringSliceVar(&fuzzy, "fuzzy", nil, "Fuzzy match filter (key=value)")
flags.StringSliceVar(&match, "match", nil, "exact match filter (key=value)")
flags.StringSliceVar(&ranges, "range", nil, "range filter (key=min~max)")

return cmd
}
24 changes: 23 additions & 1 deletion cmd/harbor/root/replication/policies/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ import (
)

func ListCommand() *cobra.Command {
var opts api.ListFlags

var (
opts api.ListFlags
// For querying, opts.Q
fuzzy []string
match []string
ranges []string
)

cmd := &cobra.Command{
Use: "list",
Short: "List replication policies",
Expand All @@ -45,6 +53,17 @@ func ListCommand() *cobra.Command {
}

log.Debug("Fetching policies...")

if len(fuzzy) != 0 || len(match) != 0 || len(ranges) != 0 {
q, qErr := utils.BuildQueryParam(fuzzy, match, ranges,
[]string{"id", "name", "description", "creation_time"},
)
if qErr != nil {
return qErr
}

opts.Q = q
}
Comment thread
Mujib-Ahasan marked this conversation as resolved.
allPolicies, err := api.ListReplicationPolicies(opts)
if err != nil {
return fmt.Errorf("failed to get projects list: %v", utils.ParseHarborErrorMsg(err))
Expand Down Expand Up @@ -76,6 +95,9 @@ func ListCommand() *cobra.Command {
flags.Int64VarP(&opts.PageSize, "page-size", "", 0, "Size of per page (0 to fetch all)")
flags.StringVarP(&opts.Q, "query", "q", "", "Query string to query resources")
flags.StringVarP(&opts.Sort, "sort", "", "", "Sort the resource list in ascending or descending order")
flags.StringSliceVar(&fuzzy, "fuzzy", nil, "Fuzzy match filter (key=value)")
flags.StringSliceVar(&match, "match", nil, "exact match filter (key=value)")
flags.StringSliceVar(&ranges, "range", nil, "range filter (key=min~max)")

return cmd
}
22 changes: 21 additions & 1 deletion cmd/harbor/root/repository/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ import (
)

func ListRepositoryCommand() *cobra.Command {
var opts api.ListFlags
var (
opts api.ListFlags
// For querying, opts.Q
fuzzy []string
match []string
ranges []string
)

cmd := &cobra.Command{
Use: "list",
Expand Down Expand Up @@ -60,6 +66,17 @@ func ListRepositoryCommand() *cobra.Command {
}
}

if len(fuzzy) != 0 || len(match) != 0 || len(ranges) != 0 {
q, qErr := utils.BuildQueryParam(fuzzy, match, ranges,
[]string{"id", "project_id", "name", "artifact_count", "description", "pull_count", "creation_time"},
)
if qErr != nil {
return qErr
}

opts.Q = q
Comment thread
Mujib-Ahasan marked this conversation as resolved.
}

repos, err = api.ListRepository(projectName, false, opts)
if err != nil {
return fmt.Errorf("failed to list repositories: %v", err)
Expand All @@ -86,6 +103,9 @@ func ListRepositoryCommand() *cobra.Command {
flags.Int64VarP(&opts.PageSize, "page-size", "", 10, "Size of per page")
flags.StringVarP(&opts.Q, "query", "q", "", "Query string to query resources")
flags.StringVarP(&opts.Sort, "sort", "", "", "Sort the resource list in ascending or descending order")
flags.StringSliceVar(&fuzzy, "fuzzy", nil, "Fuzzy match filter (key=value)")
flags.StringSliceVar(&match, "match", nil, "exact match filter (key=value)")
flags.StringSliceVar(&ranges, "range", nil, "range filter (key=min~max)")

return cmd
}
32 changes: 24 additions & 8 deletions cmd/harbor/root/robot/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ import (

// ListRobotCommand creates a new `harbor project robot list` command
func ListRobotCommand() *cobra.Command {
var opts api.ListFlags

var (
opts api.ListFlags
// For querying, opts.Q
fuzzy []string
match []string
ranges []string
)

cmd := &cobra.Command{
Use: "list [projectName]",
Expand Down Expand Up @@ -74,6 +81,18 @@ Examples:
return fmt.Errorf("page size should be less than or equal to 100")
}

if len(fuzzy) != 0 || len(match) != 0 || len(ranges) != 0 {
q, qErr := utils.BuildQueryParam(fuzzy, match, ranges,
[]string{"id", "name", "description", "secret", "level", "duration", "expires_at", "creation_time",
"editable", "disable"},
)
if qErr != nil {
return qErr
}
Comment thread
Mujib-Ahasan marked this conversation as resolved.

opts.Q = q
Comment thread
Mujib-Ahasan marked this conversation as resolved.
}

robots, err := api.ListRobot(opts)
if err != nil {
errorCode := utils.ParseHarborErrorCode(err)
Expand Down Expand Up @@ -101,13 +120,10 @@ Examples:
flags.Int64VarP(&opts.Page, "page", "", 1, "Page number")
flags.Int64VarP(&opts.PageSize, "page-size", "", 10, "Size of per page")
flags.StringVarP(&opts.Q, "query", "q", "", "Query string to query resources")
flags.StringVarP(
&opts.Sort,
"sort",
"",
"",
"Sort the resource list in ascending or descending order",
)
flags.StringVarP(&opts.Sort, "sort", "", "", "Sort the resource list in ascending or descending order")
flags.StringSliceVar(&fuzzy, "fuzzy", nil, "Fuzzy match filter (key=value)")
flags.StringSliceVar(&match, "match", nil, "exact match filter (key=value)")
flags.StringSliceVar(&ranges, "range", nil, "range filter (key=min~max)")

return cmd
}
Loading
Loading