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

"github.com/goharbor/harbor-cli/pkg/api"
"github.com/goharbor/harbor-cli/pkg/utils"
contextview "github.com/goharbor/harbor-cli/pkg/views/context"
"github.com/goharbor/harbor-cli/pkg/views/context/list"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -47,9 +47,9 @@ func ListContextCommand() *cobra.Command {
return
}
} else {
var cxlist []api.ContextListView
var cxlist []contextview.ContextListView
for _, cred := range config.Credentials {
cx := api.ContextListView{Name: cred.Name, Username: cred.Username, Server: cred.ServerAddress}
cx := contextview.ContextListView{Name: cred.Name, Username: cred.Username, Server: cred.ServerAddress}
cxlist = append(cxlist, cx)
}
currentCredential := config.CurrentCredentialName
Expand Down
40 changes: 33 additions & 7 deletions cmd/harbor/root/registry/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
package registry

import (
"github.com/goharbor/go-client/pkg/sdk/v2.0/models"
"github.com/goharbor/harbor-cli/pkg/api"
"github.com/goharbor/harbor-cli/pkg/views/registry/create"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func CreateRegistryCommand() *cobra.Command {
var opts api.CreateRegView
var opts create.CreateView

cmd := &cobra.Command{
Use: "create",
Expand All @@ -30,12 +31,12 @@ func CreateRegistryCommand() *cobra.Command {
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
var err error
createView := &api.CreateRegView{
createView := &create.CreateView{
Name: opts.Name,
Type: opts.Type,
Description: opts.Description,
URL: opts.URL,
Credential: api.RegistryCredential{
Credential: create.RegistryCredential{
AccessKey: opts.Credential.AccessKey,
Type: opts.Credential.Type,
AccessSecret: opts.Credential.AccessSecret,
Expand All @@ -44,7 +45,19 @@ func CreateRegistryCommand() *cobra.Command {
}

if opts.Name != "" && opts.Type != "" && opts.URL != "" {
err = api.CreateRegistry(opts)
registryModel := &models.Registry{
Name: opts.Name,
Type: opts.Type,
Description: opts.Description,
URL: opts.URL,
Credential: &models.RegistryCredential{
AccessKey: opts.Credential.AccessKey,
AccessSecret: opts.Credential.AccessSecret,
Type: opts.Credential.Type,
},
Insecure: opts.Insecure,
}
err = api.CreateRegistry(registryModel)
} else {
err = createRegistryView(createView)
}
Expand Down Expand Up @@ -92,11 +105,24 @@ func CreateRegistryCommand() *cobra.Command {
return cmd
}

func createRegistryView(createView *api.CreateRegView) error {
func createRegistryView(createView *create.CreateView) error {
if createView == nil {
createView = &api.CreateRegView{}
createView = &create.CreateView{}
}

create.CreateRegistryView(createView)
return api.CreateRegistry(*createView)

registryModel := &models.Registry{
Name: createView.Name,
Type: createView.Type,
Description: createView.Description,
URL: createView.URL,
Credential: &models.RegistryCredential{
AccessKey: createView.Credential.AccessKey,
AccessSecret: createView.Credential.AccessSecret,
Type: createView.Credential.Type,
},
Insecure: createView.Insecure,
}
return api.CreateRegistry(registryModel)
}
Binary file added harbor-dev
Binary file not shown.
26 changes: 26 additions & 0 deletions pkg/api/common_types.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 represents common list parameters used by multiple API handlers.
type ListFlags struct {
ProjectID int64
Scope string
Name string
Page int64
PageSize int64
Q string
Sort string
Public bool
}
48 changes: 3 additions & 45 deletions pkg/api/types.go → pkg/api/member_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,7 @@ 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
// ListMemberOptions provides options for listing project members.
type ListMemberOptions struct {
XIsResourceName bool
ProjectNameOrID string
Expand All @@ -67,15 +25,15 @@ type ListMemberOptions struct {
WithDetail bool
}

// Provides type for Update member
// UpdateMemberOptions provides options for updating a project member.
type UpdateMemberOptions struct {
XIsResourceName bool
ID int64
ProjectNameOrID string
RoleID *models.RoleRequest
}

// Provides Params for getting the Member
// GetMemberOptions provides parameters for getting a specific project member.
type GetMemberOptions struct {
XIsResourceName bool
ID int64
Expand Down
22 changes: 22 additions & 0 deletions pkg/api/quota_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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

type ListQuotaFlags struct {
PageSize int64
Page int64
Sort string
Reference string
ReferenceID string
}
15 changes: 2 additions & 13 deletions pkg/api/registry_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func ListRegistries(opts ...ListFlags) (*registry.ListRegistriesOK, error) {
return response, nil
}

func CreateRegistry(opts CreateRegView) error {
func CreateRegistry(opts *models.Registry) error {
ctx, client, err := utils.ContextWithClient()
if err != nil {
return err
Expand All @@ -57,18 +57,7 @@ func CreateRegistry(opts CreateRegView) error {
_, err = client.Registry.CreateRegistry(
ctx,
&registry.CreateRegistryParams{
Registry: &models.Registry{
Credential: &models.RegistryCredential{
AccessKey: opts.Credential.AccessKey,
AccessSecret: opts.Credential.AccessSecret,
Type: opts.Credential.Type,
},
Description: opts.Description,
Insecure: opts.Insecure,
Name: opts.Name,
Type: opts.Type,
URL: opts.URL,
},
Registry: opts,
},
)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions pkg/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/goharbor/harbor-cli/pkg/constants"
aview "github.com/goharbor/harbor-cli/pkg/views/artifact/select"
tview "github.com/goharbor/harbor-cli/pkg/views/artifact/tags/select"
contextview "github.com/goharbor/harbor-cli/pkg/views/context"
immview "github.com/goharbor/harbor-cli/pkg/views/immutable/select"
instview "github.com/goharbor/harbor-cli/pkg/views/instance/select"
lview "github.com/goharbor/harbor-cli/pkg/views/label/select"
Expand Down Expand Up @@ -287,7 +288,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 @@ -302,9 +303,9 @@ func GetActiveContextFromUser() (string, error) {
if err != nil {
return "", err
}
var cxlist []api.ContextListView
var cxlist []contextview.ContextListView
for _, cred := range config.Credentials {
cx := api.ContextListView{Name: cred.Name, Username: cred.Username, Server: cred.ServerAddress}
cx := contextview.ContextListView{Name: cred.Name, Username: cred.Username, Server: cred.ServerAddress}
cxlist = append(cxlist, cx)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/views/context/list/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ 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"
contextview "github.com/goharbor/harbor-cli/pkg/views/context"
)

var columns = []table.Column{
Expand All @@ -32,7 +32,7 @@ var columns = []table.Column{
{Title: "Server Address", Width: tablelist.WidthXXL},
}

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

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

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

for _, ctx := range contexts {
Expand Down
4 changes: 2 additions & 2 deletions pkg/views/context/switch/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ 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"
contextview "github.com/goharbor/harbor-cli/pkg/views/context"
)

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

for i, ctx := range contexts {
Expand Down
23 changes: 23 additions & 0 deletions pkg/views/context/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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 contextview holds shared types for context-related views.
package contextview

// ContextListView represents a context entry used in list/switch views.
type ContextListView struct {
Name string
Username string
Server string
}
Comment on lines +16 to +23
Copy link
Contributor

Choose a reason for hiding this comment

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

These can follow the existing structure and be included in the view.go itself.

31 changes: 31 additions & 0 deletions pkg/views/registry/create/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 create

// RegistryCredential holds credentials for a registry provider in the view layer.
type RegistryCredential struct {
AccessKey string `json:"access_key,omitempty"`
Type string `json:"type,omitempty"`
AccessSecret string `json:"access_secret,omitempty"`
}

// CreateView is the interactive view model to create a registry.
type CreateView struct {
Name string
Type string
Description string
URL string
Credential RegistryCredential
Insecure bool
}
Comment on lines +14 to +31
Copy link
Contributor

Choose a reason for hiding this comment

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

These can follow the existing structure and be included in the view.go itself.

2 changes: 1 addition & 1 deletion pkg/views/registry/create/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type RegistryOption struct {
Name string
}

func CreateRegistryView(createView *api.CreateRegView) {
func CreateRegistryView(createView *CreateView) {
registries, _ := api.GetRegistryProviders()

// Initialize a slice to hold registry options
Expand Down
Loading