Package iam-go provides Go SDK to work with the Selectel IAM API.
Jump To:
The Go library documentation is available at go.dev.
You can use this library to work with the following objects of the Selectel IAM API:
You can install iam-go via go get command:
go get github.com/selectel/iam-goTo work with the Selectel IAM API you first need to:
- Create a Selectel account: registration page.
- Retrieve a Keystone Token for your account via API or go-selvpcclient.
After that initialize Client with the retrieved token.
[!NOTE] It is highly recommended to use the
WithUserAgentPrefixoption to set a custom User-Agent for the client.
package main
import (
"context""fmt""log""github.com/selectel/iam-go"
)
funcmain() {
// A KeystoneToken to work with the Selectel IAM API.// It should be Service User Tokentoken:="gAAAAABeVNzu-..."// A Prefix to be added to User-Agent.prefix:="iam-custom"// Create a new IAM client.iamClient, err:=iam.New(
iam.WithAuthOpts(&iam.AuthOpts{KeystoneToken: token}),
iam.WithUserAgentPrefix(prefix),
)
// Handle the error.iferr!=nil {
log.Fatalf("Error occured: %s", err)
return
}
// Get the Users instance.usersAPI:=iamClient.Users// Prepare an empty context.ctx:=context.Background()
// Get all users.users:=usersAPI.List(ctx)
// Print info about each user.for_, user:=rangeusers {
fmt.Println("ID:", user.ID)
fmt.Println("KeystoneID:", user.Keystone.ID)
fmt.Println("AuthType:", user.AuthType)
}
}