我試圖在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