Skip to content

ListImmuRules not working as expected #29

@gaglimax

Description

@gaglimax

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]}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions