Skip to content

Instantly share code, notes, and snippets.

@nikolaymatrosov
Created May 5, 2022 07:20
Show Gist options
  • Save nikolaymatrosov/07ac6dbfc1afbc9029f5a004c43975f4 to your computer and use it in GitHub Desktop.
Save nikolaymatrosov/07ac6dbfc1afbc9029f5a004c43975f4 to your computer and use it in GitHub Desktop.
Yandex Cloud Service Account Go example
package main
import (
"context"
"fmt"
"github.com/yandex-cloud/go-genproto/yandex/cloud/resourcemanager/v1"
"github.com/yandex-cloud/go-sdk"
"github.com/yandex-cloud/go-sdk/iamkey"
)
func main() {
ctx := context.Background()
key, err := iamkey.ReadFromJSONFile("./key.json")
if err != nil {
print(err)
return
}
cred, err := ycsdk.ServiceAccountKey(key)
sdk, err := ycsdk.Build(ctx, ycsdk.Config{
Credentials: cred,
})
if err != nil {
print(err)
return
}
iter := sdk.ResourceManager().Folder().FolderIterator(ctx, &resourcemanager.ListFoldersRequest{
CloudId: "b1g**",
})
for iter.Next() {
folder := iter.Value()
fmt.Printf("%s\t%s\n", folder.Id, folder.Name)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment