繁体   English   中英

如何在GO中的GCE中连接到客户端

[英]How to connect to client in GCE in GO

我无法连接到客户端。 有什么方法可以将private key idprivate key传递给客户端以获得授权?

所以,到目前为止,我看到了:

ctx := context.Background()

client, err := google.DefaultClient(ctx, compute.ComputeScope)
    if err != nil {
            //...
    }
computeService, err := compute.New(client)
    if err != nil {
            //...
    }

首先,需要在GCE中为服务帐户创建凭据,该凭据将下载json文件,并将用于授权客户端。

Sample Code :

data, err := ioutil.ReadFile("downloadedfile.json")
if err != nil {
   log.Fatal(err)
}
conf, err := google.JWTConfigFromJSON(data, compute.ComputeScope) // give the specific permission for this client.
if err != nil {
  log.Fatal(err)
}
client = conf.Client(oauth2.NoContext)

computeService, err := compute.New(client)
if err != nil {
        //...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM