Last active
August 13, 2016 18:13
-
-
Save jtopjian/fe27fde637053344a06021b8eba59292 to your computer and use it in GitHub Desktop.
swauth test
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 | |
| import ( | |
| "fmt" | |
| "github.com/gophercloud/gophercloud" | |
| "github.com/gophercloud/gophercloud/openstack" | |
| "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers" | |
| "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/swauth" | |
| ) | |
| func main() { | |
| providerClient, err := openstack.NewClient("http://localhost:8080") | |
| if err != nil { | |
| fmt.Errorf("Unable to obtain provider client: %v", err) | |
| } | |
| authOpts := swauth.AuthOpts{ | |
| User: "test:tester", | |
| Key: "testing", | |
| } | |
| swauthClient := &gophercloud.ServiceClient{ | |
| ProviderClient: providerClient, | |
| Endpoint: "http://localhost:8080", | |
| } | |
| auth, err := swauth.Authenticate(swauthClient, authOpts).Extract() | |
| if err != nil { | |
| fmt.Errorf("Unable to authenticate: %v", err) | |
| } | |
| fmt.Printf("%#v\n", auth) | |
| fmt.Println(auth.Token) | |
| fmt.Println(auth.StorageURL) | |
| swiftClient := &gophercloud.ServiceClient{ | |
| ProviderClient: providerClient, | |
| Endpoint: auth.StorageURL, | |
| } | |
| swiftAuthHeaders := make(map[string]interface{}) | |
| swiftAuthHeaders["X-Auth-Token"] = auth.Token | |
| swiftClient.MoreHeaders = swiftAuthHeaders | |
| allPages, err := containers.List(swiftClient, &containers.ListOpts{Full: true}).AllPages() | |
| if err != nil { | |
| fmt.Errorf("Unable to list containers: %v", err) | |
| } | |
| allContainers, err := containers.ExtractInfo(allPages) | |
| if err != nil { | |
| fmt.Errorf("Unable to extract containers: %v", err) | |
| } | |
| for _, container := range allContainers { | |
| fmt.Printf("Name: %s\n", container.Name) | |
| } | |
| } |
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
| &swauth.GetHeader{Token:"AUTH_tk29d19a777a13484a8cd64c4d3e3b812e", StorageURL:"http://localhost:8080/v1/AUTH_test", CDNURL:""} | |
| AUTH_tk29d19a777a13484a8cd64c4d3e3b812e | |
| http://localhost:8080/v1/AUTH_test | |
| Name: bar | |
| Name: foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment