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
5 changes: 2 additions & 3 deletions cmd/harbor/root/context/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package context
import (
"fmt"

"github.com/goharbor/harbor-cli/pkg/api"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/goharbor/harbor-cli/pkg/views/context/list"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -45,9 +44,9 @@ func ListContextCommand() *cobra.Command {
return fmt.Errorf("failed to print config: %w", err)
}
} else {
var cxlist []api.ContextListView
var cxlist []list.ListView
for _, cred := range config.Credentials {
cx := api.ContextListView{Name: cred.Name, Username: cred.Username, Server: cred.ServerAddress}
cx := list.ListView{Name: cred.Name, Username: cred.Username, Server: cred.ServerAddress}
cxlist = append(cxlist, cx)
}
currentCredential := config.CurrentCredentialName
Expand Down
26 changes: 26 additions & 0 deletions pkg/api/list_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package api

// ListFlags provides common filter options for list operations across all handlers
type ListFlags struct {
ProjectID int64
Scope string
Name string
Page int64
PageSize int64
Q string
Sort string
Public bool
}
22 changes: 22 additions & 0 deletions pkg/api/member_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ import (
"github.com/goharbor/harbor-cli/pkg/views/member/create"
)

type ListMemberOptions struct {
XIsResourceName bool
ProjectNameOrID string
Page int64
PageSize int64
EntityName string
WithDetail bool
}

type UpdateMemberOptions struct {
XIsResourceName bool
ID int64
ProjectNameOrID string
RoleID *models.RoleRequest
}

type GetMemberOptions struct {
XIsResourceName bool
ID int64
ProjectNameOrID string
}

// Function variables for testing - these can be swapped in tests
var (
listMembersFunc = ListMembers
Expand Down
8 changes: 8 additions & 0 deletions pkg/api/quota_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ import (
"github.com/goharbor/harbor-cli/pkg/utils"
)

type ListQuotaFlags struct {
PageSize int64
Page int64
Sort string
Reference string
ReferenceID string
}

func ListQuota(opts ListQuotaFlags) (*quota.ListQuotasOK, error) {
ctx, client, err := utils.ContextWithClient()
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions pkg/api/registry_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ import (
"github.com/goharbor/harbor-cli/pkg/utils"
)

type CreateRegView struct {
Name string
Type string
Description string
URL string
Credential RegistryCredential
Insecure bool
}

type RegistryCredential struct {
AccessKey string `json:"access_key,omitempty"`
Type string `json:"type,omitempty"`
AccessSecret string `json:"access_secret,omitempty"`
}

func ListRegistries(opts ...ListFlags) (*registry.ListRegistriesOK, error) {
ctx, client, err := utils.ContextWithClient()
if err != nil {
Expand Down
100 changes: 0 additions & 100 deletions pkg/api/types.go

This file was deleted.

17 changes: 17 additions & 0 deletions pkg/api/vulnerability_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ import (
"github.com/goharbor/harbor-cli/pkg/utils"
)

type ListVulnerabilityOptions struct {
CVEID string
CVSSScore string
Severity string
Repository string
ProjectName string
Package string
Tag string
Digest string
Exclude string
WithTag bool
Fixable bool
All bool
Page int64
PageSize int64
}

func GetVulnerabilitySummary(withDangerousArtifact, withDangerousCVE bool) (*securityhub.GetSecuritySummaryOK, error) {
ctx, client, err := utils.ContextWithClient()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func GetQuotaIDFromUser() int64 {
QuotaID := make(chan int64)

go func() {
response, err := api.ListQuota(*&api.ListQuotaFlags{})
response, err := api.ListQuota(api.ListQuotaFlags{})
if err != nil {
log.Errorf("failed to list quota: %v", err)
}
Expand All @@ -320,9 +320,9 @@ func GetActiveContextFromUser() (string, error) {
if err != nil {
return "", err
}
var cxlist []api.ContextListView
var cxlist []list.ListView
for _, cred := range config.Credentials {
cx := api.ContextListView{Name: cred.Name, Username: cred.Username, Server: cred.ServerAddress}
cx := list.ListView{Name: cred.Name, Username: cred.Username, Server: cred.ServerAddress}
cxlist = append(cxlist, cx)
}

Expand Down
12 changes: 9 additions & 3 deletions pkg/views/context/list/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@ import (

"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
"github.com/goharbor/harbor-cli/pkg/api"
"github.com/goharbor/harbor-cli/pkg/views/base/tablelist"
)

// ListView represents a context entry in the list view
type ListView struct {
Name string
Username string
Server string
}

var columns = []table.Column{
{Title: "Name", Width: tablelist.Width3XL},
{Title: "Username", Width: tablelist.WidthL},
{Title: "Server Address", Width: tablelist.WidthXXL},
}

func ListContexts(contexts []api.ContextListView, currentCredential string) {
func ListContexts(contexts []ListView, currentCredential string) {
rows := selectActiveContext(contexts, currentCredential)

var opts []tea.ProgramOption
Expand All @@ -48,7 +54,7 @@ func ListContexts(contexts []api.ContextListView, currentCredential string) {
}
}

func selectActiveContext(contexts []api.ContextListView, currentCredential string) []table.Row {
func selectActiveContext(contexts []ListView, currentCredential string) []table.Row {
var rows []table.Row

for _, ctx := range contexts {
Expand Down
9 changes: 7 additions & 2 deletions pkg/views/context/switch/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ import (

"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/goharbor/harbor-cli/pkg/api"
"github.com/goharbor/harbor-cli/pkg/views/base/selection"
)

func ContextList(contexts []api.ContextListView, activeContext string) (string, error) {
type ListView struct {
Name string
Username string
Server string
}

func ContextList(contexts []ListView, activeContext string) (string, error) {
itemsList := make([]list.Item, len(contexts))

for i, ctx := range contexts {
Expand Down