mittwald / goharbor-client Goto Github PK
View Code? Open in Web Editor NEWGo Client for the Harbor container registry
License: MIT License
Go Client for the Harbor container registry
License: MIT License
I found ListArtfiacts interface response labes is null. When i try to config the parameter "SetWithLabe" to "True", it shows artifacts package is internal. How can i fix it?
Describe the bug
When you try to call GetReplicationPolicyByName()
but no replications are defined, it crashes because it tries to return the first value of an empty list.
To Reproduce
With a clean Harbor instance without any registries configured, try to call GetReplicationPolicyByName()
with a name that does not exist. It will return a panic error.
Expected behavior
The call to GetReplicationPolicyByName()
when the registry does not exist should return the error ErrReplicationNotFound
.
Describe the bug
When you try to call GetRegistryByName
but the registry does not exist, it crashes because tries to return the first value of an empty list.
To Reproduce
With a clean Harbor instance without any registries configured, try to call GetRegistryByName
with a name that does not exist. It will return
2023-09-08T09:48:33+02:00 INFO Observed a panic in reconciler: runtime error: index out of range [0] with length 0 {"controller": "managed/registry.registries.provider-harbor.crossplane.io", "controllerGroup": "registries.provider-harbor.crossplane.io", "controllerKind": "Registry", "Registry": {"name":"foo"}, "namespace": "", "name": "foo", "reconcileID": "bd5e566e-a5ae-4f88-b8cc-9292a674cee9"}
panic: runtime error: index out of range [0] with length 0 [recovered]
panic: runtime error: index out of range [0] with length 0
Expected behavior
The call to GetRegistryByName
when the registry does not exist should return the error ErrRegistryNotFound
.
Log files (optional)
test12023-09-08T09:48:33+02:00 INFO Observed a panic in reconciler: runtime error: index out of range [0] with length 0 {"controller": "managed/registry.registries.provider-harbor.crossplane.io", "controllerGroup": "registries.provider-harbor.crossplane.io", "controllerKind": "Registry", "Registry": {"name":"foo"}, "namespace": "", "name": "foo", "reconcileID": "bd5e566e-a5ae-4f88-b8cc-9292a674cee9"}
panic: runtime error: index out of range [0] with length 0 [recovered]
panic: runtime error: index out of range [0] with length 0
goroutine 175 [running]:
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile.func1()
sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:119 +0x1a8
panic({0x1046f30e0, 0x140005b6180})
runtime/panic.go:884 +0x204
github.com/mittwald/goharbor-client/v5/apiv2/pkg/clients/registry.(*RESTClient).GetRegistryByName(0x140003c1a40, {0x104858348, 0x14000a2b770}, {0x140007386b6?, 0x0?})
github.com/mittwald/goharbor-client/[email protected]/apiv2/pkg/clients/registry/registry.go:92 +0x1f8
github.com/mittwald/goharbor-client/v5/apiv2.(*RESTClient).GetRegistryByName(0x104841440?, {0x104858348?, 0x14000a2b770?}, {0x140007386b6?, 0x1?})
github.com/mittwald/goharbor-client/[email protected]/apiv2/client.go:401 +0x2c
provider-harbor/internal/controller/registry.(*external).Observe(0x140003c1ba0, {0x104858348, 0x14000a2b770}, {0x10486d890?, 0x140001f1180})
provider-harbor/internal/controller/registry/registry.go:122 +0xc0
github.com/crossplane/crossplane-runtime/pkg/reconciler/managed.(*Reconciler).Reconcile(0x1400081c3c0, {0x104858380, 0x14000a2b6b0}, {{{0x0, 0x0}, {0x14000988036, 0x3}}})
github.com/crossplane/[email protected]/pkg/reconciler/managed/reconciler.go:805 +0x223c
github.com/crossplane/crossplane-runtime/pkg/ratelimiter.(*Reconciler).Reconcile(0x140003341e0, {0x104858380, 0x14000a2b6b0}, {{{0x0?, 0x30?}, {0x14000988036?, 0x12d3df301?}}})
github.com/crossplane/[email protected]/pkg/ratelimiter/reconciler.go:54 +0x124
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0x104858380?, {0x104858380?, 0x14000a2b6b0?}, {{{0x0?, 0x104499d80?}, {0x14000988036?, 0x104844ae0?}}})
sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:122 +0x8c
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0x14000647040, {0x1048582d8, 0x140003701e0}, {0x104653280?, 0x1400049ad60?})
sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:323 +0x2c8
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0x14000647040, {0x1048582d8, 0x140003701e0})
sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:274 +0x1b0
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()
sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:235 +0x74
created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2
sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:231 +0x448
make: *** [run] Error 2
Environment:
goharbor-client
5.4.1goharbor
v2.8.4-ad3e767dDescribe your request
A clear and concise description of what you need help with.
# IMPORANT: Please make sure to anonymize any PII like IP addresses and usernames!
package main
import (
"context"
"fmt"
"github.com/mittwald/goharbor-client/v5/apiv2"
config2 "github.com/mittwald/goharbor-client/v5/apiv2/pkg/config"
)
func main() {
conf := config2.Defaults()
client, _ := apiv2.NewRESTClientForHost("http://10.9.68.15/api/","admin", "Harbor12345", conf)
proBaseById, _ :=client.GetProject(context.TODO(),"2")
proBaseByName,_ :=client.GetProject(context.TODO(),"base")
fmt.Println(proBaseById.Name)
fmt.Println(proBaseByName)
}
========Execution results========
GOROOT=/usr/local/go #gosetup
GOPATH=/usr/local/go/bin #gosetup
/usr/local/go/bin/go build -o /private/var/folders/9d/xqw2p6b11rz9npth2cp_3m3w0000gn/T/GoLand/___1go_build_cmdb_test cmdb/test #gosetup
/private/var/folders/9d/xqw2p6b11rz9npth2cp_3m3w0000gn/T/GoLand/___1go_build_cmdb_test
base
<nil>
proBaseByName is nil, anyone can help me?
Describe your request
A clear and concise description of what you need help with.
# IMPORANT: Please make sure to anonymize any PII like IP addresses and usernames!
Describe your request
Hi,
Does apiv1 support /repositories
query?
like this request
https://dockerhub-host/api/repositories?page=1&page_size=15&project_id=2&q=report
ref https://github.com/goharbor/harbor/blob/v1.10.0/api/harbor/swagger.yaml#L1004-L1045
Describe your request
A clear and concise description of what you need help with.
# IMPORANT: Please make sure to anonymize any PII like IP addresses and usernames!
I found that setting paging parameters is currently only used when NewRESTClientForHost
is initialized, how to make paging calls when getting data, such as getting List Project
.
Describe the bug
Apparently, the Harbor API have two parameters to set the deletion behaviour on replication policies: replicate_deletion
and deletion
. Although the documentation says that the deletion
parameter is deprecated, it is the one used under the hood.
To Reproduce
Try to create a replication policy with replicateDeletion
set to true. It should not set the deletion.
Expected behavior
On the client, when we set the replicateDeletion
both parameters the replicate_deletion
and the deletion
are configured on the request to harbor.
Environment:
goharbor-client
version: v5.5.0
goharbor
version: v2.9.1-5cbb1b01
It seems that XtotalCount did not return,only list return。
func (c *RESTClient) ListProjects(ctx context.Context, nameFilter string) ([]*model.Project, error)
how do I get total if I want to return paging data like this
{
data: [],
total: 50
}
2022-07-06T06:53:45Z [ERROR] [/server/middleware/security/basic_auth.go:72][client IP="192.168.122.123" requestID="2466ffd6-fc12-47a5-b888-1d69dce44a98" user agent="Go-http-client/1.1"]: failed to authenticate user:testt, error:Failed to authenticate user, due to error 'Invalid credentials'
Describe your request
A clear and concise description of what you need help with.
Can this client be used to upload a container built with docker into a harbor registry? If so what functions do I use to add the container? Do I use CreateTag to retag the container name for harbor? Do I use AddProjectMember to add the container to the project? Does this client allow you to update private projects?
# IMPORTANT: Please make sure to anonymize any PII like IP addresses and usernames!
Describe your request
I would like to list Harbor repository vulnerability additions using the Harbor client.
I could not find how to do this:
GetVulnerabilitiesAddition
functions calling GET /projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/additions/vulnerabilities
exist in the code.
apiv2.internal.api.client.artifact.Client.GetVulnerabilitiesAddition
exists but you cannot access this from outside the package, I think?(This issue is identical to #99 except it concerns a different endpoint.)
i can not find any examples in this project , can you make some examples?
how to make InsecureSkipVerify==true
I found that harbor's native list api does not have paging information like the total number of items, but a separate statistic api. There is also a statistic client in harbor-client, but it is not instantiated into restfulClient, and this statistic client is in the internal directory. Among them, I cannot use it directly, what should I do if I want to use this function?
Can we use opts *config.Options
to move to the input parameters of each method? Do not uniformly set in NewRESTClient
.
thanks
Describe your request
I would like to list the Harbor audit logs using the Harbor client.
I could not find how to do this:
ListAuditLogs
function calling GET /audit-logs
exist in the code.
apiv2.internal.api.client.auditlog.Client.ListAuditLogs
exists but you cannot access this from outside the package, I think?apiv2.RESTClient.ListAuditLogs
does not exist, I think?Am I missing some package functionality, or is this indeed missing from the current code?
Describe the bug
In robot client (v2), GetRobotAccountByName
, DeleteRobotAccountByName
and RefreshRobotAccountSecretByName
need loop over the result of ListRobotAccounts
methods. But it is limited by (1) client opt PageSize
and (2) Harbor API enforce (100 items/req), therefore, sometimes above methods are not working correctly if the result return by ListRobotAccounts
method not covers all existed robot accounts
To Reproduce
test-[1-11]
GetRobotAccountByName
/RefreshRobotAccountSecretByName
/RefreshRobotAccountSecretByName
to get/refresh-sec/delete robot account test-11
resource unknown
(ErrRobotAccountUnknownResourceMsg)Expected behavior
robot-11
should be existed to get/refresh-sec/delete success
Describe the bug
The generated error not handled on the client shows a memory address. For instance:
GET /projects/{project_name_or_id}][401] getProjectUnauthorized &{Errors:[0x140003c42c0]
To Reproduce
Force any error not handled on the handleSwaggerXYZErrors()
functions.
Expected behaviour
The error generated by swagger is a proper string and does not include memory addresses.
Describe the bug
I would like to list Harbor Projects and Robot Accounts using this Harbor client.
I could not find how to do list more than 10 projects/robot accounts using ListProjects()
or ListRobotAccounts()
.
It is possible to assign page/ page size parameters in the internal package V2Client.Robot.ListRobot()
\ V2Client.Project.ListProjects()
. Is it possible to use this functionality in the goharbor-client?
Expected behavior
ListProjects()
or ListRobotAccounts()
{"message":"listing artifacts: X-Total-Count in header must be of type int64: \"\"","status":"failed"}
"github.com/mittwald/goharbor-client/v5/apiv2"
"github.com/mittwald/goharbor-client/v5/apiv2/pkg/config"
func getLatestTag(endpoint, username, password, projectName, env, appName string) (string, error) {
ctx := context.Background()
// Initialize Harbor client
harborClient, err := apiv2.NewRESTClientForHost(endpoint, username, password, &config.Options{})
if err != nil {
return "", fmt.Errorf("initializing Harbor client: %w", err)
}
// Get the specified repository
repoName := fmt.Sprintf("%s/%s", strings.ToLower(env), strings.ToLower(appName))
// Get the artifacts of the specified repository
artifacts, err := harborClient.ListArtifacts(ctx, projectName, repoName)
if err != nil {
return "", fmt.Errorf("listing artifacts: %w", err)
}
if len(artifacts) == 0 {
return "", fmt.Errorf("no artifacts found")
}
// Assume the latest artifact is the first one in the list
latestArtifact := artifacts[0]
if len(latestArtifact.Tags) == 0 {
return "", fmt.Errorf("no tags found in the latest artifact")
}
// Assume the latest tag is the first one in the list
latestTag := latestArtifact.Tags[0]
return latestTag.Name, nil
}
Describe the bug
GetProject
returns ErrProjectNotFound
for any error gotten from the Harbor API.
This code changes the error to ErrProjectNotFound
: https://github.com/mittwald/goharbor-client/blob/master/apiv2/pkg/clients/project/project.go#L112-L114. The internal GetProject
function returns a nil response whenever the API returns an error: https://github.com/mittwald/goharbor-client/blob/master/apiv2/internal/api/client/project/project_client.go#L192-L194. This means that any error results in ErrProjectNotFound
and handleSwaggerProjectErrors
is never called.
To Reproduce
Call GetProject
with the wrong Harbor credentials in the client.
Expected behavior
It should return ErrUnauthorized
but returns ErrProjectNotFound
.
Environment:
goharbor-client
version: v0.5.5goharbor
version: v2.9.1-5cbb1b01Is your feature request related to a problem? Please describe.
Version 2.2.0 of Harbor was released today. It includes a new system-level robot account API.
https://github.com/goharbor/harbor/releases/tag/v2.2.0
Describe the solution you'd like
I'd like to use this API in the goharbor-client
library.
Is your feature request related to a problem? Please describe.
目前没有实现获取harbor 配置以及修改harbor 配置的api
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
Describe the bug
Getting the following error when using ListRepositories(): X-Total-Count in header must be of type int64: ""
To Reproduce
import "github.com/mittwald/goharbor-client/v5/apiv2"
harborClient, err := apiv2.NewRESTClientForHost("https://demo.goharbor.io", "<redacted username>", "<redacted password>", nil)
if err != nil {
println(err.Error())
}
repos, err := harborClient.ListRepositories(ctx, "<redacted project name>")
if err != nil {
println(err.Error())
}
...
The call to ListRepositories() yields X-Total-Count in header must be of type int64: ""
I can do the following with curl:
$ curl -v -k -u <redacted username>:<redacted password> https://demo.goharbor.io/api/v2.0/projects/<redacted project name>/repositories
< HTTP/2 200
< date: Wed, 20 Sep 2023 22:12:27 GMT
< content-type: application/json
< content-length: 1269
< server: nginx
< set-cookie: sid=262a7d70e00177240922149b208df3bc; Path=/; Secure; HttpOnly
< x-request-id: 3137777c-94a7-47b7-81b7-1e201c0fab42
< x-total-count: 7
< strict-transport-security: max-age=31536000; includeSubdomains; preload
< x-frame-options: DENY
< content-security-policy: frame-ancestors 'none'
<
<redacted json contents>
Environment:
goharbor-client
version: 5.4.2goharbor
version: v2.9.0-6d1ad65cHello, can you please give some examples, like operation codes to illustrate some cases in using this API.
Thanks
Describe the bug
The RESTClient object does not implements the Client interface
To Reproduce
Create a client variable and assign to it a new RESTClient.
example:
var _ Client = (*RESTClient)(nil)
Expected behavior
The RESTClient object implements the Client interface so we can create proper mocks for it
Fixed on the following PR: #172
Describe your request
I would like to list the Harbor users using the Harbor client.
I could not find how to do this:
GetUsers
functions calling GET /users
exist in the code.
apiv1.internal.api.client.products.Client.GetUsers
exists but you cannot access this from outside the package, I think?apiv2.internal.legacyapi.client.products.Client.GetUsers
exists but you cannot access this from outside the package, I think?apiv2.RESTClient.ListUsers
does not exist, I think?apiv2.RESTClient.GetUser
does exist but it wraps apiv2.internal.legacyapi.client.products.Client.GetUsers
to require a username parameter; it does not allow this parameter to be empty.Am I missing some package functionality, or is this indeed missing from the current code?
Describe your request
I would like to list Harbor repositories using the Harbor client.
I could not find how to do this:
ListRepositories
functions calling GET /projects/{project_name}/repositories
exist in the code.
apiv2.internal.api.client.repository.Client.ListRepositories
exists but you cannot access this from outside the package, I think?(This issue is identical to #99 except it concerns a different endpoint.)
I see that the API Client internal folder contains a usergroup package, which could do this, but the RESTClient doesn't.
https://pkg.go.dev/github.com/mittwald/goharbor-client/[email protected]/apiv2/internal/api/client/usergroup
https://github.com/mittwald/goharbor-client/tree/v5.0.3/apiv2
Is it possible somehow to manipulate (eg.: delete) groups using this package?
Hello,
I'd like to create group in a Harbor instance binded to a LDAP server.
Is there a way to achieve that using this library?
For now I am using:
cat template/create-ldap-group.tpl
{
"group_name": "__group_name__",
"ldap_group_dn": "__group_dn__",
"group_type": 0,
"id": 0
}
Is your feature request related to a problem? Please describe.
As in the method's description at:
NewRobotAccount
should return an additional RobotCreated
object, not only an error:Because the Secret
of the created Robot Account could not retrieve later by Get methods, so, we need to know it after this method call.
Hep with Replication Policies
Hey folks!
I'm trying to use the client to automate how we create replication policies. I'm getting an issue that seems to come from swagger itself when I use NewReplicationPolicy
:
"&[] (*[]*legacy.Registry) is not supported by the TextConsumer, can be resolved by supporting TextUnmarshaler interface"
I don't understand why it says *[]*legacy.Registry
since I'm just passing single registry objects.
Not sure if this is related but:
I'm hesitant to open this as a bug, since I'm not really sure if it's on my side, swagger side or your side 😅 . Can I get some hep please?
How to configure it to access the self-signed https harbor
❯ go run main.go
error Get "https://xxxx/api/v2.0/registries?name=public": x509: certificate signed by unknown authority
Describe your request
Hi all, I'm trying to create a replication rule using the Method NewReplicationPolicy
which is throwing:
[POST /replication/policies][400] createReplicationPolicyBadRequest &{Errors:[0xc00039e5a0]
What's the best way to find out the specific part causing the error?
This is what I'm returning when calling the mentioned method
return s.Client.NewReplicationPolicy(
ctx,
policy.DestRegistry,
nil,
policy.ReplicateDeletion,
policy.Override,
policy.Enabled,
policy.Filters,
policy.Trigger,
policy.DestNamespace,
policy.Description,
policy.Name)
The filters
I'm passing in:
rp.Filters = []*model.ReplicationFilter{
{
Decoration: "",
Type: "resource",
Value: rule.FilterType,
},
}
Where rule.FilterType
has the value of image
The trigger
is:
rp.Trigger = &model.ReplicationTrigger{
TriggerSettings: &model.ReplicationTriggerSettings{Cron: ""},
Type: rule.Trigger,
}
Where rule.Trigger
has the value of event_based
.
All the values are correct (AFAICT). I'm getting the dest
and src
registry using the GetRegistryById
and the ListRegistries
respectively.
I'm inspecting the error type and I'm getting:
error type: *replication.CreateReplicationPolicyBadRequest
Which is from an internal package type and I cannot use it to inspect further.
I would appreciate any help.
Is your feature request related to a problem? Please describe.
Implement Configurations client package
Describe the solution you'd like
Implement Configurations client package so Configurations endpoints are available
Describe alternatives you've considered
NA
Additional context
API already implemented
There appear to be some changes to robot accounts in Harbor 2.2.x vs 2.1.x
Some fields are renamed, if we look at https://github.com/mittwald/goharbor-client/blob/master/apiv2/model/legacy/robot_account.go#L18-L43
Two things I've noticed so far (there could be more)
disabled
is now disable
expires_at
field, Harbor ignores it and creates it with the default 30 days.Is there a plan to support changes for Harbor 2.2.x ?
This is an outstanding project. I think it is a perfect candidate to add it to the https://github.com/container-registry/awesome-harbor.
Is your feature request related to a problem? Please describe.
I can't see a method to get all charts data in repositories. If I get a repository and list artifacts in it, then I cannot see the ones that are type Chart, only type IMAGE
.
Is the chartrepo
a different domain?
Describe the solution you'd like
Methods associated with Helm Charts info. Something like ListAllCharts
GetChart
Additional context
I can see that there are two types in Models
which are ChartMedata
and ChartVersion
but I don't see any method associated with them.
Describe your request
I would like to get the Harbor system CVE Allowlist. using the Harbor client.
I could not find how to do this:
GetSystemCVEAllowlist
functions calling GET /system/CVEAllowlist
exist in the code.
apiv2.internal.legacyapi.client.products.Client.GetSystemCVEAllowlist
exists but you cannot access this from outside the package, I think?(This issue is identical to #99 except it concerns a different endpoint.)
Describe your request
A clear and concise description of what you need help with.
# IMPORANT: Please make sure to anonymize any PII like IP addresses and usernames!
Describe the bug
To Reproduce
Steps to reproduce the behavior.
docker pull alpine
docker tag alpine harbor.mydomain.com/project/a/b:latest
docker push harbor.mydomain.com/project/a/b:latest
List tags for 'project/a/b' error: [GET /projects/{project_name}/repositories/{repository_name}/artifacts][404] listArtifactsNotFound &{Errors:[0xc0003be7c0]}
while delete the tag, will requested the a/b
not a%252Fb
, ref https://github.com/goharbor/harbor/blob/f910c5654baf64a090f5b423ee6990d9f9adbc61/api/v2.0/swagger.yaml#L6242
Expected behavior
A clear and concise description of what you expected to happen.
Log files (optional)
If applicable, add log files to help explain your problem.
Environment:
goharbor-client
versiongoharbor
version# IMPORANT: Please make sure to anonymize any PII like IP addresses and usernames!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.