Beginning work on add user role
diff --git a/openstack/identity/v2/extensions/admin/roles/fixtures.go b/openstack/identity/v2/extensions/admin/roles/fixtures.go
index 04fccd7..e92476c 100644
--- a/openstack/identity/v2/extensions/admin/roles/fixtures.go
+++ b/openstack/identity/v2/extensions/admin/roles/fixtures.go
@@ -30,3 +30,11 @@
`)
})
}
+
+func MockAddUserRoleResponse(t *testing.T) {
+ th.Mux.HandleFunc("/tenants/{tenant_id}/users/{user_id}/OS-KSADMN/roles/{role_id}", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ w.WriteHeader(http.StatusCreated)
+ })
+}
diff --git a/openstack/identity/v2/extensions/admin/roles/requests.go b/openstack/identity/v2/extensions/admin/roles/requests.go
index a748fff..df58eec 100644
--- a/openstack/identity/v2/extensions/admin/roles/requests.go
+++ b/openstack/identity/v2/extensions/admin/roles/requests.go
@@ -11,3 +11,14 @@
}
return pagination.NewPager(client, rootURL(client), createPage)
}
+
+func AddRoleToUser(client *gophercloud.ServiceClient, tenantID, userID, roleID string) AddRoleResult {
+ var result AddRoleResult
+
+ _, result.Err = perigee.Request("PUT", userRoleURL(client, tenantID, userID, roleID), perigee.Options{
+ MoreHeaders: client.AuthenticatedHeaders(),
+ OkCodes: []int{201},
+ })
+
+ return result
+}
diff --git a/openstack/identity/v2/extensions/admin/roles/requests_test.go b/openstack/identity/v2/extensions/admin/roles/requests_test.go
index ce0f9aa..70d1fa7 100644
--- a/openstack/identity/v2/extensions/admin/roles/requests_test.go
+++ b/openstack/identity/v2/extensions/admin/roles/requests_test.go
@@ -40,3 +40,14 @@
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, count)
}
+
+func TestAddUserRole(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockAddUserRoleResponse(t)
+
+ err := AddRoleToUser(client.ServiceClient(), "{tenant_id}", "{user_id}", "{role_id}").ExtractErr()
+
+ th.AssertNoErr(t, err)
+}
diff --git a/openstack/identity/v2/extensions/admin/roles/results.go b/openstack/identity/v2/extensions/admin/roles/results.go
index c829c01..dfa2665 100644
--- a/openstack/identity/v2/extensions/admin/roles/results.go
+++ b/openstack/identity/v2/extensions/admin/roles/results.go
@@ -2,7 +2,7 @@
import (
"github.com/mitchellh/mapstructure"
-
+ "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
)
@@ -41,3 +41,7 @@
err := mapstructure.Decode(casted, &response)
return response.Roles, err
}
+
+type AddRoleResult struct {
+ gophercloud.ErrResult
+}