Feature/filestorage sharetype showaccess (#149)
* sfs: Add support for share type Show Access
* sfs: Add acceptance tests for share type Show Access
* sfs: Remove unused type
* sfs: Fix unit and acceptance test
diff --git a/acceptance/openstack/sharedfilesystems/v2/sharetypes.go b/acceptance/openstack/sharedfilesystems/v2/sharetypes.go
index c965034..97b44bd 100644
--- a/acceptance/openstack/sharedfilesystems/v2/sharetypes.go
+++ b/acceptance/openstack/sharedfilesystems/v2/sharetypes.go
@@ -24,7 +24,7 @@
createOpts := sharetypes.CreateOpts{
Name: shareTypeName,
- IsPublic: true,
+ IsPublic: false,
ExtraSpecs: extraSpecsOps,
}
diff --git a/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go b/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go
index 1209443..7a2c21b 100644
--- a/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go
+++ b/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go
@@ -113,3 +113,25 @@
defer DeleteShareType(t, client, shareType)
}
+
+func TestShareTypeShowAccess(t *testing.T) {
+ client, err := clients.NewSharedFileSystemV2Client()
+ if err != nil {
+ t.Fatalf("Unable to create shared file system client: %v", err)
+ }
+
+ shareType, err := CreateShareType(t, client)
+ if err != nil {
+ t.Fatalf("Unable to create share type: %v", err)
+ }
+
+ _, err = sharetypes.ShowAccess(client, shareType.ID).Extract()
+ if err != nil {
+ t.Fatalf("Unable to retrieve the access details for a share type: %v", err)
+ }
+
+ PrintShareType(t, shareType)
+
+ defer DeleteShareType(t, client, shareType)
+
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/requests.go b/openstack/sharedfilesystems/v2/sharetypes/requests.go
index dca43af..8bfc632 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/requests.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/requests.go
@@ -143,3 +143,9 @@
_, r.Err = client.Delete(unsetExtraSpecsURL(client, id, key), nil)
return
}
+
+// ShowAccess will show access details for an existing ShareType.
+func ShowAccess(client *gophercloud.ServiceClient, id string) (r ShowAccessResult) {
+ _, r.Err = client.Get(showAccessURL(client, id), &r.Body, nil)
+ return
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/results.go b/openstack/sharedfilesystems/v2/sharetypes/results.go
index 6caac40..92a8fab 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/results.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/results.go
@@ -100,3 +100,30 @@
type UnsetExtraSpecsResult struct {
gophercloud.ErrResult
}
+
+// ShareTypeAccess contains all the information associated with an OpenStack
+// ShareTypeAccess.
+type ShareTypeAccess struct {
+ // The share type ID of the member.
+ ShareTypeID string `json:"share_type_id"`
+ // The UUID of the project for which access to the share type is granted.
+ ProjectID string `json:"project_id"`
+}
+
+type shareTypeAccessResult struct {
+ gophercloud.Result
+}
+
+// ShowAccessResult contains the response body and error from a Show access request.
+type ShowAccessResult struct {
+ shareTypeAccessResult
+}
+
+// Extract will get the ShareTypeAccess objects out of the shareTypeAccessResult object.
+func (r ShowAccessResult) Extract() ([]ShareTypeAccess, error) {
+ var s struct {
+ ShareTypeAccess []ShareTypeAccess `json:"share_type_access"`
+ }
+ err := r.ExtractInto(&s)
+ return s.ShareTypeAccess, err
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/testing/fixtures.go b/openstack/sharedfilesystems/v2/sharetypes/testing/fixtures.go
index 4450cbf..03fc83b 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/testing/fixtures.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/testing/fixtures.go
@@ -215,3 +215,26 @@
w.WriteHeader(http.StatusAccepted)
})
}
+
+func MockShowAccessResponse(t *testing.T) {
+ th.Mux.HandleFunc("/types/shareTypeID/share_type_access", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprintf(w, `
+ {
+ "share_type_access": [
+ {
+ "share_type_id": "1732f284-401d-41d9-a494-425451e8b4b8",
+ "project_id": "818a3f48dcd644909b3fa2e45a399a27"
+ },
+ {
+ "share_type_id": "1732f284-401d-41d9-a494-425451e8b4b8",
+ "project_id": "e1284adea3ee4d2482af5ed214f3ad90"
+ }
+ ]
+ }`)
+ })
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go b/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go
index aeb6771..bcc1b16 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go
@@ -161,3 +161,27 @@
res := sharetypes.UnsetExtraSpecs(client.ServiceClient(), "shareTypeID", "my_key")
th.AssertNoErr(t, res.Err)
}
+
+// Verifies that it is possible to see the access for a share type
+func TestShowAccess(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockShowAccessResponse(t)
+
+ expected := []sharetypes.ShareTypeAccess{
+ {
+ ShareTypeID: "1732f284-401d-41d9-a494-425451e8b4b8",
+ ProjectID: "818a3f48dcd644909b3fa2e45a399a27",
+ },
+ {
+ ShareTypeID: "1732f284-401d-41d9-a494-425451e8b4b8",
+ ProjectID: "e1284adea3ee4d2482af5ed214f3ad90",
+ },
+ }
+
+ shareType, err := sharetypes.ShowAccess(client.ServiceClient(), "shareTypeID").Extract()
+ th.AssertNoErr(t, err)
+
+ th.CheckDeepEquals(t, expected, shareType)
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/urls.go b/openstack/sharedfilesystems/v2/sharetypes/urls.go
index 8bbc050..b963c7b 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/urls.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/urls.go
@@ -29,3 +29,7 @@
func unsetExtraSpecsURL(c *gophercloud.ServiceClient, id string, key string) string {
return c.ServiceURL("types", id, "extra_specs", key)
}
+
+func showAccessURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL("types", id, "share_type_access")
+}