Skip to content

selectel/iam-go

Repository files navigation

iam-go: Go SDK for IAM API

Go.dev reference Go Report Card codecov

Package iam-go provides Go SDK to work with the Selectel IAM API.

Jump To:

Documentation

The Go library documentation is available at go.dev.

Getting started

You can use this library to work with the following objects of the Selectel IAM API:

Installation

You can install iam-go via go get command:

go get github.com/selectel/iam-go

Authentication

To work with the Selectel IAM API you first need to:

After that initialize Client with the retrieved token.

Usage example

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)
    }
}

Additional info

  • See examples for more code examples of iam-go
  • Read docs for advanced topics and guides