英文:
How to extract list of docker images inside GCP artifact registry
问题
我想要列出 GCP Artifact Registry 中所有的存储库,使用的是 Golang 语言。
当前的代码如下:
c, err := artifactregistry.NewClient(ctx, option.WithCredentialsFile("<service account json>"))
if err != nil {
// 这里没有错误
}
defer c.Close()
req := &artifactregistrypb.ListRepositoriesRequest{
Parent: "<project-id>",
}
it := c.ListRepositories(ctx, req)
for {
resp, err := it.Next()
if err == nil {
fmt.Println("resp", resp)
} else {
fmt.Println("err =>", err)
}
}
错误信息显示为:Invalid field value in the request.
或者有时候会显示 Request contains an invalid argument
。
我在这里做错了什么?Parent
参数是什么意思?(在 ListRepositoriesRequest
中)
进一步调查后,我发现传递给 Parent
的值会放在 x-goog-request-params
中,正确的格式应该是什么?
英文:
I want to list all the repositories inside GCP artifact registry in golang.
Current code : (https://pkg.go.dev/cloud.google.com/go/artifactregistry/apiv1beta2)
c, err := artifactregistry.NewClient(ctx, option.WithCredentialsFile("<service account json>"))
if err != nil {
// no error here
}
defer c.Close()
req := &artifactregistrypb.ListRepositoriesRequest{
Parent: "<project-id>",
}
it := c.ListRepositories(ctx, req)
for {
resp, err := it.Next()
if err == nil {
fmt.Println("resp", resp)
} else {
fmt.Println("err ==>", err)
}
}
The error prints: Invalid field value in the request.
OR sometimes I get Request contains an invalid argument
What am I doing wrong here ? and What does the "Parent" mean ? (in ListRepositoriesRequest)
On further digging, I found that the value passed in the Parent goes to : "x-goog-request-params", what should be the correct format for this ?
答案1
得分: 2
有时候库/ API 的文档写得很好,有时候不太好...
这是 REST API,你可以在 API 浏览器中测试(右侧边栏)。经过一些测试,父级必须具有以下格式:
projects/<PROJECT_ID>/locations/<REGION>
尝试使用这个格式来解决你的问题。
英文:
Sometime the libraries/api are well documented, sometime not...
Here the REST API that you can test in the API explorer (right hand side bar). After some tests, the parent must have that format
projects/<PROJECT_ID>/locations/<REGION>
Try with that to solve your issue
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论