Add ResetAPIKey.
diff --git a/rackspace/identity/v2/users/delegate.go b/rackspace/identity/v2/users/delegate.go
index 94b97dc..6628097 100644
--- a/rackspace/identity/v2/users/delegate.go
+++ b/rackspace/identity/v2/users/delegate.go
@@ -130,3 +130,16 @@
func Delete(client *gophercloud.ServiceClient, id string) os.DeleteResult {
return os.Delete(client, id)
}
+
+// ResetAPIKey resets the User's API key.
+func ResetAPIKey(client *gophercloud.ServiceClient, id string) ResetAPIKeyResult {
+ var result ResetAPIKeyResult
+
+ _, result.Err = perigee.Request("POST", resetAPIKeyURL(client, id), perigee.Options{
+ Results: &result.Body,
+ MoreHeaders: client.AuthenticatedHeaders(),
+ OkCodes: []int{200},
+ })
+
+ return result
+}
diff --git a/rackspace/identity/v2/users/delegate_test.go b/rackspace/identity/v2/users/delegate_test.go
index 616d64c..62faf0c 100644
--- a/rackspace/identity/v2/users/delegate_test.go
+++ b/rackspace/identity/v2/users/delegate_test.go
@@ -97,3 +97,15 @@
res := Delete(client.ServiceClient(), "c39e3de9be2d4c779f1dfd6abacc176d")
th.AssertNoErr(t, res.Err)
}
+
+func TestResetAPIKey(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ mockResetAPIKey(t)
+
+ apiKey, err := ResetAPIKey(client.ServiceClient(), "99").Extract()
+ th.AssertNoErr(t, err)
+ th.AssertEquals(t, "joesmith", apiKey.Username)
+ th.AssertEquals(t, "mooH1eiLahd5ahYood7r", apiKey.APIKey)
+}
diff --git a/rackspace/identity/v2/users/fixtures.go b/rackspace/identity/v2/users/fixtures.go
index e843966..973f39e 100644
--- a/rackspace/identity/v2/users/fixtures.go
+++ b/rackspace/identity/v2/users/fixtures.go
@@ -136,3 +136,19 @@
w.WriteHeader(http.StatusNoContent)
})
}
+
+func mockResetAPIKey(t *testing.T) {
+ th.Mux.HandleFunc("/users/99/OS-KSADM/credentials/RAX-KSKEY:apiKeyCredentials/RAX-AUTH/reset", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprintf(w, `
+{
+ "RAX-KSKEY:apiKeyCredentials": {
+ "username": "joesmith",
+ "apiKey": "mooH1eiLahd5ahYood7r"
+ }
+}`)
+ })
+}
diff --git a/rackspace/identity/v2/users/results.go b/rackspace/identity/v2/users/results.go
index 670060e..6936ecb 100644
--- a/rackspace/identity/v2/users/results.go
+++ b/rackspace/identity/v2/users/results.go
@@ -3,6 +3,7 @@
import (
"strconv"
+ "github.com/rackspace/gophercloud"
os "github.com/rackspace/gophercloud/openstack/identity/v2/users"
"github.com/mitchellh/mapstructure"
@@ -97,3 +98,32 @@
func (r UpdateResult) Extract() (*User, error) {
return commonExtract(r.Body, r.Err)
}
+
+// ResetAPIKeyResult represents the server response to the ResetAPIKey method.
+type ResetAPIKeyResult struct {
+ gophercloud.Result
+}
+
+// ResetAPIKeyValue represents an API Key that has been reset.
+type ResetAPIKeyValue struct {
+ // The Username for this API Key reset.
+ Username string `mapstructure:"username"`
+
+ // The new API Key for this user.
+ APIKey string `mapstructure:"apiKey"`
+}
+
+// Extract will get the Error or ResetAPIKeyValue object out of the ResetAPIKeyResult object.
+func (r ResetAPIKeyResult) Extract() (*ResetAPIKeyValue, error) {
+ if r.Err != nil {
+ return nil, r.Err
+ }
+
+ var response struct {
+ ResetAPIKeyValue ResetAPIKeyValue `mapstructure:"RAX-KSKEY:apiKeyCredentials"`
+ }
+
+ err := mapstructure.Decode(r.Body, &response)
+
+ return &response.ResetAPIKeyValue, err
+}
diff --git a/rackspace/identity/v2/users/urls.go b/rackspace/identity/v2/users/urls.go
new file mode 100644
index 0000000..bc1aaef
--- /dev/null
+++ b/rackspace/identity/v2/users/urls.go
@@ -0,0 +1,7 @@
+package users
+
+import "github.com/rackspace/gophercloud"
+
+func resetAPIKeyURL(client *gophercloud.ServiceClient, id string) string {
+ return client.ServiceURL("users", id, "OS-KSADM", "credentials", "RAX-KSKEY:apiKeyCredentials", "RAX-AUTH", "reset")
+}