Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 740fda7

Browse filesBrowse files
authored
Merge pull request #2506 from artem-lifshits/auth/domains
[Identity v3] Add available domain listing
2 parents 3002039 + 022c50f commit 740fda7
Copy full SHA for 740fda7

File tree

5 files changed

+120
-0
lines changed
Filter options

5 files changed

+120
-0
lines changed

‎acceptance/openstack/identity/v3/domains_test.go

Copy file name to clipboardExpand all lines: acceptance/openstack/identity/v3/domains_test.go
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ import (
1212
th "github.com/gophercloud/gophercloud/testhelper"
1313
)
1414

15+
func TestDomainsListAvailable(t *testing.T) {
16+
clients.RequireAdmin(t)
17+
18+
client, err := clients.NewIdentityV3Client()
19+
th.AssertNoErr(t, err)
20+
21+
allPages, err := domains.ListAvailable(client).AllPages()
22+
th.AssertNoErr(t, err)
23+
24+
allDomains, err := domains.ExtractDomains(allPages)
25+
th.AssertNoErr(t, err)
26+
27+
for _, domain := range allDomains {
28+
tools.PrintResource(t, domain)
29+
}
30+
}
31+
1532
func TestDomainsList(t *testing.T) {
1633
clients.RequireAdmin(t)
1734

‎openstack/identity/v3/domains/requests.go

Copy file name to clipboardExpand all lines: openstack/identity/v3/domains/requests.go
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pa
4141
})
4242
}
4343

44+
// ListAvailable enumerates the domains which are available to a specific user.
45+
func ListAvailable(client *gophercloud.ServiceClient) pagination.Pager {
46+
url := listAvailableURL(client)
47+
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
48+
return DomainPage{pagination.LinkedPageBase{PageResult: r}}
49+
})
50+
}
51+
4452
// Get retrieves details on a single domain, by ID.
4553
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
4654
resp, err := client.Get(getURL(client, id), &r.Body, nil)

‎openstack/identity/v3/domains/testing/fixtures.go

Copy file name to clipboardExpand all lines: openstack/identity/v3/domains/testing/fixtures.go
+71Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,37 @@ import (
1010
"github.com/gophercloud/gophercloud/testhelper/client"
1111
)
1212

13+
// ListAvailableOutput provides a single page of available domain results.
14+
const ListAvailableOutput = `
15+
{
16+
"domains": [
17+
{
18+
"id": "52af04aec5f84182b06959d2775d2000",
19+
"name": "TestDomain",
20+
"description": "Testing domain",
21+
"enabled": false,
22+
"links": {
23+
"self": "https://example.com/v3/domains/52af04aec5f84182b06959d2775d2000"
24+
}
25+
},
26+
{
27+
"id": "a720688fb87f4575a4c000d818061eae",
28+
"name": "ProdDomain",
29+
"description": "Production domain",
30+
"enabled": true,
31+
"links": {
32+
"self": "https://example.com/v3/domains/a720688fb87f4575a4c000d818061eae"
33+
}
34+
}
35+
],
36+
"links": {
37+
"next": null,
38+
"self": "https://example.com/v3/auth/domains",
39+
"previous": null
40+
}
41+
}
42+
`
43+
1344
// ListOutput provides a single page of Domain results.
1445
const ListOutput = `
1546
{
@@ -87,6 +118,28 @@ const UpdateOutput = `
87118
}
88119
`
89120

121+
// ProdDomain is a domain fixture.
122+
var ProdDomain = domains.Domain{
123+
Enabled: true,
124+
ID: "a720688fb87f4575a4c000d818061eae",
125+
Links: map[string]interface{}{
126+
"self": "https://example.com/v3/domains/a720688fb87f4575a4c000d818061eae",
127+
},
128+
Name: "ProdDomain",
129+
Description: "Production domain",
130+
}
131+
132+
// TestDomain is a domain fixture.
133+
var TestDomain = domains.Domain{
134+
Enabled: false,
135+
ID: "52af04aec5f84182b06959d2775d2000",
136+
Links: map[string]interface{}{
137+
"self": "https://example.com/v3/domains/52af04aec5f84182b06959d2775d2000",
138+
},
139+
Name: "TestDomain",
140+
Description: "Testing domain",
141+
}
142+
90143
// FirstDomain is the first domain in the List request.
91144
var FirstDomain = domains.Domain{
92145
Enabled: true,
@@ -119,9 +172,27 @@ var SecondDomainUpdated = domains.Domain{
119172
Description: "Staging Domain",
120173
}
121174

175+
// ExpectedAvailableDomainsSlice is the slice of domains expected to be returned
176+
// from ListAvailableOutput.
177+
var ExpectedAvailableDomainsSlice = []domains.Domain{TestDomain, ProdDomain}
178+
122179
// ExpectedDomainsSlice is the slice of domains expected to be returned from ListOutput.
123180
var ExpectedDomainsSlice = []domains.Domain{FirstDomain, SecondDomain}
124181

182+
// HandleListAvailableDomainsSuccessfully creates an HTTP handler at `/auth/domains`
183+
// on the test handler mux that responds with a list of two domains.
184+
func HandleListAvailableDomainsSuccessfully(t *testing.T) {
185+
th.Mux.HandleFunc("/auth/domains", func(w http.ResponseWriter, r *http.Request) {
186+
th.TestMethod(t, r, "GET")
187+
th.TestHeader(t, r, "Accept", "application/json")
188+
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
189+
190+
w.Header().Set("Content-Type", "application/json")
191+
w.WriteHeader(http.StatusOK)
192+
fmt.Fprintf(w, ListAvailableOutput)
193+
})
194+
}
195+
125196
// HandleListDomainsSuccessfully creates an HTTP handler at `/domains` on the
126197
// test handler mux that responds with a list of two domains.
127198
func HandleListDomainsSuccessfully(t *testing.T) {

‎openstack/identity/v3/domains/testing/requests_test.go

Copy file name to clipboardExpand all lines: openstack/identity/v3/domains/testing/requests_test.go
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@ import (
99
"github.com/gophercloud/gophercloud/testhelper/client"
1010
)
1111

12+
func TestListAvailableDomains(t *testing.T) {
13+
th.SetupHTTP()
14+
defer th.TeardownHTTP()
15+
HandleListAvailableDomainsSuccessfully(t)
16+
17+
count := 0
18+
err := domains.ListAvailable(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
19+
count++
20+
21+
actual, err := domains.ExtractDomains(page)
22+
th.AssertNoErr(t, err)
23+
24+
th.CheckDeepEquals(t, ExpectedAvailableDomainsSlice, actual)
25+
26+
return true, nil
27+
})
28+
th.AssertNoErr(t, err)
29+
th.CheckEquals(t, count, 1)
30+
}
31+
1232
func TestListDomains(t *testing.T) {
1333
th.SetupHTTP()
1434
defer th.TeardownHTTP()

‎openstack/identity/v3/domains/urls.go

Copy file name to clipboardExpand all lines: openstack/identity/v3/domains/urls.go
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ package domains
22

33
import "github.com/gophercloud/gophercloud"
44

5+
func listAvailableURL(client *gophercloud.ServiceClient) string {
6+
return client.ServiceURL("auth", "domains")
7+
}
8+
59
func listURL(client *gophercloud.ServiceClient) string {
610
return client.ServiceURL("domains")
711
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.