Skip to content

Commit

Permalink
feat(identity): add get endpoint by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
reenjii authored and chuliang committed Sep 4, 2023
1 parent a6cf357 commit 55d9c2b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
23 changes: 23 additions & 0 deletions acceptance/openstack/identity/v3/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ func TestEndpointsList(t *testing.T) {
th.AssertEquals(t, found, true)
}

func TestEndpointsGet(t *testing.T) {
clients.RequireAdmin(t)

client, err := clients.NewIdentityV3Client()
th.AssertNoErr(t, err)

allPages, err := endpoints.List(client, nil).AllPages()
th.AssertNoErr(t, err)

allEndpoints, err := endpoints.ExtractEndpoints(allPages)
th.AssertNoErr(t, err)

endpoint := allEndpoints[0]
e, err := endpoints.Get(client, endpoint.ID).Extract()
if err != nil {
t.Fatalf("Unable to get endpoint: %v", err)
}

tools.PrintResource(t, p)

th.AssertEquals(t, e.Name, e.Name)
}

func TestEndpointsNavigateCatalog(t *testing.T) {
clients.RequireAdmin(t)

Expand Down
7 changes: 7 additions & 0 deletions openstack/identity/v3/endpoints/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pa
})
}

// Get retrieves details on a single endpoint, by ID.
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
resp, err := client.Get(endpointURL(client, id), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}

// UpdateOptsBuilder allows extensions to add parameters to the Update request.
type UpdateOptsBuilder interface {
ToEndpointUpdateMap() (map[string]interface{}, error)
Expand Down
6 changes: 6 additions & 0 deletions openstack/identity/v3/endpoints/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ func (r commonResult) Extract() (*Endpoint, error) {
return s.Endpoint, err
}

// GetResult is the response from a Get operation. Call its Extract method
// to interpret it as an Endpoint.
type GetResult struct {
commonResult
}

// CreateResult is the response from a Create operation. Call its Extract
// method to interpret it as an Endpoint.
type CreateResult struct {
Expand Down

0 comments on commit 55d9c2b

Please sign in to comment.