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

ListImmuRules not working as expected #29

Open
gaglimax opened this issue May 2, 2024 · 0 comments
Open

ListImmuRules not working as expected #29

gaglimax opened this issue May 2, 2024 · 0 comments

Comments

@gaglimax
Copy link

gaglimax commented May 2, 2024

Hi,

When I try to list immutable rules of a project with ListImmuRules method, it returns a 401 error.
I use the admin account and everything works on projects, repositories, artifacts and labels.

Here is my code :

package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/goharbor/go-client/pkg/harbor"
	"github.com/goharbor/go-client/pkg/sdk/v2.0/client/artifact"
	"github.com/goharbor/go-client/pkg/sdk/v2.0/client/immutable"
	"github.com/goharbor/go-client/pkg/sdk/v2.0/client/label"
	"github.com/goharbor/go-client/pkg/sdk/v2.0/client/project"
	"github.com/goharbor/go-client/pkg/sdk/v2.0/client/repository"
)

func main() {
	// Create a new REST client for the Harbor API
	cs, _ := harbor.NewClientSet(&harbor.ClientSetConfig{
		URL:      "https://registry-docker.staging.eul.sncf.fr/api/v2.0",
		Password: "admin",
		Username: "NQs2rE9UNMGLafJ8m7rAZF6Rnf3gR8NPDwL1IKpjbChj1EWKVM",
		Insecure: false,
	})

	h := cs.V2()

	// Get all labels
	scope := "g"
	labels, err := h.Label.ListLabels(context.Background(), &label.ListLabelsParams{Scope: &scope})
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("Labels:", labels.GetPayload())

	// Get all projects
	projects, err := h.Project.ListProjects(context.Background(), &project.ListProjectsParams{})
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("Projects:", projects.GetPayload())

	for _, project := range projects.GetPayload() {
		// Get all repositories in the project
		repositories, err := h.Repository.ListRepositories(context.Background(), &repository.ListRepositoriesParams{ProjectName: project.Name})
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println("Repositories:", repositories.GetPayload())

		for _, repository := range repositories.GetPayload() {
			// Get all artifacts in the repository
			artifacts, err := h.Artifact.ListArtifacts(context.Background(), &artifact.ListArtifactsParams{ProjectName: project.Name, RepositoryName: strings.Join(strings.Split(repository.Name, "/")[1:], "/")})
			if err != nil {
				fmt.Println(err)
				return
			}
			fmt.Println("Artifacts:", artifacts.GetPayload())
		}

		// Get all immutable rules in the project
		immutableRules, err := h.Immutable.ListImmuRules(context.Background(), &immutable.ListImmuRulesParams{ProjectNameOrID: project.Name})
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println("Immutable rules:", immutableRules.GetPayload())
	}
}

Everything works until the ListImmuRules method :
[GET /projects/{project_name_or_id}/immutabletagrules][401] listImmuRulesUnauthorized &{Errors:[0xc000224220]}

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

No branches or pull requests

1 participant