-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This command will help to list all the available registry. It also has different options to list registries. Signed-off-by: Akshat <akshat25iiit@gmail.com>
- Loading branch information
1 parent
58a1714
commit 94cafa1
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package registry | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/akshatdalton/harbor-cli/cmd/constants" | ||
"github.com/akshatdalton/harbor-cli/cmd/utils" | ||
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type listRegistryOptions struct { | ||
page int64 | ||
pageSize int64 | ||
q string | ||
sort string | ||
} | ||
|
||
// NewListRegistryCommand creates a new `harbor list registry` command | ||
func NewListRegistryCommand() *cobra.Command { | ||
var opts listRegistryOptions | ||
|
||
cmd := &cobra.Command{ | ||
Use: "registry", | ||
Short: "list registry", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
credentialName, err := cmd.Flags().GetString(constants.CredentialNameOption) | ||
if err != nil { | ||
return err | ||
} | ||
return runListRegistry(opts, credentialName) | ||
}, | ||
} | ||
|
||
flags := cmd.Flags() | ||
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") | ||
|
||
return cmd | ||
} | ||
|
||
func runListRegistry(opts listRegistryOptions, credentialName string) error { | ||
client := utils.GetClientByCredentialName(credentialName) | ||
ctx := context.Background() | ||
response, err := client.Registry.ListRegistries(ctx, ®istry.ListRegistriesParams{Page: &opts.page, PageSize: &opts.pageSize, Q: &opts.q, Sort: &opts.sort}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
utils.PrintPayloadInJSONFormat(response.GetPayload()) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters