簡體   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