Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keystone: add v3 OS-FEDERATION mappings get operation #2543

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions acceptance/openstack/identity/v3/federation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ func TestMappingsCRUD(t *testing.T) {
},
}

actual, err := federation.CreateMapping(client, mappingName, createOpts).Extract()
createdMapping, err := federation.CreateMapping(client, mappingName, createOpts).Extract()
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, createOpts.Rules[0], actual.Rules[0])
th.AssertEquals(t, len(createOpts.Rules), len(createdMapping.Rules))
th.CheckDeepEquals(t, createOpts.Rules[0], createdMapping.Rules[0])

mapping, err := federation.GetMapping(client, mappingName).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, len(createOpts.Rules), len(mapping.Rules))
th.CheckDeepEquals(t, createOpts.Rules[0], mapping.Rules[0])
}
7 changes: 7 additions & 0 deletions openstack/identity/v3/extensions/federation/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,12 @@ Example to Create Mappings
if err != nil {
panic(err)
}

Example to Get a Mapping

mapping, err := federation.GetMapping(identityClient, "ACME").Extract()
if err != nil {
panic(err)
}
*/
package federation
7 changes: 7 additions & 0 deletions openstack/identity/v3/extensions/federation/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ func CreateMapping(client *gophercloud.ServiceClient, mappingID string, opts Cre
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

// GetMapping retrieves details on a single mapping, by ID.
func GetMapping(client *gophercloud.ServiceClient, mappingID string) (r GetMappingResult) {
resp, err := client.Get(mappingsResourceURL(client, mappingID), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
6 changes: 6 additions & 0 deletions openstack/identity/v3/extensions/federation/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ type CreateMappingResult struct {
mappingResult
}

// GetMappingResult is the response from a GetMapping operation.
// Call its Extract method to interpret it as a Mapping.
type GetMappingResult struct {
mappingResult
}

// MappingsPage is a single page of Mapping results.
type MappingsPage struct {
pagination.LinkedPageBase
Expand Down
16 changes: 16 additions & 0 deletions openstack/identity/v3/extensions/federation/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ const CreateOutput = `
}
`

const GetOutput = CreateOutput

var MappingACME = federation.Mapping{
ID: "ACME",
Links: map[string]interface{}{
Expand Down Expand Up @@ -194,3 +196,17 @@ func HandleCreateMappingSuccessfully(t *testing.T) {
fmt.Fprintf(w, CreateOutput)
})
}

// HandleGetMappingSuccessfully creates an HTTP handler at `/mappings` on the
// test handler mux that responds with a single mapping.
func HandleGetMappingSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/OS-FEDERATION/mappings/ACME", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "Accept", "application/json")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, GetOutput)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,13 @@ func TestCreateMappings(t *testing.T) {
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, MappingACME, *actual)
}

func TestGetMapping(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleGetMappingSuccessfully(t)

actual, err := federation.GetMapping(client.ServiceClient(), "ACME").Extract()
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, MappingACME, *actual)
}