Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat add permissions command #167

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mahbub570
Copy link
Contributor

@mahbub570 mahbub570 commented Aug 15, 2024

Enhanced the permissions command to display system and project permissions.

New Command:
harbor permissions

Fix: #94

@mahbub570
Copy link
Contributor Author

Permissions :
permissions

@Althaf66
Copy link
Collaborator

@mahbub570 Make changes in cmd/harbor/root/permissions.go

package root

import (
	"github.com/goharbor/harbor-cli/pkg/api"
	"github.com/goharbor/harbor-cli/pkg/utils"
	"github.com/goharbor/harbor-cli/pkg/views/permissions"
	log "github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

func permissionsCommand() *cobra.Command {

	cmd := &cobra.Command{
		Use:   "permissions",
		Short: "Manage Harbor permissions",
		Run: func(cmd *cobra.Command, args []string) {
			permission, err := api.GetPermissions()
			if err != nil {
				log.Fatalf("Failed to get permissions: %v\n", err)
			}
			FormatFlag := viper.GetString("output-format")
			if FormatFlag != "" {
				utils.PrintPayloadInJSONFormat(permission)
				return
			}

			permissions.PrintPermissions(permission.Payload)
		},
	}
	
	return cmd
}

@Althaf66
Copy link
Collaborator

Changes in pkg/api/permissions_handler.go

package api

import (
	"github.com/goharbor/go-client/pkg/sdk/v2.0/client/permissions"
	"github.com/goharbor/harbor-cli/pkg/utils"
)

func GetPermissions() (permissions.GetPermissionsOK, error) {
	ctx, client, err := utils.ContextWithClient()
	if err != nil {
		return permissions.GetPermissionsOK{}, err
	}
	
	response, err := client.Permissions.GetPermissions(ctx, &permissions.GetPermissionsParams{})
	if err != nil {
		return permissions.GetPermissionsOK{}, err
	}

	return *response, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

📌 Tracker: Missing and To-Be-Added CLI Commands
2 participants