我试图在GoDoc中插入一条简单的记录。但这返回,Go Google云端Bigtable身份验证
rpc error: code = 7 desc = "User can't access project: tidy-groove"
当我搜索GRPC代码,它说..
PermissionDenied Code = 7
// Unauthenticated indicates the request does not have valid
// authentication credentials for the operation.
我已经启用在我的控制台大表,创建一个集群和服务帐户和收到的JSON 。我在这里做错了什么?
package main
import (
"fmt"
"golang.org/x/net/context"
"golang.org/x/oauth2/google"
"google.golang.org/cloud"
"google.golang.org/cloud/bigtable"
"io/ioutil"
)
func main() {
fmt.Println("Start!")
put()
}
func getClient() *bigtable.Client {
jsonKey, err := ioutil.ReadFile("TestProject-7854ea9op741.json")
if err != nil {
fmt.Println(err.Error())
}
config, err := google.JWTConfigFromJSON(
jsonKey,
bigtable.Scope,
) // or bigtable.AdminScope, etc.
if err != nil {
fmt.Println(err.Error())
}
ctx := context.Background()
client, err := bigtable.NewClient(ctx, "tidy-groove", "asia-east1-b", "test1-bigtable", cloud.WithTokenSource(config.TokenSource(ctx)))
if err != nil {
fmt.Println(err.Error())
}
return client
}
func put() {
ctx := context.Background()
client := getClient()
tbl := client.Open("table1")
mut := bigtable.NewMutation()
mut.Set("links", "maps.google.com", bigtable.Now(), []byte("1"))
mut.Set("links", "golang.org", bigtable.Now(), []byte("1"))
err := tbl.Apply(ctx, "com.google.cloud", mut)
if err != nil {
fmt.Println(err.Error())
}
}
你为什么要做JWTConfigFromJSON? MVM或GCP都不需要这样做。你应该已经配置好了。看看:https://github.com/GoogleCloudPlatform/gcloud-golang/blob/master/examples/bigtable/bigtable-hello/helloworld.go#L42或https://github.com/GoogleCloudPlatform/gcloud-golang /blob/master/examples/bigtable/search/search.go#L120,它使用GOOGLE_APPLICATION_CREDENTIALS env var。 –
我们的项目可能或不可能在不同于Google VM的独立服务器中托管,因此需要可在任何地方工作的身份验证。 – PrasadJay