dougan7657 2015-12-14 09:07
浏览 120
已采纳

使用Go进行Google Cloud Bigtable身份验证

I'm trying to insert a simple record as in GoDoc. But this returns,

rpc error: code = 7 desc = "User can't access project: tidy-groove"

When I searched for grpc codes, it says..

PermissionDenied Code = 7

// Unauthenticated indicates the request does not have valid
// authentication credentials for the operation.

I've enabled Big table in my console and created a cluster and a service account and recieved the json. What I'm doing wrong here?

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())
}
}
  • 写回答

2条回答 默认 最新

  • dsd119120 2015-12-16 04:12
    关注

    I've solved the problem. It's nothing wrong with the code, but config json itself. So anyone who out there want to authenticate and came here by google search... This code is correct and working perfectly. What I've done wrong is follows.

    First I made a service account and got the json. But google warned me that im not an owner of project hence it wont be added to accept list but anyway it let me download the json. Then I deleted that key from console and requested project owner to create a key for me. There he has created another key with the same name I given.. And since he's the owner no error/warning msgs displayed and successfully json file was downloaded.

    When I tried with that... my question begun. That's when i posted this question. After that with no solutions. I asked owner to delete that key and create another key but with a different name..

    Then it worked! It seems if you try to create a key with non-owner account and then again create with same name ( after deleting original of course ) has no effect. Hope this helps everyone out there :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效