Skip to content

Commit 33800da

Browse files
committed
fix(privatenetworks): PrivateNetworksDomainsList must take a pagination.Request in argument
1 parent 682777b commit 33800da

Some content is hidden

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

50 files changed

+739
-596
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* feat(sshkeys): add support for ed25519 keys
1111
* feat(apps/create): detect Git main branch name
1212
* fix(databases): `parseScheduleAtFlag` returns a validation error
13+
* fix(privatenetworks): `PrivateNetworksDomainsList` must take a `pagination.Request` in argument
1314

1415
## 1.43.3
1516

apps/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func Create(ctx context.Context, appName, remote, buildpack, projectID string, h
3232

3333
if buildpack != "" {
3434
fmt.Println("Installing custom buildpack...")
35-
_, _, err := c.VariableSet(ctx, app.Name, "BUILDPACK_URL", buildpack)
35+
_, err := c.VariableSet(ctx, app.Name, "BUILDPACK_URL", buildpack)
3636
if err != nil {
3737
fmt.Println("Failed to set custom buildpack. Please add BUILDPACK_URL=" + buildpack + " to your application environment")
3838
}

apps/operations.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ type OperationWaiter struct {
2727
url string
2828
}
2929

30+
// TODO make it rivate and remove it?
3031
func NewOperationWaiterFromHTTPResponse(app string, res *http.Response) *OperationWaiter {
3132
operationURL := res.Header.Get("Location")
32-
return NewOperationWaiterFromURL(app, operationURL)
33+
return newOperationWaiterFromURL(app, operationURL)
3334
}
3435

35-
func NewOperationWaiterFromURL(app, url string) *OperationWaiter {
36-
return NewOperationWaiter(os.Stderr, app, url)
36+
func newOperationWaiterFromURL(app, url string) *OperationWaiter {
37+
return newOperationWaiter(os.Stderr, app, url)
3738
}
3839

39-
func NewOperationWaiter(output stdio.Writer, app, url string) *OperationWaiter {
40+
func newOperationWaiter(output stdio.Writer, app, url string) *OperationWaiter {
4041
return &OperationWaiter{
4142
output: output,
4243
app: app,

apps/restart.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@ func Restart(ctx context.Context, app string, sync bool, args []string) error {
1717
return errors.Wrapf(ctx, err, "fail to get Scalingo client")
1818
}
1919

20-
res, err := c.AppsRestart(ctx, app, &params)
20+
restartOpURL, err := c.AppsRestart(ctx, app, &params)
2121
if err != nil {
2222
return errors.Wrapf(ctx, err, "restart app %s", app)
2323
}
24-
res.Body.Close()
2524

2625
if !sync {
2726
fmt.Println("Your application is being restarted.")
2827
return nil
2928
}
3029

31-
waiter := NewOperationWaiterFromHTTPResponse(app, res)
30+
waiter := newOperationWaiterFromURL(app, restartOpURL)
3231
_, err = waiter.WaitOperation(ctx)
3332
if err != nil {
3433
return errors.Wrap(ctx, err, "wait for restart operation")

apps/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func Run(ctx context.Context, opts RunOpts) error {
139139
return nil
140140
}
141141

142-
waiter := NewOperationWaiter(runCtx.waitingTextOutputWriter, opts.App, runRes.OperationURL)
142+
waiter := newOperationWaiter(runCtx.waitingTextOutputWriter, opts.App, runRes.OperationURL)
143143
waiter.SetPrompt(fmt.Sprintf("-----> Starting container %v ", runRes.Container.Label))
144144
operation, err := waiter.WaitOperation(ctx)
145145
if err != nil {

apps/scale.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package apps
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76

87
"strconv"
@@ -107,7 +106,7 @@ func Scale(ctx context.Context, app string, sync bool, types []string) error {
107106
}
108107
}
109108

110-
res, err := c.AppsScale(ctx, app, scaleParams)
109+
resContainerTypes, operationURL, err := c.AppsScale(ctx, app, scaleParams)
111110
if err != nil {
112111
if !utils.IsPaymentRequiredAndFreeTrialExceededError(err) {
113112
var reqestFailedError *http.RequestFailedError
@@ -127,27 +126,20 @@ func Scale(ctx context.Context, app string, sync bool, types []string) error {
127126
return Scale(ctx, app, sync, types)
128127
})
129128
}
130-
defer res.Body.Close()
131-
132-
var scaleRes ScaleRes
133-
err = json.NewDecoder(res.Body).Decode(&scaleRes)
134-
if err != nil {
135-
return errors.Wrapf(ctx, err, "fail to decode API response to scale operation")
136-
}
137129

138130
fmt.Printf("Your application is being scaled to:\n")
139-
for _, ct := range scaleRes.Containers {
131+
for _, ct := range resContainerTypes {
140132
fmt.Println(io.Indent(fmt.Sprintf("%s: %d - %s", ct.Name, ct.Amount, ct.Size), 2))
141133
}
142134

143135
if !sync {
144136
return nil
145137
}
146138

147-
waiter := NewOperationWaiterFromHTTPResponse(app, res)
139+
waiter := newOperationWaiterFromURL(app, operationURL)
148140
_, err = waiter.WaitOperation(ctx)
149141
if err != nil {
150-
return errors.Wrapf(ctx, err, "fail to handle the scale operation")
142+
return errors.Wrapf(ctx, err, "wait for the end of the scale operation")
151143
}
152144

153145
fmt.Println("Your application has been scaled.")

cmd/deployments.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ var (
5454
`,
5555
Action: func(ctx context.Context, c *cli.Command) error {
5656
currentApp := detect.CurrentApp(ctx, c)
57-
err := deployments.List(ctx, currentApp, pagination.Request{
58-
Page: c.Int("page"),
59-
PerPage: c.Int("per-page"),
60-
})
57+
err := deployments.List(ctx, currentApp, pagination.NewRequest(c.Int("page"), c.Int("per-page")))
6158
if err != nil {
6259
errorQuit(ctx, err)
6360
}

cmd/maintenance.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ var databaseMaintenanceList = cli.Command{
3838
addonName = addonUUIDFromFlags(ctx, c, currentResource, true)
3939
}
4040

41-
err := maintenance.List(ctx, currentResource, addonName, pagination.Request{
42-
Page: c.Int("page"),
43-
PerPage: c.Int("per-page"),
44-
})
41+
err := maintenance.List(ctx, currentResource, addonName, pagination.NewRequest(c.Int("page"), c.Int("per-page")))
4542
if err != nil {
4643
errorQuit(ctx, err)
4744
}

cmd/privatenetworks.go

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ package cmd
22

33
import (
44
"context"
5-
"strconv"
65

76
"github.com/sirupsen/logrus"
87
"github.com/urfave/cli/v3"
98

109
"github.com/Scalingo/cli/cmd/autocomplete"
1110
"github.com/Scalingo/cli/detect"
1211
"github.com/Scalingo/cli/privatenetworks"
13-
"github.com/Scalingo/go-utils/errors/v3"
1412
"github.com/Scalingo/go-utils/logger"
13+
"github.com/Scalingo/go-utils/pagination"
1514
)
1615

1716
const (
@@ -29,14 +28,14 @@ var (
2928
Value: outputFormatTable,
3029
Usage: "[" + outputFormatJSON + "|" + outputFormatTable + "]",
3130
},
32-
&cli.StringFlag{
31+
&cli.IntFlag{
3332
Name: "page",
34-
Value: "1",
33+
Value: 1,
3534
Usage: "[page]",
3635
},
37-
&cli.StringFlag{
36+
&cli.IntFlag{
3837
Name: "per-page",
39-
Value: "20",
38+
Value: 20,
4039
Usage: "[per-page]",
4140
},
4241
},
@@ -55,35 +54,18 @@ var (
5554
return nil
5655
}
5756

58-
pageStr := c.String("page")
59-
perPageStr := c.String("per-page")
57+
page := c.Int("page")
58+
perPage := c.Int("per-page")
6059
formatStr := c.String("format")
6160
ctx, _ = logger.WithFieldsToCtx(ctx, logrus.Fields{
62-
"page": pageStr,
63-
"per_page": perPageStr,
61+
"page": page,
62+
"per_page": perPage,
6463
"format": formatStr,
6564
})
6665

67-
var err error
68-
var page int
69-
if pageStr != "" {
70-
page, err = strconv.Atoi(pageStr)
71-
if err != nil || page < 1 {
72-
return errors.New(ctx, "invalid page number")
73-
}
74-
}
75-
76-
var perPage int
77-
if perPageStr != "" {
78-
perPage, err = strconv.Atoi(perPageStr)
79-
if err != nil || perPage < 1 || perPage > 50 {
80-
return errors.New(ctx, "invalid per_page number")
81-
}
82-
}
83-
8466
currentApp := detect.CurrentApp(ctx, c)
8567

86-
err = privatenetworks.List(ctx, currentApp, formatStr, uint(page), uint(perPage))
68+
err := privatenetworks.List(ctx, currentApp, formatStr, pagination.NewRequest(page, perPage))
8769
if err != nil {
8870
errorQuit(ctx, err)
8971
}

cmd/timeline.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ var (
3636
}
3737

3838
utils.CheckForConsent(ctx, currentResource)
39-
err := apps.Events(ctx, currentResource, pagination.Request{
40-
Page: c.Int("page"),
41-
PerPage: c.Int("per-page"),
42-
})
39+
err := apps.Events(ctx, currentResource, pagination.NewRequest(c.Int("page"), c.Int("per-page")))
4340
if err != nil {
4441
errorQuit(ctx, err)
4542
}

0 commit comments

Comments
 (0)