diff --git a/cmd/harbor/root/context/list.go b/cmd/harbor/root/context/list.go index 01bdeec9f..bdabce62c 100644 --- a/cmd/harbor/root/context/list.go +++ b/cmd/harbor/root/context/list.go @@ -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" @@ -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 diff --git a/pkg/api/list_flags.go b/pkg/api/list_flags.go new file mode 100644 index 000000000..31cbc2799 --- /dev/null +++ b/pkg/api/list_flags.go @@ -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 +} diff --git a/pkg/api/member_handler.go b/pkg/api/member_handler.go index ceff19240..6a69f3e90 100644 --- a/pkg/api/member_handler.go +++ b/pkg/api/member_handler.go @@ -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 diff --git a/pkg/api/quota_handler.go b/pkg/api/quota_handler.go index 6b96d932b..1e1c02438 100644 --- a/pkg/api/quota_handler.go +++ b/pkg/api/quota_handler.go @@ -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 { diff --git a/pkg/api/registry_handler.go b/pkg/api/registry_handler.go index 42d075705..ccbee0afc 100644 --- a/pkg/api/registry_handler.go +++ b/pkg/api/registry_handler.go @@ -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 { diff --git a/pkg/api/types.go b/pkg/api/types.go deleted file mode 100644 index d44fa28cf..000000000 --- a/pkg/api/types.go +++ /dev/null @@ -1,100 +0,0 @@ -// 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 - -import "github.com/goharbor/go-client/pkg/sdk/v2.0/models" - -type ListFlags struct { - ProjectID int64 - Scope string - Name string - Page int64 - PageSize int64 - Q string - Sort string - Public bool -} - -// CreateView for Registry -type CreateRegView struct { - Name string - Type string - Description string - URL string - Credential RegistryCredential - Insecure bool -} - -type ContextListView struct { - Name string - Username string - Server string -} - -// Credential for Registry -type RegistryCredential struct { - AccessKey string `json:"access_key,omitempty"` - Type string `json:"type,omitempty"` - AccessSecret string `json:"access_secret,omitempty"` -} - -type ListQuotaFlags struct { - PageSize int64 - Page int64 - Sort string - Reference string - ReferenceID string -} - -// Provides type for List member -type ListMemberOptions struct { - XIsResourceName bool - ProjectNameOrID string - Page int64 - PageSize int64 - EntityName string - WithDetail bool -} - -// Provides type for Update member -type UpdateMemberOptions struct { - XIsResourceName bool - ID int64 - ProjectNameOrID string - RoleID *models.RoleRequest -} - -// Provides Params for getting the Member -type GetMemberOptions struct { - XIsResourceName bool - ID int64 - ProjectNameOrID string -} - -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 -} diff --git a/pkg/api/vulnerability_handler.go b/pkg/api/vulnerability_handler.go index 708cac231..0dfc36cfa 100644 --- a/pkg/api/vulnerability_handler.go +++ b/pkg/api/vulnerability_handler.go @@ -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 { diff --git a/pkg/prompt/prompt.go b/pkg/prompt/prompt.go index 8c05e6e11..8a3bf1afe 100644 --- a/pkg/prompt/prompt.go +++ b/pkg/prompt/prompt.go @@ -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) } @@ -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) } diff --git a/pkg/views/context/list/view.go b/pkg/views/context/list/view.go index 3f8e9bd78..f2920281c 100644 --- a/pkg/views/context/list/view.go +++ b/pkg/views/context/list/view.go @@ -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 @@ -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 { diff --git a/pkg/views/context/switch/view.go b/pkg/views/context/switch/view.go index 7f9417dba..564845106 100644 --- a/pkg/views/context/switch/view.go +++ b/pkg/views/context/switch/view.go @@ -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 {