我正在使用以下代碼列出dockerGCR 中可用的存盤庫
package main
import (
"context"
"fmt"
"log"
"github.com/google/go-containerregistry/pkg/authn"
gcr "github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/google"
"github.com/google/go-containerregistry/pkg/v1/remote"
)
func main() {
auth, err := google.NewGcloudAuthenticator()
if err != nil {
log.Fatal(err)
}
fmt.Println(auth)
registry, err := gcr.NewRegistry("gcr.io")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
repos, err := remote.Catalog(ctx, registry, remote.WithAuthFromKeychain(authn.DefaultKeychain))
if err != nil {
log.Fatal(err)
}
for _, repoName := range repos {
fmt.Println(repoName)
}
}
問題是,盡管我已經gcloud config set project對特定專案執行了顯式,但呼叫上述程式將列出我有權訪問的所有組織和所有專案的所有存盤庫。gcloud
有沒有辦法限制上面的代碼,以便它列出特定組織/專案的 gcr 存盤庫?
uj5u.com熱心網友回復:
"Checking the Container Registry API, and there's no way explained there to do so (seems to only implement the Docker API, which does not understand the concept of projects). There is suggested to migrate to Artifact Registry. Is this a change that you can make? Or do you need to use the Google Container Registry?" - @Jofre
"The GCP project in which a GCR repository (not registry) is created are named [(us|eu|..).]gcr.io/${PROJECT}. The registry root is gcr.io. There's a NewRepository method too that may permit referencing the Project to give you only those images. Projects are a primary resource container in GCP. You'll probably want to enumerate the projects in an Org and then enumerate the content of the repositories (!) using the approach above. You can check whether GCR is enabled in a project but likely easier to just try to enumerate its images. But, this is probably the way you'll have to proceed. Note gcloud config set project only applies to gcloud (CLI) commands not SDKs." - @DazWilkin
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/358277.html
上一篇:在wasm構建中使用可選引數
下一篇:在字串中的單詞之間添加字符
