Created
May 5, 2022 07:20
-
-
Save nikolaymatrosov/07ac6dbfc1afbc9029f5a004c43975f4 to your computer and use it in GitHub Desktop.
Yandex Cloud Service Account Go example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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