Skip to content

Instantly share code, notes, and snippets.

@eumel8
Created April 28, 2022 19:16
Show Gist options
  • Select an option

  • Save eumel8/45cf407f952e9ac18af9e32e61f15f4c to your computer and use it in GitHub Desktop.

Select an option

Save eumel8/45cf407f952e9ac18af9e32e61f15f4c to your computer and use it in GitHub Desktop.
otc_token.go
package main
// get a token with project scope "eu-de"
import (
"fmt"
gophercloud "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/openstack"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/identity/v3/tokens"
)
func main() {
opts, err := openstack.AuthOptionsFromEnv()
if err != nil {
panic(err)
}
provider, err := openstack.AuthenticatedClient(opts)
client, _ := openstack.NewIdentityV3(provider, gophercloud.EndpointOpts{})
authOptions := tokens.AuthOptions{
IdentityEndpoint: opts.IdentityEndpoint,
Username: opts.Username,
Password: opts.Password,
Scope: tokens.Scope{ProjectID: "7c3ec0b3db5f476990043258670caf82"},
DomainName: opts.DomainName,
}
token, err := tokens.Create(client, &authOptions).ExtractToken()
if err != nil {
panic(err)
}
fmt.Println(token.ID)
// revoke token
// _ := tokens.Revoke(client, token.ID)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment