Created
April 28, 2022 19:16
-
-
Save eumel8/45cf407f952e9ac18af9e32e61f15f4c to your computer and use it in GitHub Desktop.
otc_token.go
This file contains hidden or 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 | |
| // 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