Skip to content

Commit 7f72c70

Browse files
committed
Merge pull request #4163 from Joshua-Anderson/paginate-responses
fix(client-go): paginate over lists
2 parents bbf5766 + 75fb5a9 commit 7f72c70

53 files changed

Lines changed: 375 additions & 207 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

client-go/cmd/apps.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,24 @@ func AppCreate(id string, buildpack string, remote string, noRemote bool) error
5555
}
5656

5757
// AppsList lists apps on the Deis controller.
58-
func AppsList() error {
58+
func AppsList(results int) error {
5959
c, err := client.New()
6060

6161
if err != nil {
6262
return err
6363
}
6464

65-
apps, err := apps.List(c)
65+
if results == defaultLimit {
66+
results = c.ResponseLimit
67+
}
68+
69+
apps, count, err := apps.List(c, results)
6670

6771
if err != nil {
6872
return err
6973
}
7074

71-
fmt.Println("=== Apps")
75+
fmt.Printf("=== Apps%s", limitCount(len(apps), count))
7276

7377
for _, app := range apps {
7478
fmt.Println(app.ID)

client-go/cmd/builds.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,24 @@ import (
99
)
1010

1111
// BuildsList lists an app's builds.
12-
func BuildsList(appID string) error {
12+
func BuildsList(appID string, results int) error {
1313
c, appID, err := load(appID)
1414

1515
if err != nil {
1616
return err
1717
}
1818

19-
builds, err := builds.List(c, appID)
19+
if results == defaultLimit {
20+
results = c.ResponseLimit
21+
}
22+
23+
builds, count, err := builds.List(c, appID, results)
2024

2125
if err != nil {
2226
return err
2327
}
2428

25-
fmt.Printf("=== %s Builds\n", appID)
29+
fmt.Printf("=== %s Builds%s", appID, limitCount(len(builds), count))
2630

2731
for _, build := range builds {
2832
fmt.Println(build.UUID, build.Created)

client-go/cmd/certs.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ import (
1212
)
1313

1414
// CertsList lists certs registered with the controller.
15-
func CertsList() error {
15+
func CertsList(results int) error {
1616
c, err := client.New()
1717

1818
if err != nil {
1919
return err
2020
}
2121

22-
certList, err := certs.List(c)
22+
if results == defaultLimit {
23+
results = c.ResponseLimit
24+
}
25+
26+
certList, _, err := certs.List(c, results)
2327

2428
if err != nil {
2529
return err

client-go/cmd/domains.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@ import (
77
)
88

99
// DomainsList lists domains registered with an app.
10-
func DomainsList(appID string) error {
10+
func DomainsList(appID string, results int) error {
1111
c, appID, err := load(appID)
1212

1313
if err != nil {
1414
return err
1515
}
1616

17-
domains, err := domains.List(c, appID)
17+
if results == defaultLimit {
18+
results = c.ResponseLimit
19+
}
20+
21+
domains, count, err := domains.List(c, appID, results)
1822

1923
if err != nil {
2024
return err
2125
}
2226

23-
fmt.Printf("=== %s Domains\n", appID)
27+
fmt.Printf("=== %s Domains%s", appID, limitCount(len(domains), count))
2428

2529
for _, domain := range domains {
2630
fmt.Println(domain.Domain)

client-go/cmd/keys.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,24 @@ import (
1414
)
1515

1616
// KeysList lists a user's keys.
17-
func KeysList() error {
17+
func KeysList(results int) error {
1818
c, err := client.New()
1919

2020
if err != nil {
2121
return err
2222
}
2323

24-
keys, err := keys.List(c)
24+
if results == defaultLimit {
25+
results = c.ResponseLimit
26+
}
27+
28+
keys, count, err := keys.List(c, results)
2529

2630
if err != nil {
2731
return err
2832
}
2933

30-
fmt.Printf("=== %s Keys\n", c.Username)
34+
fmt.Printf("=== %s Keys%s", c.Username, limitCount(len(keys), count))
3135

3236
for _, key := range keys {
3337
fmt.Printf("%s %s...%s\n", key.ID, key.Public[:16], key.Public[len(key.Public)-10:])

client-go/cmd/perms.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ import (
99
)
1010

1111
// PermsList prints which users have permissions.
12-
func PermsList(appID string, admin bool) error {
12+
func PermsList(appID string, admin bool, results int) error {
1313
c, appID, err := permsLoad(appID, admin)
1414

1515
if err != nil {
1616
return err
1717
}
1818

1919
var users []string
20+
var count int
2021

2122
if admin {
22-
users, err = perms.ListAdmins(c)
23+
if results == defaultLimit {
24+
results = c.ResponseLimit
25+
}
26+
users, count, err = perms.ListAdmins(c, results)
2327
} else {
2428
users, err = perms.List(c, appID)
2529
}
@@ -29,7 +33,7 @@ func PermsList(appID string, admin bool) error {
2933
}
3034

3135
if admin {
32-
fmt.Println("=== Administrators")
36+
fmt.Printf("=== Administrators%s", limitCount(len(users), count))
3337
} else {
3438
fmt.Printf("=== %s's Users\n", appID)
3539
}

client-go/cmd/ps.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,24 @@ import (
1212
)
1313

1414
// PsList lists an app's processes.
15-
func PsList(appID string) error {
15+
func PsList(appID string, results int) error {
1616
c, appID, err := load(appID)
1717

1818
if err != nil {
1919
return err
2020
}
2121

22-
processes, err := ps.List(c, appID)
22+
if results == defaultLimit {
23+
results = c.ResponseLimit
24+
}
25+
26+
processes, count, err := ps.List(c, appID, results)
2327

2428
if err != nil {
2529
return err
2630
}
2731

28-
printProcesses(appID, processes)
32+
printProcesses(appID, processes, count)
2933

3034
return nil
3135
}
@@ -69,13 +73,13 @@ func PsScale(appID string, targets []string) error {
6973

7074
fmt.Printf("done in %ds\n", int(time.Since(startTime).Seconds()))
7175

72-
processes, err := ps.List(c, appID)
76+
processes, count, err := ps.List(c, appID, c.ResponseLimit)
7377

7478
if err != nil {
7579
return err
7680
}
7781

78-
printProcesses(appID, processes)
82+
printProcesses(appID, processes, count)
7983
return nil
8084
}
8185

@@ -119,20 +123,20 @@ func PsRestart(appID, target string) error {
119123

120124
fmt.Printf("done in %ds\n", int(time.Since(startTime).Seconds()))
121125

122-
processes, err := ps.List(c, appID)
126+
processes, count, err := ps.List(c, appID, c.ResponseLimit)
123127

124128
if err != nil {
125129
return err
126130
}
127131

128-
printProcesses(appID, processes)
132+
printProcesses(appID, processes, count)
129133
return nil
130134
}
131135

132-
func printProcesses(appID string, processes []api.Process) {
136+
func printProcesses(appID string, processes []api.Process, count int) {
133137
psMap := ps.ByType(processes)
134138

135-
fmt.Printf("=== %s Processes\n", appID)
139+
fmt.Printf("=== %s Processes%s", appID, limitCount(len(processes), count))
136140

137141
for psType, procs := range psMap {
138142
fmt.Printf("--- %s:\n", psType)

client-go/cmd/releases.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@ import (
99
)
1010

1111
// ReleasesList lists an app's releases.
12-
func ReleasesList(appID string) error {
12+
func ReleasesList(appID string, results int) error {
1313
c, appID, err := load(appID)
1414

1515
if err != nil {
1616
return err
1717
}
1818

19-
releases, err := releases.List(c, appID)
19+
if results == defaultLimit {
20+
results = c.ResponseLimit
21+
}
22+
23+
releases, count, err := releases.List(c, appID, results)
2024

21-
fmt.Printf("=== %s Releases\n", appID)
25+
fmt.Printf("=== %s Releases%s", appID, limitCount(len(releases), count))
2226

2327
w := new(tabwriter.Writer)
2428

client-go/cmd/users.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@ import (
88
)
99

1010
// UsersList lists users registered with the controller.
11-
func UsersList() error {
11+
func UsersList(results int) error {
1212
c, err := client.New()
1313

1414
if err != nil {
1515
return err
1616
}
1717

18-
users, err := users.List(c)
18+
if results == defaultLimit {
19+
results = c.ResponseLimit
20+
}
21+
22+
users, count, err := users.List(c, results)
1923

2024
if err != nil {
2125
return err
2226
}
2327

24-
fmt.Println("=== Users")
28+
fmt.Printf("=== Users%s", limitCount(len(users), count))
2529

2630
for _, user := range users {
2731
fmt.Println(user.Username)

client-go/cmd/utils.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/deis/deis/client-go/pkg/git"
1111
)
1212

13+
var defaultLimit = -1
14+
1315
func progress() chan bool {
1416
frames := []string{"...", "o..", ".o.", "..o"}
1517
backspaces := strings.Repeat("\b", 3)
@@ -78,3 +80,11 @@ func drinkOfChoice() string {
7880

7981
return drink
8082
}
83+
84+
func limitCount(objs, total int) string {
85+
if objs == total {
86+
return "\n"
87+
}
88+
89+
return fmt.Sprintf(" (%d of %d)\n", objs, total)
90+
}

0 commit comments

Comments
 (0)