如何提取 Google Cloud Platform(GCP)Artifact Registry 中的 Docker 镜像列表

huangapple go评论75阅读模式
英文:

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(&quot;&lt;service account json&gt;&quot;))
	if err != nil {
		// no error here
	}
	defer c.Close()

	req := &amp;artifactregistrypb.ListRepositoriesRequest{
		Parent: &quot;&lt;project-id&gt;&quot;,
	}
	it := c.ListRepositories(ctx, req)
	for {
		resp, err := it.Next()
		if err == nil {
			fmt.Println(&quot;resp&quot;, resp)
		} else {
			fmt.Println(&quot;err ==&gt;&quot;, 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/&lt;PROJECT_ID&gt;/locations/&lt;REGION&gt;

Try with that to solve your issue

huangapple
  • 本文由 发表于 2022年1月17日 18:12:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/70739640.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定