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-go
To 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.
package main
import (
"context"
"fmt"
"log"
"github.com/selectel/iam-go"
)
func main() {
// A KeystoneToken to work with the Selectel IAM API.
// It should be Service User Token
token := "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.
if err != 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 := range users {
fmt.Println("ID:", user.ID)
fmt.Println("KeystoneID:", user.Keystone.ID)
fmt.Println("AuthType:", user.AuthType)
}
}