diff --git a/CHANGELOG.md b/CHANGELOG.md index a1d296cb5..007ed15ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## To Be Released -* build(deps): update `github.com/Scalingo/go-scalingo` to v10 +* build(deps): update `github.com/Scalingo/go-scalingo` from v9 to v11 * refactor: replace `errgo` and `pkg/errors` with `github.com/Scalingo/go-utils/errors/v3` * refactor: autofix by `go fix` and golangci-lint * fix(error): correctly parse in case of `RequestFailedError` @@ -10,6 +10,8 @@ * feat(sshkeys): add support for ed25519 keys * feat(apps/create): detect Git main branch name * fix(databases): `parseScheduleAtFlag` returns a validation error +* fix(privatenetworks): `PrivateNetworksDomainsList` must take a `pagination.Request` in argument +* build(deps): update `github.com/Scalingo/go-scalingo` from v10 to v11 ## 1.43.3 diff --git a/addonproviders/plans.go b/addonproviders/plans.go index b2d7ade9a..eb430dcab 100644 --- a/addonproviders/plans.go +++ b/addonproviders/plans.go @@ -7,7 +7,7 @@ import ( "github.com/olekukonko/tablewriter" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/addons/config.go b/addons/config.go index 952984e31..49bdaaed1 100644 --- a/addons/config.go +++ b/addons/config.go @@ -8,7 +8,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/addons/destroy.go b/addons/destroy.go index d25147e19..b20dc75cb 100644 --- a/addons/destroy.go +++ b/addons/destroy.go @@ -7,7 +7,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/addons/info.go b/addons/info.go index b86384663..deeb3dc7b 100644 --- a/addons/info.go +++ b/addons/info.go @@ -16,7 +16,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/db" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/addons/provision.go b/addons/provision.go index ca3242bcf..385b59ba5 100644 --- a/addons/provision.go +++ b/addons/provision.go @@ -6,7 +6,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/addons/upgrade.go b/addons/upgrade.go index ddb5ed929..9e6d69e0f 100644 --- a/addons/upgrade.go +++ b/addons/upgrade.go @@ -6,7 +6,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/alerts/add.go b/alerts/add.go index 03df0cc2d..62e748509 100644 --- a/alerts/add.go +++ b/alerts/add.go @@ -5,7 +5,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/alerts/update.go b/alerts/update.go index 95e23cb82..c7e09de6a 100644 --- a/alerts/update.go +++ b/alerts/update.go @@ -5,7 +5,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/apps/create.go b/apps/create.go index 14c08f0c4..873e2d6f5 100644 --- a/apps/create.go +++ b/apps/create.go @@ -6,7 +6,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) @@ -32,7 +32,7 @@ func Create(ctx context.Context, appName, remote, buildpack, projectID string, h if buildpack != "" { fmt.Println("Installing custom buildpack...") - _, _, err := c.VariableSet(ctx, app.Name, "BUILDPACK_URL", buildpack) + _, err := c.VariableSet(ctx, app.Name, "BUILDPACK_URL", buildpack) if err != nil { fmt.Println("Failed to set custom buildpack. Please add BUILDPACK_URL=" + buildpack + " to your application environment") } diff --git a/apps/info.go b/apps/info.go index d01726181..3aacc3add 100644 --- a/apps/info.go +++ b/apps/info.go @@ -9,8 +9,8 @@ import ( "github.com/olekukonko/tablewriter" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/apps/logs.go b/apps/logs.go index d5efb02e1..9dbab7ded 100644 --- a/apps/logs.go +++ b/apps/logs.go @@ -6,7 +6,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/logs" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/apps/one_off_stop.go b/apps/one_off_stop.go index 1d9daa885..5e966f5b7 100644 --- a/apps/one_off_stop.go +++ b/apps/one_off_stop.go @@ -6,7 +6,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/apps/operations.go b/apps/operation_waiter.go similarity index 82% rename from apps/operations.go rename to apps/operation_waiter.go index e80d4e646..c4fda34d3 100644 --- a/apps/operations.go +++ b/apps/operation_waiter.go @@ -4,7 +4,6 @@ import ( "context" "fmt" stdio "io" - "net/http" "net/url" "os" "path/filepath" @@ -12,7 +11,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) @@ -27,16 +26,11 @@ type OperationWaiter struct { url string } -func NewOperationWaiterFromHTTPResponse(app string, res *http.Response) *OperationWaiter { - operationURL := res.Header.Get("Location") - return NewOperationWaiterFromURL(app, operationURL) +func newOperationWaiterFromURL(app, url string) *OperationWaiter { + return newOperationWaiter(os.Stderr, app, url) } -func NewOperationWaiterFromURL(app, url string) *OperationWaiter { - return NewOperationWaiter(os.Stderr, app, url) -} - -func NewOperationWaiter(output stdio.Writer, app, url string) *OperationWaiter { +func newOperationWaiter(output stdio.Writer, app, url string) *OperationWaiter { return &OperationWaiter{ output: output, app: app, diff --git a/apps/restart.go b/apps/restart.go index 51afc9c5b..11bbc8fa1 100644 --- a/apps/restart.go +++ b/apps/restart.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) @@ -17,18 +17,17 @@ func Restart(ctx context.Context, app string, sync bool, args []string) error { return errors.Wrapf(ctx, err, "fail to get Scalingo client") } - res, err := c.AppsRestart(ctx, app, ¶ms) + restartOpURL, err := c.AppsRestart(ctx, app, ¶ms) if err != nil { return errors.Wrapf(ctx, err, "restart app %s", app) } - res.Body.Close() if !sync { fmt.Println("Your application is being restarted.") return nil } - waiter := NewOperationWaiterFromHTTPResponse(app, res) + waiter := newOperationWaiterFromURL(app, restartOpURL) _, err = waiter.WaitOperation(ctx) if err != nil { return errors.Wrap(ctx, err, "wait for restart operation") diff --git a/apps/run.go b/apps/run.go index 94653c294..5c2ef878e 100644 --- a/apps/run.go +++ b/apps/run.go @@ -26,8 +26,8 @@ import ( "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/signals" "github.com/Scalingo/cli/term" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) @@ -139,7 +139,7 @@ func Run(ctx context.Context, opts RunOpts) error { return nil } - waiter := NewOperationWaiter(runCtx.waitingTextOutputWriter, opts.App, runRes.OperationURL) + waiter := newOperationWaiter(runCtx.waitingTextOutputWriter, opts.App, runRes.OperationURL) waiter.SetPrompt(fmt.Sprintf("-----> Starting container %v ", runRes.Container.Label)) operation, err := waiter.WaitOperation(ctx) if err != nil { diff --git a/apps/run/run_unix.go b/apps/run/run_unix.go index 4f6cd7ffc..e7f250cf4 100644 --- a/apps/run/run_unix.go +++ b/apps/run/run_unix.go @@ -16,8 +16,8 @@ import ( "golang.org/x/term" "github.com/Scalingo/cli/httpclient" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/apps/run/run_windows.go b/apps/run/run_windows.go index 4cae02ee3..e00f508ca 100644 --- a/apps/run/run_windows.go +++ b/apps/run/run_windows.go @@ -5,7 +5,7 @@ import ( "net" "os" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) func NotifiedSignals() chan os.Signal { diff --git a/apps/scale.go b/apps/scale.go index 7067d15cd..754b1ff58 100644 --- a/apps/scale.go +++ b/apps/scale.go @@ -2,7 +2,6 @@ package apps import ( "context" - "encoding/json" "fmt" "strconv" @@ -11,9 +10,9 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) @@ -107,7 +106,7 @@ func Scale(ctx context.Context, app string, sync bool, types []string) error { } } - res, err := c.AppsScale(ctx, app, scaleParams) + resContainerTypes, operationURL, err := c.AppsScale(ctx, app, scaleParams) if err != nil { if !utils.IsPaymentRequiredAndFreeTrialExceededError(err) { var reqestFailedError *http.RequestFailedError @@ -127,16 +126,9 @@ func Scale(ctx context.Context, app string, sync bool, types []string) error { return Scale(ctx, app, sync, types) }) } - defer res.Body.Close() - - var scaleRes ScaleRes - err = json.NewDecoder(res.Body).Decode(&scaleRes) - if err != nil { - return errors.Wrapf(ctx, err, "fail to decode API response to scale operation") - } fmt.Printf("Your application is being scaled to:\n") - for _, ct := range scaleRes.Containers { + for _, ct := range resContainerTypes { fmt.Println(io.Indent(fmt.Sprintf("%s: %d - %s", ct.Name, ct.Amount, ct.Size), 2)) } @@ -144,10 +136,10 @@ func Scale(ctx context.Context, app string, sync bool, types []string) error { return nil } - waiter := NewOperationWaiterFromHTTPResponse(app, res) + waiter := newOperationWaiterFromURL(app, operationURL) _, err = waiter.WaitOperation(ctx) if err != nil { - return errors.Wrapf(ctx, err, "fail to handle the scale operation") + return errors.Wrapf(ctx, err, "wait for the end of the scale operation") } fmt.Println("Your application has been scaled.") diff --git a/apps/sendsignal.go b/apps/sendsignal.go index 3133f632a..007af3802 100644 --- a/apps/sendsignal.go +++ b/apps/sendsignal.go @@ -7,7 +7,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/apps/stats.go b/apps/stats.go index f342ce309..229ff09a1 100644 --- a/apps/stats.go +++ b/apps/stats.go @@ -10,7 +10,7 @@ import ( "github.com/olekukonko/tablewriter" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/autoscalers/add.go b/autoscalers/add.go index 5f5a9c0db..aa2fa64d9 100644 --- a/autoscalers/add.go +++ b/autoscalers/add.go @@ -5,7 +5,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/autoscalers/get_from_container_type.go b/autoscalers/get_from_container_type.go index 5be53d70a..9b821abae 100644 --- a/autoscalers/get_from_container_type.go +++ b/autoscalers/get_from_container_type.go @@ -4,7 +4,7 @@ import ( "context" stderrors "errors" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/autoscalers/update.go b/autoscalers/update.go index 7982677fd..f4a171091 100644 --- a/autoscalers/update.go +++ b/autoscalers/update.go @@ -5,7 +5,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/cmd/alerts.go b/cmd/alerts.go index 90583f3e2..7c0160be3 100644 --- a/cmd/alerts.go +++ b/cmd/alerts.go @@ -9,7 +9,7 @@ import ( "github.com/Scalingo/cli/cmd/autocomplete" "github.com/Scalingo/cli/detect" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) var ( diff --git a/cmd/autocomplete/addons_add.go b/cmd/autocomplete/addons_add.go index 6fa3564b9..6e0f15af3 100644 --- a/cmd/autocomplete/addons_add.go +++ b/cmd/autocomplete/addons_add.go @@ -6,7 +6,7 @@ import ( "os" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/cmd/autocomplete/addons_upgrade.go b/cmd/autocomplete/addons_upgrade.go index 9aa6f610c..11642d8e0 100644 --- a/cmd/autocomplete/addons_upgrade.go +++ b/cmd/autocomplete/addons_upgrade.go @@ -8,7 +8,7 @@ import ( "github.com/urfave/cli/v3" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/cmd/autocomplete/apps.go b/cmd/autocomplete/apps.go index 68f95e841..ef7c17ebc 100644 --- a/cmd/autocomplete/apps.go +++ b/cmd/autocomplete/apps.go @@ -9,8 +9,8 @@ import ( "time" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/cmd/autocomplete/collaborators_add.go b/cmd/autocomplete/collaborators_add.go index 720ad7b67..bc5df4ec3 100644 --- a/cmd/autocomplete/collaborators_add.go +++ b/cmd/autocomplete/collaborators_add.go @@ -8,8 +8,8 @@ import ( "github.com/urfave/cli/v3" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/cmd/autocomplete/current_app.go b/cmd/autocomplete/current_app.go index 981371707..a91f674eb 100644 --- a/cmd/autocomplete/current_app.go +++ b/cmd/autocomplete/current_app.go @@ -8,7 +8,7 @@ import ( "github.com/Scalingo/cli/detect" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" ) func CurrentAppCompletion(ctx context.Context, c *cli.Command) string { diff --git a/cmd/autocomplete/flag_app.go b/cmd/autocomplete/flag_app.go index f607e7c52..98f8af22b 100644 --- a/cmd/autocomplete/flag_app.go +++ b/cmd/autocomplete/flag_app.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" ) func FlagAppAutoComplete(ctx context.Context) bool { diff --git a/cmd/autoscalers.go b/cmd/autoscalers.go index ad6e08729..9bd28574d 100644 --- a/cmd/autoscalers.go +++ b/cmd/autoscalers.go @@ -9,7 +9,7 @@ import ( "github.com/Scalingo/cli/cmd/autocomplete" "github.com/Scalingo/cli/detect" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) var ( diff --git a/cmd/collaborators.go b/cmd/collaborators.go index 1140517f4..c6b0df483 100644 --- a/cmd/collaborators.go +++ b/cmd/collaborators.go @@ -9,7 +9,7 @@ import ( "github.com/Scalingo/cli/collaborators" "github.com/Scalingo/cli/detect" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) var ( diff --git a/cmd/commands.go b/cmd/commands.go index eb2a252a5..0b9b5a3ba 100644 --- a/cmd/commands.go +++ b/cmd/commands.go @@ -13,8 +13,8 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/detect" "github.com/Scalingo/cli/session" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" ) type AppCommands struct { diff --git a/cmd/databases.go b/cmd/databases.go index 0fdb02ff0..abb733eb8 100644 --- a/cmd/databases.go +++ b/cmd/databases.go @@ -14,7 +14,7 @@ import ( dbUsers "github.com/Scalingo/cli/db/users" "github.com/Scalingo/cli/detect" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/cmd/databases_ng.go b/cmd/databases_ng.go index 4f22ee3a8..67470f2ca 100644 --- a/cmd/databases_ng.go +++ b/cmd/databases_ng.go @@ -11,7 +11,7 @@ import ( "github.com/Scalingo/cli/detect" "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) var ( diff --git a/cmd/deployments.go b/cmd/deployments.go index b695c7b80..60b56cb1e 100644 --- a/cmd/deployments.go +++ b/cmd/deployments.go @@ -10,7 +10,7 @@ import ( "github.com/Scalingo/cli/deployments" "github.com/Scalingo/cli/detect" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10/io" + "github.com/Scalingo/go-scalingo/v11/io" "github.com/Scalingo/go-utils/pagination" ) @@ -54,10 +54,7 @@ var ( `, Action: func(ctx context.Context, c *cli.Command) error { currentApp := detect.CurrentApp(ctx, c) - err := deployments.List(ctx, currentApp, pagination.Request{ - Page: c.Int("page"), - PerPage: c.Int("per-page"), - }) + err := deployments.List(ctx, currentApp, pagination.NewRequest(c.Int("page"), c.Int("per-page"))) if err != nil { errorQuit(ctx, err) } diff --git a/cmd/domains.go b/cmd/domains.go index 2ea6faf80..482d2ae5f 100644 --- a/cmd/domains.go +++ b/cmd/domains.go @@ -10,7 +10,7 @@ import ( "github.com/Scalingo/cli/detect" "github.com/Scalingo/cli/domains" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/cmd/error.go b/cmd/error.go index a7f65e160..5fbd1f608 100644 --- a/cmd/error.go +++ b/cmd/error.go @@ -16,9 +16,9 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" - httpclient "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/cmd/firewall_rules.go b/cmd/firewall_rules.go index ad8c37be3..fda0adf6f 100644 --- a/cmd/firewall_rules.go +++ b/cmd/firewall_rules.go @@ -11,7 +11,7 @@ import ( "github.com/Scalingo/cli/detect" "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) var ( diff --git a/cmd/flags.go b/cmd/flags.go index 9dda9010d..9c57c786e 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -9,7 +9,7 @@ import ( "github.com/Scalingo/cli/detect" "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" ) var ( diff --git a/cmd/integration_link.go b/cmd/integration_link.go index 98cd21e37..c4cc6d0f6 100644 --- a/cmd/integration_link.go +++ b/cmd/integration_link.go @@ -18,8 +18,8 @@ import ( "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/scmintegrations" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/cmd/log_drains.go b/cmd/log_drains.go index df20bfc1f..063565519 100644 --- a/cmd/log_drains.go +++ b/cmd/log_drains.go @@ -11,7 +11,7 @@ import ( "github.com/Scalingo/cli/detect" "github.com/Scalingo/cli/logdrains" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) const confirmDeletionSuffix = "\n\tConfirm deletion ?" diff --git a/cmd/maintenance.go b/cmd/maintenance.go index d41df5014..0b2923239 100644 --- a/cmd/maintenance.go +++ b/cmd/maintenance.go @@ -38,10 +38,7 @@ var databaseMaintenanceList = cli.Command{ addonName = addonUUIDFromFlags(ctx, c, currentResource, true) } - err := maintenance.List(ctx, currentResource, addonName, pagination.Request{ - Page: c.Int("page"), - PerPage: c.Int("per-page"), - }) + err := maintenance.List(ctx, currentResource, addonName, pagination.NewRequest(c.Int("page"), c.Int("per-page"))) if err != nil { errorQuit(ctx, err) } diff --git a/cmd/notifiers.go b/cmd/notifiers.go index 6a5409279..abfdf1e74 100644 --- a/cmd/notifiers.go +++ b/cmd/notifiers.go @@ -9,7 +9,7 @@ import ( "github.com/Scalingo/cli/detect" "github.com/Scalingo/cli/notifiers" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) var ( diff --git a/cmd/privatenetworks.go b/cmd/privatenetworks.go index 60c1a6a91..67a87cf1e 100644 --- a/cmd/privatenetworks.go +++ b/cmd/privatenetworks.go @@ -2,7 +2,6 @@ package cmd import ( "context" - "strconv" "github.com/sirupsen/logrus" "github.com/urfave/cli/v3" @@ -10,8 +9,8 @@ import ( "github.com/Scalingo/cli/cmd/autocomplete" "github.com/Scalingo/cli/detect" "github.com/Scalingo/cli/privatenetworks" - "github.com/Scalingo/go-utils/errors/v3" "github.com/Scalingo/go-utils/logger" + "github.com/Scalingo/go-utils/pagination" ) const ( @@ -29,14 +28,14 @@ var ( Value: outputFormatTable, Usage: "[" + outputFormatJSON + "|" + outputFormatTable + "]", }, - &cli.StringFlag{ + &cli.IntFlag{ Name: "page", - Value: "1", + Value: 1, Usage: "[page]", }, - &cli.StringFlag{ + &cli.IntFlag{ Name: "per-page", - Value: "20", + Value: 20, Usage: "[per-page]", }, }, @@ -55,35 +54,18 @@ var ( return nil } - pageStr := c.String("page") - perPageStr := c.String("per-page") + page := c.Int("page") + perPage := c.Int("per-page") formatStr := c.String("format") ctx, _ = logger.WithFieldsToCtx(ctx, logrus.Fields{ - "page": pageStr, - "per_page": perPageStr, + "page": page, + "per_page": perPage, "format": formatStr, }) - var err error - var page int - if pageStr != "" { - page, err = strconv.Atoi(pageStr) - if err != nil || page < 1 { - return errors.New(ctx, "invalid page number") - } - } - - var perPage int - if perPageStr != "" { - perPage, err = strconv.Atoi(perPageStr) - if err != nil || perPage < 1 || perPage > 50 { - return errors.New(ctx, "invalid per_page number") - } - } - currentApp := detect.CurrentApp(ctx, c) - err = privatenetworks.List(ctx, currentApp, formatStr, uint(page), uint(perPage)) + err := privatenetworks.List(ctx, currentApp, formatStr, pagination.NewRequest(page, perPage)) if err != nil { errorQuit(ctx, err) } diff --git a/cmd/projects.go b/cmd/projects.go index 4b01e72a4..7b1e7cf07 100644 --- a/cmd/projects.go +++ b/cmd/projects.go @@ -7,7 +7,7 @@ import ( "github.com/Scalingo/cli/cmd/autocomplete" "github.com/Scalingo/cli/projects" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/cmd/scm_integrations.go b/cmd/scm_integrations.go index 39da33c31..816253f76 100644 --- a/cmd/scm_integrations.go +++ b/cmd/scm_integrations.go @@ -10,7 +10,7 @@ import ( "github.com/Scalingo/cli/cmd/autocomplete" "github.com/Scalingo/cli/scmintegrations" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) var ( diff --git a/cmd/timeline.go b/cmd/timeline.go index 8e4e33d3e..d3e243ccb 100644 --- a/cmd/timeline.go +++ b/cmd/timeline.go @@ -36,10 +36,7 @@ var ( } utils.CheckForConsent(ctx, currentResource) - err := apps.Events(ctx, currentResource, pagination.Request{ - Page: c.Int("page"), - PerPage: c.Int("per-page"), - }) + err := apps.Events(ctx, currentResource, pagination.NewRequest(c.Int("page"), c.Int("per-page"))) if err != nil { errorQuit(ctx, err) } diff --git a/cmd/user-timeline.go b/cmd/user-timeline.go index f73bd2948..1ab8a52db 100644 --- a/cmd/user-timeline.go +++ b/cmd/user-timeline.go @@ -27,10 +27,7 @@ var ( Action: func(ctx context.Context, c *cli.Command) error { var err error if c.Args().Len() == 0 { - err = user.Events(ctx, pagination.Request{ - Page: c.Int("page"), - PerPage: c.Int("per-page"), - }) + err = user.Events(ctx, pagination.NewRequest(c.Int("page"), c.Int("per-page"))) } else { _ = cli.ShowCommandHelp(ctx, c, "user-timeline") } diff --git a/collaborators/add.go b/collaborators/add.go index 4a8946650..1b7ba2032 100644 --- a/collaborators/add.go +++ b/collaborators/add.go @@ -5,7 +5,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/collaborators/remove.go b/collaborators/remove.go index e5ac0e8f5..926fd2135 100644 --- a/collaborators/remove.go +++ b/collaborators/remove.go @@ -6,7 +6,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/collaborators/update.go b/collaborators/update.go index 25658ce9d..7d81e7922 100644 --- a/collaborators/update.go +++ b/collaborators/update.go @@ -5,7 +5,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/config/auth.go b/config/auth.go index 6c9f63b7a..2e109336f 100644 --- a/config/auth.go +++ b/config/auth.go @@ -14,8 +14,8 @@ import ( "github.com/Scalingo/cli/config/auth" appio "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/term" - "github.com/Scalingo/go-scalingo/v10" - scalingohttp "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11" + scalingohttp "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/config/auth/config.go b/config/auth/config.go index cce869e3d..bd83879ee 100644 --- a/config/auth/config.go +++ b/config/auth/config.go @@ -4,7 +4,7 @@ import ( "encoding/json" "time" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) const ( diff --git a/config/auth_test.go b/config/auth_test.go index 9c088ec01..624c82707 100644 --- a/config/auth_test.go +++ b/config/auth_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/Scalingo/cli/config/auth" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) func TestStoreAuth(t *testing.T) { diff --git a/config/config.go b/config/config.go index 20211a611..c9e6d92ac 100644 --- a/config/config.go +++ b/config/config.go @@ -13,7 +13,7 @@ import ( "github.com/kelseyhightower/envconfig" "github.com/stvp/rollbar" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/config/region.go b/config/region.go index e3109508e..992ead3bb 100644 --- a/config/region.go +++ b/config/region.go @@ -8,8 +8,8 @@ import ( "time" "github.com/Scalingo/cli/config/auth" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/crontasks/list.go b/crontasks/list.go index a824d83fe..e2e7bc45d 100644 --- a/crontasks/list.go +++ b/crontasks/list.go @@ -8,7 +8,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/utils" - httpclient "github.com/Scalingo/go-scalingo/v10/http" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/db/backup_create.go b/db/backup_create.go index efc6a063f..41324eea7 100644 --- a/db/backup_create.go +++ b/db/backup_create.go @@ -9,7 +9,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/db/backup_download.go b/db/backup_download.go index 70b212192..2f9dc8fc0 100644 --- a/db/backup_download.go +++ b/db/backup_download.go @@ -12,9 +12,9 @@ import ( "github.com/cheggaaa/pb/v3" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" - httpclient "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/db/backups.go b/db/backups.go index 5b67ab226..d4cbef602 100644 --- a/db/backups.go +++ b/db/backups.go @@ -10,7 +10,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/db/backups_config.go b/db/backups_config.go index 6951b38c0..7c020ca8d 100644 --- a/db/backups_config.go +++ b/db/backups_config.go @@ -9,7 +9,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/db/features.go b/db/features.go index 56e917c08..3be90cdde 100644 --- a/db/features.go +++ b/db/features.go @@ -9,7 +9,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/db/maintenance/info.go b/db/maintenance/info.go index 5dea3cf97..35e892cb6 100644 --- a/db/maintenance/info.go +++ b/db/maintenance/info.go @@ -11,7 +11,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/db/maintenance/info_test.go b/db/maintenance/info_test.go index 6eb43a35e..1deb8fce6 100644 --- a/db/maintenance/info_test.go +++ b/db/maintenance/info_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) type test struct { diff --git a/db/tunnel.go b/db/tunnel.go index 35afcd51f..0a3f7e28f 100644 --- a/db/tunnel.go +++ b/db/tunnel.go @@ -17,8 +17,8 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" netssh "github.com/Scalingo/cli/net/ssh" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/db/users/create.go b/db/users/create.go index 9d90ea89a..a0f3cfbaf 100644 --- a/db/users/create.go +++ b/db/users/create.go @@ -6,7 +6,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" "github.com/Scalingo/gopassword" ) diff --git a/db/users/delete.go b/db/users/delete.go index 7119b71dd..81e92a1c3 100644 --- a/db/users/delete.go +++ b/db/users/delete.go @@ -6,7 +6,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/db/users/update_password.go b/db/users/update_password.go index a073877c4..cb1c53326 100644 --- a/db/users/update_password.go +++ b/db/users/update_password.go @@ -6,7 +6,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/dbng/create.go b/dbng/create.go index 0029d0a04..614f0ee3b 100644 --- a/dbng/create.go +++ b/dbng/create.go @@ -9,7 +9,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/dbng/firewall_rules.go b/dbng/firewall_rules.go index 2de2a4c42..b64a46043 100644 --- a/dbng/firewall_rules.go +++ b/dbng/firewall_rules.go @@ -8,7 +8,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/dbng/upgrade.go b/dbng/upgrade.go index b2bb05018..a47d236b3 100644 --- a/dbng/upgrade.go +++ b/dbng/upgrade.go @@ -9,7 +9,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/deployments/deploy.go b/deployments/deploy.go index 29f050d74..4d77130d1 100644 --- a/deployments/deploy.go +++ b/deployments/deploy.go @@ -9,9 +9,9 @@ import ( "time" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" - scalingoio "github.com/Scalingo/go-scalingo/v10/io" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" + scalingoio "github.com/Scalingo/go-scalingo/v11/io" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/deployments/deploy_war.go b/deployments/deploy_war.go index 518aa77af..8d130a3d5 100644 --- a/deployments/deploy_war.go +++ b/deployments/deploy_war.go @@ -15,7 +15,7 @@ import ( "time" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/deployments/follow.go b/deployments/follow.go index 936a5e202..e7f26822c 100644 --- a/deployments/follow.go +++ b/deployments/follow.go @@ -10,8 +10,8 @@ import ( "time" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/deployments/logs.go b/deployments/logs.go index 3e8bbaa5b..66cac88c0 100644 --- a/deployments/logs.go +++ b/deployments/logs.go @@ -3,10 +3,12 @@ package deployments import ( "context" stdio "io" + "net/http" "os" "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) @@ -26,24 +28,27 @@ func Logs(ctx context.Context, app, deploymentID string) error { deploymentID = deployments[0].ID io.Infof("-----> Selected the most recent deployment (%s)\n", deploymentID) } - deploy, err := client.Deployment(ctx, app, deploymentID) + deploy, err := client.Deployment(ctx, app, deploymentID) if err != nil { return errors.Wrapf(ctx, err, "get deployment %s", deploymentID) } - res, err := client.DeploymentLogs(ctx, deploy.Links.Output) - + readCloser, err := client.DeploymentLogs(ctx, deploy.Links.Output) if err != nil { - return errors.Wrap(ctx, err, "fetch deployment logs") - } - - defer res.Body.Close() + var requestFailedErr *httpclient.RequestFailedError + if !errors.As(err, &requestFailedErr) || requestFailedErr.Code != http.StatusNotFound { + return errors.Wrap(ctx, err, "fetch deployment logs") + } - if res.StatusCode == 404 { io.Error("There is no log for this deployment.") - } else { - stdio.Copy(os.Stdout, res.Body) + return nil + } + defer readCloser.Close() + + _, err = stdio.Copy(os.Stdout, readCloser) + if err != nil { + return errors.Wrap(ctx, err, "copy deployment logs to stdout") } return nil } diff --git a/detect/app.go b/detect/app.go index 595c06343..94dc47383 100644 --- a/detect/app.go +++ b/detect/app.go @@ -11,7 +11,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/detect/region.go b/detect/region.go index 0a9c8b955..91fb21333 100644 --- a/detect/region.go +++ b/detect/region.go @@ -9,7 +9,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/detect/region_test.go b/detect/region_test.go index 2bb5ecdbd..4eaaf49bb 100644 --- a/detect/region_test.go +++ b/detect/region_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) func TestGetRegionFromGitRemote(t *testing.T) { diff --git a/domains/add.go b/domains/add.go index 83014c049..e39d5da5a 100644 --- a/domains/add.go +++ b/domains/add.go @@ -5,7 +5,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/domains/list.go b/domains/list.go index 4b7ad3f7e..9134bbac3 100644 --- a/domains/list.go +++ b/domains/list.go @@ -9,7 +9,7 @@ import ( "github.com/olekukonko/tablewriter" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/domains/remove.go b/domains/remove.go index a79f3e30d..879b88e2c 100644 --- a/domains/remove.go +++ b/domains/remove.go @@ -5,7 +5,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/env/edit.go b/env/edit.go index cebc1a7a6..0cca63787 100644 --- a/env/edit.go +++ b/env/edit.go @@ -11,7 +11,7 @@ import ( "github.com/joho/godotenv" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) @@ -45,7 +45,7 @@ func Add(ctx context.Context, app string, params []string, filePath string) erro if err != nil { return errors.Wrapf(ctx, err, "get Scalingo client") } - _, _, err = c.VariableMultipleSet(ctx, app, scalingoVariables) + _, err = c.VariableMultipleSet(ctx, app, scalingoVariables) if err != nil { return errors.Wrapf(ctx, err, "set multiple environment variables") } diff --git a/events/timeline.go b/events/timeline.go index 6ff80f08a..6c8a32acc 100644 --- a/events/timeline.go +++ b/events/timeline.go @@ -5,7 +5,7 @@ import ( "os" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/pagination" ) diff --git a/git/setup.go b/git/setup.go index f30952059..b9520211b 100644 --- a/git/setup.go +++ b/git/setup.go @@ -7,7 +7,7 @@ import ( gitconfig "github.com/go-git/go-git/v5/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/go.mod b/go.mod index fe32e6914..28ca1420b 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.25.0 require ( github.com/AlecAivazis/survey/v2 v2.3.7 - github.com/Scalingo/go-scalingo/v10 v10.0.0 + github.com/Scalingo/go-scalingo/v11 v11.0.0 github.com/Scalingo/go-utils/errors/v3 v3.2.0 github.com/Scalingo/go-utils/logger v1.12.0 github.com/Scalingo/go-utils/pagination v1.2.0 @@ -26,7 +26,7 @@ require ( github.com/urfave/cli/v3 v3.6.2 golang.org/x/crypto v0.48.0 golang.org/x/term v0.40.0 - golang.org/x/text v0.34.0 + golang.org/x/text v0.35.0 ) require ( @@ -46,7 +46,6 @@ require ( github.com/goccy/go-json v0.10.5 // indirect github.com/golang-jwt/jwt/v5 v5.3.1 // indirect github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect - github.com/golang/mock v1.6.0 // indirect github.com/google/go-querystring v1.2.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect @@ -65,6 +64,7 @@ require ( github.com/sergi/go-diff v1.4.0 // indirect github.com/skeema/knownhosts v1.3.2 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect + go.uber.org/mock v0.6.0 // indirect golang.org/x/net v0.51.0 // indirect golang.org/x/sys v0.41.0 // indirect gopkg.in/errgo.v1 v1.0.1 // indirect diff --git a/go.sum b/go.sum index cd032de21..8f9d25edf 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63n github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w= github.com/ProtonMail/go-crypto v1.4.0 h1:Zq/pbM3F5DFgJiMouxEdSVY44MVoQNEKp5d5QxIQceQ= github.com/ProtonMail/go-crypto v1.4.0/go.mod h1:e1OaTyu5SYVrO9gKOEhTc+5UcXtTUa+P3uLudwcgPqo= -github.com/Scalingo/go-scalingo/v10 v10.0.0 h1:xUbb+MTkzdgWisXhw3MHa0nVSVuossNZJBjw8ak1AFc= -github.com/Scalingo/go-scalingo/v10 v10.0.0/go.mod h1:d5J8wm6cO1bEycKuLXuWfGY99OhmYR3ATu7QRYvAEAk= +github.com/Scalingo/go-scalingo/v11 v11.0.0 h1:URWRLO4mK+06WMfA6065vVwKIL0k4146RCiZuxARWp4= +github.com/Scalingo/go-scalingo/v11 v11.0.0/go.mod h1:SKmfy5pA4i9jb6Zxx5n2X9uh9Q7Hwkr1sCDICA/3Z4U= github.com/Scalingo/go-utils/errors/v3 v3.2.0 h1:Ks+v2oRwv3VZfe+xVB+kpfmZouXHVCPHHtwL5W60prc= github.com/Scalingo/go-utils/errors/v3 v3.2.0/go.mod h1:jVVNoOdYFjuNkR/BeEZWNWJVvu4jmyLY4udlsQQyBss= github.com/Scalingo/go-utils/logger v1.12.0 h1:tK1LwRz7ijYLGe7/c4SzAtNEJCbSPQnOo859O1FsOLM= @@ -70,8 +70,6 @@ github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63Y github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ= github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/google/go-cmp v0.2.1-0.20190312032427-6f77996f0c42/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= @@ -153,38 +151,31 @@ github.com/urfave/cli/v3 v3.6.2 h1:lQuqiPrZ1cIz8hz+HcrG0TNZFxU70dPZ3Yl+pSrH9A8= github.com/urfave/cli/v3 v3.6.2/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= +go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts= golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo= golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -202,15 +193,12 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= -golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA= +golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8= +golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/integrationlink/create.go b/integrationlink/create.go index 987edfa97..4c6c133ab 100644 --- a/integrationlink/create.go +++ b/integrationlink/create.go @@ -8,8 +8,8 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/integrationlink/params.go b/integrationlink/params.go index 0dd255c4a..c39323352 100644 --- a/integrationlink/params.go +++ b/integrationlink/params.go @@ -4,7 +4,7 @@ import ( "github.com/urfave/cli/v3" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) func CheckAndFillParams(c *cli.Command) *scalingo.SCMRepoLinkUpdateParams { diff --git a/integrationlink/pull_request.go b/integrationlink/pull_request.go index 229a2aa31..c2e9f991f 100644 --- a/integrationlink/pull_request.go +++ b/integrationlink/pull_request.go @@ -4,7 +4,7 @@ import ( "context" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/integrationlink/show.go b/integrationlink/show.go index 4e19e48e5..22c1d0ff2 100644 --- a/integrationlink/show.go +++ b/integrationlink/show.go @@ -10,8 +10,8 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/integrationlink/update.go b/integrationlink/update.go index 8e635745d..ff3b6bd85 100644 --- a/integrationlink/update.go +++ b/integrationlink/update.go @@ -6,7 +6,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/utils" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/keys/remove.go b/keys/remove.go index b116fb805..1d8453e51 100644 --- a/keys/remove.go +++ b/keys/remove.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/logdrains/add.go b/logdrains/add.go index 57c63a23b..1f9789001 100644 --- a/logdrains/add.go +++ b/logdrains/add.go @@ -5,7 +5,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/logdrains/list.go b/logdrains/list.go index 39c191a65..9e774c7f3 100644 --- a/logdrains/list.go +++ b/logdrains/list.go @@ -9,7 +9,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/logs/logs.go b/logs/logs.go index 0c48e83bf..e67f81695 100644 --- a/logs/logs.go +++ b/logs/logs.go @@ -21,7 +21,8 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" "github.com/Scalingo/cli/signals" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) @@ -41,17 +42,15 @@ func Dump(ctx context.Context, logsURL string, n int, filter string) error { return errors.Wrapf(ctx, err, "fail to get Scalingo client") } - res, err := c.Logs(ctx, logsURL, n, filter) - if err != nil { - return errors.Wrap(ctx, err, "fetch logs") - } - defer res.Body.Close() - - if res.StatusCode == 404 || res.StatusCode == 204 { + readCloser, err := c.Logs(ctx, logsURL, n, filter) + if errors.Is(err, scalingo.ErrNoLogs) { io.Error("There is no log for this application") io.Info("Ensure your application is writing to the standard output") return nil + } else if err != nil { + return errors.Wrap(ctx, err, "fetch logs") } + defer readCloser.Close() // Create a buffered channel with a maximum size of the number of log lines // requested. On medium to good internet connection, we are fetching lines @@ -88,7 +87,7 @@ func Dump(ctx context.Context, logsURL string, n int, filter string) error { // this internal buffer until it runs out. However if our logs processing // pipeline is slow, it will never query the next 4MB of data. Hence the // buffered channel. - sr := bufio.NewReader(res.Body) + sr := bufio.NewReader(readCloser) for { // Read one line from the response diff --git a/net/ssh/client.go b/net/ssh/client.go index 9a3230742..57b6d08c1 100644 --- a/net/ssh/client.go +++ b/net/ssh/client.go @@ -9,7 +9,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/crypto/sshkeys" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/notifiers/create.go b/notifiers/create.go index eaca965ba..fe2096c96 100644 --- a/notifiers/create.go +++ b/notifiers/create.go @@ -5,8 +5,8 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/notifiers/destroy.go b/notifiers/destroy.go index 0039d7686..19e5c6304 100644 --- a/notifiers/destroy.go +++ b/notifiers/destroy.go @@ -7,7 +7,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/notifiers/details.go b/notifiers/details.go index 9b16b6a35..84ae45fd7 100644 --- a/notifiers/details.go +++ b/notifiers/details.go @@ -11,7 +11,7 @@ import ( "golang.org/x/text/language" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/notifiers/list.go b/notifiers/list.go index 168b9f709..604cd2beb 100644 --- a/notifiers/list.go +++ b/notifiers/list.go @@ -8,7 +8,7 @@ import ( "github.com/olekukonko/tablewriter" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/privatenetworks/list.go b/privatenetworks/list.go index 4305ebb63..7d544ae0d 100644 --- a/privatenetworks/list.go +++ b/privatenetworks/list.go @@ -12,17 +12,18 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/go-utils/errors/v3" + "github.com/Scalingo/go-utils/pagination" ) const containerTypeWeb = "web" -func List(ctx context.Context, app string, format string, page uint, perPage uint) error { +func List(ctx context.Context, app string, format string, paginationReq pagination.Request) error { scalingoClient, err := config.ScalingoClient(ctx) if err != nil { return errors.Wrapf(ctx, err, "get Scalingo client") } - domainNames, err := scalingoClient.PrivateNetworksDomainsList(ctx, app, page, perPage) + domainNames, err := scalingoClient.PrivateNetworksDomainsList(ctx, app, paginationReq) if err != nil { return errors.Wrapf(ctx, err, "list private network domains") } diff --git a/projects/add.go b/projects/add.go index f0f5e952d..ad2ba35cc 100644 --- a/projects/add.go +++ b/projects/add.go @@ -5,7 +5,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/projects/update.go b/projects/update.go index 17411e33c..c3d39092e 100644 --- a/projects/update.go +++ b/projects/update.go @@ -5,7 +5,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/scalingo/main.go b/scalingo/main.go index b144e1565..b357db768 100644 --- a/scalingo/main.go +++ b/scalingo/main.go @@ -16,7 +16,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/signals" "github.com/Scalingo/cli/update" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" "github.com/Scalingo/go-utils/logger" ) diff --git a/scmintegrations/create.go b/scmintegrations/create.go index fab3d54c1..7abe462f4 100644 --- a/scmintegrations/create.go +++ b/scmintegrations/create.go @@ -5,7 +5,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/scmintegrations/delete.go b/scmintegrations/delete.go index 3f2754374..5d13af2fa 100644 --- a/scmintegrations/delete.go +++ b/scmintegrations/delete.go @@ -5,7 +5,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/scmintegrations/import_keys.go b/scmintegrations/import_keys.go index e7b4d6693..f3ab9d308 100644 --- a/scmintegrations/import_keys.go +++ b/scmintegrations/import_keys.go @@ -9,7 +9,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/scmintegrations/list.go b/scmintegrations/list.go index 4994fde1e..64237e9a1 100644 --- a/scmintegrations/list.go +++ b/scmintegrations/list.go @@ -8,7 +8,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/scmintegrations/utils.go b/scmintegrations/utils.go index 506d28c4b..ebfa09b96 100644 --- a/scmintegrations/utils.go +++ b/scmintegrations/utils.go @@ -7,7 +7,7 @@ import ( "net/url" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/services/github/client.go b/services/github/client.go index 1093c9808..c44ae262d 100644 --- a/services/github/client.go +++ b/services/github/client.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-github/v47/github" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/session/login.go b/session/login.go index c0d4abd2f..0bb2968f2 100644 --- a/session/login.go +++ b/session/login.go @@ -7,8 +7,8 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" netssh "github.com/Scalingo/cli/net/ssh" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/stacks/set.go b/stacks/set.go index 0f4c3a6f7..6d93418ed 100644 --- a/stacks/set.go +++ b/stacks/set.go @@ -5,7 +5,7 @@ import ( "github.com/Scalingo/cli/config" "github.com/Scalingo/cli/io" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/utils/database.go b/utils/database.go index fa3065995..78374c229 100644 --- a/utils/database.go +++ b/utils/database.go @@ -5,7 +5,7 @@ import ( stderrors "errors" "github.com/Scalingo/cli/config" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/utils/errors.go b/utils/errors.go index 76f4dabdf..31e46d920 100644 --- a/utils/errors.go +++ b/utils/errors.go @@ -1,7 +1,7 @@ package utils import ( - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/utils/git.go b/utils/git.go index 2d34dc7ae..ec67c250e 100644 --- a/utils/git.go +++ b/utils/git.go @@ -12,7 +12,7 @@ import ( gitconfig "github.com/go-git/go-git/v5/config" "github.com/go-git/go-git/v5/plumbing" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/utils/helper.go b/utils/helper.go index af4571ed9..6fd0f9c83 100644 --- a/utils/helper.go +++ b/utils/helper.go @@ -7,8 +7,8 @@ import ( "os" "strings" - "github.com/Scalingo/go-scalingo/v10" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/utils/plans.go b/utils/plans.go index 408dba35d..ee382d3d3 100644 --- a/utils/plans.go +++ b/utils/plans.go @@ -3,7 +3,7 @@ package utils import ( "context" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/utils/roles.go b/utils/roles.go index c7ecdd8ec..fa8fc1a81 100644 --- a/utils/roles.go +++ b/utils/roles.go @@ -1,7 +1,7 @@ package utils import ( - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) const ( diff --git a/utils/time.go b/utils/time.go index de576a20d..afdf096a6 100644 --- a/utils/time.go +++ b/utils/time.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) const ( diff --git a/utils/time_test.go b/utils/time_test.go index 2a96f403e..5f034a674 100644 --- a/utils/time_test.go +++ b/utils/time_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) func Test_beginningOfDay(t *testing.T) { diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/version.go b/vendor/github.com/Scalingo/go-scalingo/v10/version.go deleted file mode 100644 index 1c809787e..000000000 --- a/vendor/github.com/Scalingo/go-scalingo/v10/version.go +++ /dev/null @@ -1,3 +0,0 @@ -package scalingo - -var Version = "10.0.0" diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/.ackrc b/vendor/github.com/Scalingo/go-scalingo/v11/.ackrc similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/.ackrc rename to vendor/github.com/Scalingo/go-scalingo/v11/.ackrc diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/.env.test b/vendor/github.com/Scalingo/go-scalingo/v11/.env.test similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/.env.test rename to vendor/github.com/Scalingo/go-scalingo/v11/.env.test diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/.gitignore b/vendor/github.com/Scalingo/go-scalingo/v11/.gitignore similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/.gitignore rename to vendor/github.com/Scalingo/go-scalingo/v11/.gitignore diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/CHANGELOG.md b/vendor/github.com/Scalingo/go-scalingo/v11/CHANGELOG.md similarity index 98% rename from vendor/github.com/Scalingo/go-scalingo/v10/CHANGELOG.md rename to vendor/github.com/Scalingo/go-scalingo/v11/CHANGELOG.md index 4ac902485..0f134d1ba 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/CHANGELOG.md +++ b/vendor/github.com/Scalingo/go-scalingo/v11/CHANGELOG.md @@ -2,6 +2,13 @@ ## To Be Released +## 11.0.0 + +* fix(privatenetworks): `PrivateNetworksDomainsList` must take a `pagination.Request` in argument (breaking change) +* fix(errors): detect if body is invalid in case of 422 +* refactor: replace `github.com/golang/mock` with `go.uber.org/mock` +* refactor(env): replace most calls to `Do` with calls to `DoRequest` (breaking change) + ## 10.0.0 * chore(databases): refactor constants diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/Dockerfile b/vendor/github.com/Scalingo/go-scalingo/v11/Dockerfile similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/Dockerfile rename to vendor/github.com/Scalingo/go-scalingo/v11/Dockerfile diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/LICENSE b/vendor/github.com/Scalingo/go-scalingo/v11/LICENSE similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/LICENSE rename to vendor/github.com/Scalingo/go-scalingo/v11/LICENSE diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/README.md b/vendor/github.com/Scalingo/go-scalingo/v11/README.md similarity index 96% rename from vendor/github.com/Scalingo/go-scalingo/v10/README.md rename to vendor/github.com/Scalingo/go-scalingo/v11/README.md index 79dbe3cdd..758669753 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/README.md +++ b/vendor/github.com/Scalingo/go-scalingo/v11/README.md @@ -1,4 +1,4 @@ -# Go client for Scalingo API v10.0.0 +# Go client for Scalingo API v11.0.0 This repository is the Go client for the [Scalingo APIs](https://developers.scalingo.com/). @@ -8,7 +8,7 @@ This repository is the Go client for the [Scalingo APIs](https://developers.scal package main import ( - "github.com/Scalingo/go-scalingo/v10" + "github.com/Scalingo/go-scalingo/v11" ) func getClient() (*scalingo.Client, error) { @@ -81,11 +81,11 @@ Bump new version number in: Commit, tag and create a new release: ```sh -version="10.0.0" +version="11.0.0" git switch --create release/${version} git add CHANGELOG.md README.md version.go -git commit -m "Bump v${version}" +git commit --message="Bump v${version}" git push --set-upstream origin release/${version} gh pr create --reviewer=scalingo/team-ist --title "$(git log -1 --pretty=%B)" ``` diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/addons.go b/vendor/github.com/Scalingo/go-scalingo/v11/addons.go similarity index 86% rename from vendor/github.com/Scalingo/go-scalingo/v10/addons.go rename to vendor/github.com/Scalingo/go-scalingo/v11/addons.go index ca8e1aefa..c4d524685 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/addons.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/addons.go @@ -2,12 +2,10 @@ package scalingo import ( "context" - "encoding/json" - "io" "strconv" "time" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) @@ -141,45 +139,28 @@ func (c *Client) AddonToken(ctx context.Context, app, addonID string) (string, e } func (c *Client) AddonLogsURL(ctx context.Context, app, addonID string) (string, error) { - var url AddonLogsURLRes - res, err := c.DBAPI(app, addonID).Do(ctx, &http.APIRequest{ + var urlRes AddonLogsURLRes + err := c.DBAPI(app, addonID).DoRequest(ctx, &http.APIRequest{ Endpoint: "/databases/" + addonID + "/logs", - }) + }, &urlRes) if err != nil { return "", errors.Wrap(ctx, err, "get addon log URL") } - defer res.Body.Close() - err = json.NewDecoder(res.Body).Decode(&url) - if err != nil { - return "", errors.Wrap(ctx, err, "decode addon log URL response") - } - - return url.URL, nil + return urlRes.URL, nil } func (c *Client) AddonLogsArchives(ctx context.Context, app, addonID string, page int) (*LogsArchivesResponse, error) { - res, err := c.DBAPI(app, addonID).Do(ctx, &http.APIRequest{ + var logsRes LogsArchivesResponse + err := c.DBAPI(app, addonID).DoRequest(ctx, &http.APIRequest{ Endpoint: "/databases/" + addonID + "/logs_archives", Params: map[string]string{ "page": strconv.FormatInt(int64(page), 10), }, - }) + }, &logsRes) if err != nil { return nil, errors.Wrap(ctx, err, "get addon log archives") } - defer res.Body.Close() - - body, err := io.ReadAll(res.Body) - if err != nil { - return nil, errors.Wrap(ctx, err, "read addon log archives response body") - } - - var logsRes = LogsArchivesResponse{} - err = json.Unmarshal(body, &logsRes) - if err != nil { - return nil, errors.Wrap(ctx, err, "decode addon log archives response") - } return &logsRes, nil } diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/addons_providers.go b/vendor/github.com/Scalingo/go-scalingo/v11/addons_providers.go similarity index 98% rename from vendor/github.com/Scalingo/go-scalingo/v10/addons_providers.go rename to vendor/github.com/Scalingo/go-scalingo/v11/addons_providers.go index 6e8d32311..e75d98292 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/addons_providers.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/addons_providers.go @@ -4,7 +4,7 @@ import ( "context" "strconv" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/alerts.go b/vendor/github.com/Scalingo/go-scalingo/v11/alerts.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/alerts.go rename to vendor/github.com/Scalingo/go-scalingo/v11/alerts.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/apps.go b/vendor/github.com/Scalingo/go-scalingo/v11/apps.go similarity index 87% rename from vendor/github.com/Scalingo/go-scalingo/v10/apps.go rename to vendor/github.com/Scalingo/go-scalingo/v11/apps.go index ac37eaea8..02788c8bb 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/apps.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/apps.go @@ -2,11 +2,12 @@ package scalingo import ( "context" + "encoding/json" "fmt" "net/http" "time" - httpclient "github.com/Scalingo/go-scalingo/v10/http" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) @@ -27,12 +28,12 @@ type AppsService interface { AppsRename(ctx context.Context, name string, newName string) (*App, error) AppsTransfer(ctx context.Context, name string, email string) (*App, error) AppsSetStack(ctx context.Context, name string, stackID string) (*App, error) - AppsRestart(ctx context.Context, app string, scope *AppsRestartParams) (*http.Response, error) + AppsRestart(ctx context.Context, app string, scope *AppsRestartParams) (string, error) AppsCreate(ctx context.Context, opts AppsCreateOpts) (*App, error) AppsStats(ctx context.Context, app string) (*AppStatsRes, error) AppsContainerTypes(ctx context.Context, app string) ([]ContainerType, error) AppsContainersPs(ctx context.Context, app string) ([]Container, error) - AppsScale(ctx context.Context, app string, params *AppsScaleParams) (*http.Response, error) + AppsScale(ctx context.Context, app string, params *AppsScaleParams) ([]ContainerType, string, error) AppsForceHTTPS(ctx context.Context, name string, enable bool) (*App, error) AppsStickySession(ctx context.Context, name string, enable bool) (*App, error) AppsRouterLogs(ctx context.Context, name string, enable bool) (*App, error) @@ -241,7 +242,9 @@ func (c *Client) AppsSetStack(ctx context.Context, app string, stackID string) ( return appRes.App, nil } -func (c *Client) AppsRestart(ctx context.Context, app string, scope *AppsRestartParams) (*http.Response, error) { +// AppsRestart order the restart of the given application containers, limited by the given scope. +// It returns an operation URL to track its progress. +func (c *Client) AppsRestart(ctx context.Context, app string, scope *AppsRestartParams) (string, error) { req := &httpclient.APIRequest{ Method: "POST", Endpoint: "/apps/" + app + "/restart", @@ -249,7 +252,13 @@ func (c *Client) AppsRestart(ctx context.Context, app string, scope *AppsRestart Params: scope, } - return c.ScalingoAPI().Do(ctx, req) + res, err := c.ScalingoAPI().Do(ctx, req) + if err != nil { + return "", errors.Wrap(ctx, err, "request Scalingo API to restart the application") + } + defer res.Body.Close() + + return res.Header.Get("Location"), nil } func (c *Client) AppsCreate(ctx context.Context, opts AppsCreateOpts) (*App, error) { @@ -305,16 +314,33 @@ func (c *Client) AppsContainerTypes(ctx context.Context, app string) ([]Containe return containerTypesRes.Containers, nil } -func (c *Client) AppsScale(ctx context.Context, app string, params *AppsScaleParams) (*http.Response, error) { +type ScaleRes struct { + Containers []ContainerType `json:"containers"` +} + +// AppsScale scales an app and returns the updated containers and the operation URL when scaling is processed asynchronously. +func (c *Client) AppsScale(ctx context.Context, app string, params *AppsScaleParams) ([]ContainerType, string, error) { req := &httpclient.APIRequest{ Method: "POST", Endpoint: "/apps/" + app + "/scale", Params: params, - // Return 200 if app is scaled before deployment - // Otherwise async job is triggered, it's 202 - Expected: httpclient.Statuses{200, 202}, + // Return "200 OK" if app is scaled before deployment. + // Otherwise async job is triggered, it's "202 Accepted". + Expected: httpclient.Statuses{http.StatusOK, http.StatusAccepted}, } - return c.ScalingoAPI().Do(ctx, req) + res, err := c.ScalingoAPI().Do(ctx, req) + if err != nil { + return nil, "", errors.Wrap(ctx, err, "request Scalingo API to scale the application") + } + defer res.Body.Close() + + var scaleRes ScaleRes + err = json.NewDecoder(res.Body).Decode(&scaleRes) + if err != nil { + return nil, "", errors.Wrapf(ctx, err, "decode API response to scale request") + } + + return scaleRes.Containers, res.Header.Get("Location"), nil } func (c *Client) AppsForceHTTPS(ctx context.Context, name string, enable bool) (*App, error) { diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/auth_mock.go b/vendor/github.com/Scalingo/go-scalingo/v11/auth_mock.go similarity index 51% rename from vendor/github.com/Scalingo/go-scalingo/v10/auth_mock.go rename to vendor/github.com/Scalingo/go-scalingo/v11/auth_mock.go index 0493c8ce0..e3d1e2bc2 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/auth_mock.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/auth_mock.go @@ -1,36 +1,34 @@ package scalingo import ( - "bytes" "context" - "fmt" - "io" - "net/http" "time" "github.com/golang-jwt/jwt/v5" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" - httpclient "github.com/Scalingo/go-scalingo/v10/http" - "github.com/Scalingo/go-scalingo/v10/http/httpmock" + httpclient "github.com/Scalingo/go-scalingo/v11/http" + "github.com/Scalingo/go-scalingo/v11/http/httpmock" ) func MockAuth(ctrl *gomock.Controller) *httpmock.MockClient { mock := httpmock.NewMockClient(ctrl) - mock.EXPECT().Do(gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, _ *httpclient.APIRequest) (*http.Response, error) { + mock.EXPECT().DoRequest(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, _ *httpclient.APIRequest, data any) error { claims := &jwt.RegisteredClaims{ ExpiresAt: jwt.NewNumericDate(time.Now().Add(5 * time.Minute)), } jwtToken := jwt.NewWithClaims(jwt.SigningMethodNone, claims) jwt, err := jwtToken.SignedString(jwt.UnsafeAllowNoneSignatureType) if err != nil { - return nil, err + return err } - return &http.Response{ - Body: io.NopCloser(bytes.NewBuffer(fmt.Appendf(nil, `{"token": "%v"}`, jwt))), - }, nil + if data != nil { + res, _ := data.(*BearerTokenRes) + res.Token = jwt + } + return nil }).AnyTimes() return mock } diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/autoscalers.go b/vendor/github.com/Scalingo/go-scalingo/v11/autoscalers.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/autoscalers.go rename to vendor/github.com/Scalingo/go-scalingo/v11/autoscalers.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/backups.go b/vendor/github.com/Scalingo/go-scalingo/v11/backups.go similarity index 90% rename from vendor/github.com/Scalingo/go-scalingo/v10/backups.go rename to vendor/github.com/Scalingo/go-scalingo/v11/backups.go index 1445c1814..a1f63902c 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/backups.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/backups.go @@ -2,10 +2,9 @@ package scalingo import ( "context" - "encoding/json" "time" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) @@ -83,20 +82,14 @@ func (c *Client) BackupShow(ctx context.Context, app, addonID, backup string) (* } func (c *Client) BackupDownloadURL(ctx context.Context, app, addonID, backupID string) (string, error) { + var downloadRes DownloadURLRes req := &http.APIRequest{ Method: "GET", Endpoint: "/databases/" + addonID + "/backups/" + backupID + "/archive", } - resp, err := c.DBAPI(app, addonID).Do(ctx, req) + err := c.DBAPI(app, addonID).DoRequest(ctx, req, &downloadRes) if err != nil { return "", errors.Wrap(ctx, err, "get backup archive") } - defer resp.Body.Close() - - var downloadRes DownloadURLRes - err = json.NewDecoder(resp.Body).Decode(&downloadRes) - if err != nil { - return "", errors.Wrap(ctx, err, "decode backup archive") - } return downloadRes.DownloadURL, nil } diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/billing/profile.go b/vendor/github.com/Scalingo/go-scalingo/v11/billing/profile.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/billing/profile.go rename to vendor/github.com/Scalingo/go-scalingo/v11/billing/profile.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/client.go b/vendor/github.com/Scalingo/go-scalingo/v11/client.go similarity index 98% rename from vendor/github.com/Scalingo/go-scalingo/v10/client.go rename to vendor/github.com/Scalingo/go-scalingo/v11/client.go index 7dc7737ca..a4bcb0a5b 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/client.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/client.go @@ -6,7 +6,7 @@ import ( "net/http" "time" - httpclient "github.com/Scalingo/go-scalingo/v10/http" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/collaborators.go b/vendor/github.com/Scalingo/go-scalingo/v11/collaborators.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/collaborators.go rename to vendor/github.com/Scalingo/go-scalingo/v11/collaborators.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/container.go b/vendor/github.com/Scalingo/go-scalingo/v11/container.go similarity index 96% rename from vendor/github.com/Scalingo/go-scalingo/v10/container.go rename to vendor/github.com/Scalingo/go-scalingo/v11/container.go index 2aaaf8290..90075bfd4 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/container.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/container.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - httpclient "github.com/Scalingo/go-scalingo/v10/http" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/container_sizes.go b/vendor/github.com/Scalingo/go-scalingo/v11/container_sizes.go similarity index 95% rename from vendor/github.com/Scalingo/go-scalingo/v10/container_sizes.go rename to vendor/github.com/Scalingo/go-scalingo/v11/container_sizes.go index 4303b2f70..2b4ad7b74 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/container_sizes.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/container_sizes.go @@ -3,7 +3,7 @@ package scalingo import ( "context" - httpclient "github.com/Scalingo/go-scalingo/v10/http" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/cron_tasks.go b/vendor/github.com/Scalingo/go-scalingo/v11/cron_tasks.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/cron_tasks.go rename to vendor/github.com/Scalingo/go-scalingo/v11/cron_tasks.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/data_access_consent.go b/vendor/github.com/Scalingo/go-scalingo/v11/data_access_consent.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/data_access_consent.go rename to vendor/github.com/Scalingo/go-scalingo/v11/data_access_consent.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/database_type_versions.go b/vendor/github.com/Scalingo/go-scalingo/v11/database_type_versions.go similarity index 97% rename from vendor/github.com/Scalingo/go-scalingo/v10/database_type_versions.go rename to vendor/github.com/Scalingo/go-scalingo/v11/database_type_versions.go index 9aef73db7..7fa94efac 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/database_type_versions.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/database_type_versions.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/databases.go b/vendor/github.com/Scalingo/go-scalingo/v11/databases.go similarity index 99% rename from vendor/github.com/Scalingo/go-scalingo/v10/databases.go rename to vendor/github.com/Scalingo/go-scalingo/v11/databases.go index 413d1c59a..8052e95b5 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/databases.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/databases.go @@ -5,7 +5,7 @@ import ( "net/http" "time" - httpclient "github.com/Scalingo/go-scalingo/v10/http" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" "github.com/Scalingo/go-utils/pagination" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/databases_preview.go b/vendor/github.com/Scalingo/go-scalingo/v11/databases_preview.go similarity index 99% rename from vendor/github.com/Scalingo/go-scalingo/v10/databases_preview.go rename to vendor/github.com/Scalingo/go-scalingo/v11/databases_preview.go index 09a73e89d..2a547f100 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/databases_preview.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/databases_preview.go @@ -4,7 +4,7 @@ import ( "context" stderrors "errors" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/debug/log.go b/vendor/github.com/Scalingo/go-scalingo/v11/debug/log.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/debug/log.go rename to vendor/github.com/Scalingo/go-scalingo/v11/debug/log.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/deployments.go b/vendor/github.com/Scalingo/go-scalingo/v11/deployments.go similarity index 95% rename from vendor/github.com/Scalingo/go-scalingo/v10/deployments.go rename to vendor/github.com/Scalingo/go-scalingo/v11/deployments.go index f07d18437..d0cc2f521 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/deployments.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/deployments.go @@ -3,13 +3,14 @@ package scalingo import ( "context" "encoding/json" + "io" "net/http" "net/url" "time" "github.com/gorilla/websocket" - httpclient "github.com/Scalingo/go-scalingo/v10/http" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" "github.com/Scalingo/go-utils/pagination" ) @@ -18,7 +19,7 @@ type DeploymentsService interface { DeploymentList(ctx context.Context, app string) ([]*Deployment, error) DeploymentListWithPagination(ctx context.Context, app string, paginationReq pagination.Request) ([]*Deployment, pagination.Meta, error) Deployment(ctx context.Context, app string, deploy string) (*Deployment, error) - DeploymentLogs(ctx context.Context, deployURL string) (*http.Response, error) + DeploymentLogs(ctx context.Context, deployURL string) (io.ReadCloser, error) DeploymentStream(ctx context.Context, deployURL string) (*websocket.Conn, error) DeploymentsCreate(ctx context.Context, app string, params *DeploymentsCreateParams) (*Deployment, error) } @@ -173,18 +174,22 @@ func (c *Client) Deployment(ctx context.Context, app string, deploy string) (*De return deploymentMap["deployment"], nil } -func (c *Client) DeploymentLogs(ctx context.Context, deployURL string) (*http.Response, error) { +func (c *Client) DeploymentLogs(ctx context.Context, deployURL string) (io.ReadCloser, error) { u, err := url.Parse(deployURL) if err != nil { return nil, errors.Wrap(ctx, err, "parse deployment URL") } req := &httpclient.APIRequest{ - Expected: httpclient.Statuses{200, 404}, + Expected: httpclient.Statuses{http.StatusOK}, Endpoint: u.Path, URL: u.Scheme + "://" + u.Host, } - return c.ScalingoAPI().Do(ctx, req) + res, err := c.ScalingoAPI().Do(ctx, req) + if err != nil { + return nil, errors.Wrap(ctx, err, "request Scalingo API to get the deployment logs") + } + return res.Body, err } // DeploymentStream returns a websocket connection to follow the various deployment events happening on an application. The type of the data sent on this connection is DeployEvent. diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/docker-compose.yml b/vendor/github.com/Scalingo/go-scalingo/v11/docker-compose.yml similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/docker-compose.yml rename to vendor/github.com/Scalingo/go-scalingo/v11/docker-compose.yml diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/domains.go b/vendor/github.com/Scalingo/go-scalingo/v11/domains.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/domains.go rename to vendor/github.com/Scalingo/go-scalingo/v11/domains.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/env.go b/vendor/github.com/Scalingo/go-scalingo/v11/env.go similarity index 70% rename from vendor/github.com/Scalingo/go-scalingo/v10/env.go rename to vendor/github.com/Scalingo/go-scalingo/v11/env.go index 581411191..ba7db9359 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/env.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/env.go @@ -2,17 +2,16 @@ package scalingo import ( "context" - "encoding/json" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) type VariablesService interface { VariablesList(ctx context.Context, app string) (Variables, error) VariablesListWithoutAlias(ctx context.Context, app string) (Variables, error) - VariableSet(ctx context.Context, app string, name string, value string) (*Variable, int, error) - VariableMultipleSet(ctx context.Context, app string, variables Variables) (Variables, int, error) + VariableSet(ctx context.Context, app string, name string, value string) (*Variable, error) + VariableMultipleSet(ctx context.Context, app string, variables Variables) (Variables, error) VariableUnset(ctx context.Context, app string, id string) error } @@ -60,8 +59,9 @@ func (c *Client) variableList(ctx context.Context, app string, aliases bool) (Va return variablesRes.Variables, nil } -func (c *Client) VariableSet(ctx context.Context, app string, name string, value string) (*Variable, int, error) { - req := &http.APIRequest{ +func (c *Client) VariableSet(ctx context.Context, app string, name string, value string) (*Variable, error) { + var variablesSetRes VariableSetParams + err := c.ScalingoAPI().DoRequest(ctx, &http.APIRequest{ Method: "POST", Endpoint: "/apps/" + app + "/variables", Params: map[string]any{ @@ -71,23 +71,16 @@ func (c *Client) VariableSet(ctx context.Context, app string, name string, value }, }, Expected: http.Statuses{200, 201}, - } - res, err := c.ScalingoAPI().Do(ctx, req) - if err != nil { - return nil, 0, errors.Wrap(ctx, err, "set app variable") - } - defer res.Body.Close() - - var params VariableSetParams - err = json.NewDecoder(res.Body).Decode(¶ms) + }, &variablesSetRes) if err != nil { - return nil, 0, errors.Wrap(ctx, err, "decode app variable response") + return nil, errors.Wrap(ctx, err, "set app variable") } - return params.Variable, res.StatusCode, nil + return variablesSetRes.Variable, nil } -func (c *Client) VariableMultipleSet(ctx context.Context, app string, variables Variables) (Variables, int, error) { +func (c *Client) VariableMultipleSet(ctx context.Context, app string, variables Variables) (Variables, error) { + var variabelsRes VariablesRes req := &http.APIRequest{ Method: "PUT", Endpoint: "/apps/" + app + "/variables", @@ -96,19 +89,12 @@ func (c *Client) VariableMultipleSet(ctx context.Context, app string, variables }, Expected: http.Statuses{200, 201}, } - res, err := c.ScalingoAPI().Do(ctx, req) - if err != nil { - return nil, 0, errors.Wrap(ctx, err, "set multiple app variables") - } - defer res.Body.Close() - - var params VariablesRes - err = json.NewDecoder(res.Body).Decode(¶ms) + err := c.ScalingoAPI().DoRequest(ctx, req, &variabelsRes) if err != nil { - return nil, 0, errors.Wrap(ctx, err, "decode app variables response") + return nil, errors.Wrap(ctx, err, "set multiple app variables") } - return params.Variables, res.StatusCode, nil + return variabelsRes.Variables, nil } func (c *Client) VariableUnset(ctx context.Context, app string, id string) error { diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/events.go b/vendor/github.com/Scalingo/go-scalingo/v11/events.go similarity index 86% rename from vendor/github.com/Scalingo/go-scalingo/v10/events.go rename to vendor/github.com/Scalingo/go-scalingo/v11/events.go index 8e58505c4..a202d0599 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/events.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/events.go @@ -5,9 +5,8 @@ package scalingo import ( "context" - "encoding/json" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" "github.com/Scalingo/go-utils/pagination" ) @@ -48,16 +47,10 @@ func (c *Client) UserEventsList(ctx context.Context, paginationReq pagination.Re } var eventsRes EventsRes - res, err := c.ScalingoAPI().Do(ctx, req) + err := c.ScalingoAPI().DoRequest(ctx, req, &eventsRes) if err != nil { return nil, pagination.Meta{}, errors.Wrap(ctx, err, "list user events") } - defer res.Body.Close() - - err = json.NewDecoder(res.Body).Decode(&eventsRes) - if err != nil { - return nil, pagination.Meta{}, errors.Wrap(ctx, err, "decode user events response") - } var events Events for _, ev := range eventsRes.Events { diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/events_account.go b/vendor/github.com/Scalingo/go-scalingo/v11/events_account.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/events_account.go rename to vendor/github.com/Scalingo/go-scalingo/v11/events_account.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/events_addon.go b/vendor/github.com/Scalingo/go-scalingo/v11/events_addon.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/events_addon.go rename to vendor/github.com/Scalingo/go-scalingo/v11/events_addon.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/events_alert.go b/vendor/github.com/Scalingo/go-scalingo/v11/events_alert.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/events_alert.go rename to vendor/github.com/Scalingo/go-scalingo/v11/events_alert.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/events_app.go b/vendor/github.com/Scalingo/go-scalingo/v11/events_app.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/events_app.go rename to vendor/github.com/Scalingo/go-scalingo/v11/events_app.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/events_billing.go b/vendor/github.com/Scalingo/go-scalingo/v11/events_billing.go similarity index 96% rename from vendor/github.com/Scalingo/go-scalingo/v10/events_billing.go rename to vendor/github.com/Scalingo/go-scalingo/v11/events_billing.go index 2b5190e19..67d544f32 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/events_billing.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/events_billing.go @@ -3,7 +3,7 @@ package scalingo import ( "fmt" - "github.com/Scalingo/go-scalingo/v10/billing" + "github.com/Scalingo/go-scalingo/v11/billing" ) type EventAddCreditType struct { diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/events_boilerplate.go b/vendor/github.com/Scalingo/go-scalingo/v11/events_boilerplate.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/events_boilerplate.go rename to vendor/github.com/Scalingo/go-scalingo/v11/events_boilerplate.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/events_specialize.go b/vendor/github.com/Scalingo/go-scalingo/v11/events_specialize.go similarity index 99% rename from vendor/github.com/Scalingo/go-scalingo/v10/events_specialize.go rename to vendor/github.com/Scalingo/go-scalingo/v11/events_specialize.go index f783a2c52..12fc834ed 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/events_specialize.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/events_specialize.go @@ -5,7 +5,7 @@ package scalingo import ( "encoding/json" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" ) func (pev *Event) Specialize() DetailedEvent { diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/events_structs.go b/vendor/github.com/Scalingo/go-scalingo/v11/events_structs.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/events_structs.go rename to vendor/github.com/Scalingo/go-scalingo/v11/events_structs.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/events_token.go b/vendor/github.com/Scalingo/go-scalingo/v11/events_token.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/events_token.go rename to vendor/github.com/Scalingo/go-scalingo/v11/events_token.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/events_types.go b/vendor/github.com/Scalingo/go-scalingo/v11/events_types.go similarity index 96% rename from vendor/github.com/Scalingo/go-scalingo/v10/events_types.go rename to vendor/github.com/Scalingo/go-scalingo/v11/events_types.go index ff639c89d..74098b783 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/events_types.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/events_types.go @@ -3,7 +3,7 @@ package scalingo import ( "context" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/events_user.go b/vendor/github.com/Scalingo/go-scalingo/v11/events_user.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/events_user.go rename to vendor/github.com/Scalingo/go-scalingo/v11/events_user.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/firewall_rules.go b/vendor/github.com/Scalingo/go-scalingo/v11/firewall_rules.go similarity index 98% rename from vendor/github.com/Scalingo/go-scalingo/v10/firewall_rules.go rename to vendor/github.com/Scalingo/go-scalingo/v11/firewall_rules.go index 414102610..d154eaf7c 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/firewall_rules.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/firewall_rules.go @@ -3,7 +3,7 @@ package scalingo import ( "context" - httpclient "github.com/Scalingo/go-scalingo/v10/http" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/gomock_subresourceservice.go b/vendor/github.com/Scalingo/go-scalingo/v11/gomock_subresourceservice.go similarity index 99% rename from vendor/github.com/Scalingo/go-scalingo/v10/gomock_subresourceservice.go rename to vendor/github.com/Scalingo/go-scalingo/v11/gomock_subresourceservice.go index 6486cd0e5..74e3fc79f 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/gomock_subresourceservice.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/gomock_subresourceservice.go @@ -5,8 +5,9 @@ package scalingo import ( - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "go.uber.org/mock/gomock" ) // MockSubresourceService is a mock of SubresourceService interface diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/http/addon_token_generator.go b/vendor/github.com/Scalingo/go-scalingo/v11/http/addon_token_generator.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/http/addon_token_generator.go rename to vendor/github.com/Scalingo/go-scalingo/v11/http/addon_token_generator.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/http/api_request.go b/vendor/github.com/Scalingo/go-scalingo/v11/http/api_request.go similarity index 91% rename from vendor/github.com/Scalingo/go-scalingo/v10/http/api_request.go rename to vendor/github.com/Scalingo/go-scalingo/v11/http/api_request.go index bea3a190b..63a842729 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/http/api_request.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/http/api_request.go @@ -12,8 +12,8 @@ import ( "slices" "time" - "github.com/Scalingo/go-scalingo/v10/debug" - pkgio "github.com/Scalingo/go-scalingo/v10/io" + "github.com/Scalingo/go-scalingo/v11/debug" + pkgio "github.com/Scalingo/go-scalingo/v11/io" "github.com/Scalingo/go-utils/errors/v3" ) @@ -37,7 +37,7 @@ func (c *client) fillDefaultValues(ctx context.Context, req *APIRequest) error { if req.Method == "" { req.Method = "GET" } - if req.Expected == nil || len(req.Expected) == 0 { + if len(req.Expected) == 0 { req.Expected = Statuses{200} } if req.Params == nil { @@ -63,6 +63,7 @@ func (statuses Statuses) Contains(status int) bool { } // Execute an API request and return its response/error +// This should mostly be called from the http/client.DoRequest function. Don't forget to close the body of the returned http.Response. func (c *client) Do(ctx context.Context, req *APIRequest) (*http.Response, error) { err := c.fillDefaultValues(ctx, req) if err != nil { @@ -143,11 +144,11 @@ func (c *client) doRequest(req *http.Request) (*http.Response, error) { return c.HTTPClient().Do(req) } -func parseJSON(ctx context.Context, res *http.Response, data any) error { +func parseJSON(ctx context.Context, res *http.Response, data any) (string, error) { body, err := io.ReadAll(res.Body) if err != nil { reqErr := fmt.Sprintf("%v %v", res.Request.Method, res.Request.URL) - return errors.Errorf(ctx, "read body of request %v: %v", reqErr, err) + return "", errors.Errorf(ctx, "read body of request %v: %v", reqErr, err) } debug.Println(string(body)) @@ -155,10 +156,10 @@ func parseJSON(ctx context.Context, res *http.Response, data any) error { err = json.Unmarshal(body, data) if err != nil { reqErr := fmt.Sprintf("%v %v", res.Request.Method, res.Request.URL) - return errors.Errorf(ctx, "parse JSON of request %v: %v", reqErr, err) + return "", errors.Errorf(ctx, "parse JSON of request %v: %v", reqErr, err) } - return nil + return string(body), nil } func (req *APIRequest) buildQueryFromParams(ctx context.Context) (url.Values, error) { diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/http/api_token_generator.go b/vendor/github.com/Scalingo/go-scalingo/v11/http/api_token_generator.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/http/api_token_generator.go rename to vendor/github.com/Scalingo/go-scalingo/v11/http/api_token_generator.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/http/client.go b/vendor/github.com/Scalingo/go-scalingo/v11/http/client.go similarity index 95% rename from vendor/github.com/Scalingo/go-scalingo/v10/http/client.go rename to vendor/github.com/Scalingo/go-scalingo/v11/http/client.go index 9134cdc4d..44f8a41ae 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/http/client.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/http/client.go @@ -27,7 +27,7 @@ type Client interface { SubresourceUpdate(ctx context.Context, resource, resourceID, subresource, id string, payload, data any) error SubresourceDelete(ctx context.Context, resource, resourceID, subresource, id string) error DoRequest(ctx context.Context, req *APIRequest, data any) error - Do(context.Context, *APIRequest) (*http.Response, error) + Do(ctx context.Context, req *APIRequest) (*http.Response, error) TokenGenerator() TokenGenerator IsAuthenticatedClient() bool @@ -102,7 +102,7 @@ func (c *client) ResourceAdd(ctx context.Context, resource string, payload, data return c.DoRequest(ctx, &APIRequest{ Method: "POST", Endpoint: "/" + resource, - Expected: Statuses{201}, + Expected: Statuses{http.StatusCreated}, Params: payload, }, data) } @@ -119,7 +119,7 @@ func (c *client) ResourceDelete(ctx context.Context, resource, resourceID string return c.DoRequest(ctx, &APIRequest{ Method: "DELETE", Endpoint: "/" + resource + "/" + resourceID, - Expected: Statuses{204}, + Expected: Statuses{http.StatusNoContent}, }, nil) } @@ -143,7 +143,7 @@ func (c *client) SubresourceAdd(ctx context.Context, resource, resourceID, subre return c.DoRequest(ctx, &APIRequest{ Method: "POST", Endpoint: "/" + resource + "/" + resourceID + "/" + subresource, - Expected: Statuses{201}, + Expected: Statuses{http.StatusCreated}, Params: payload, }, data) } @@ -152,7 +152,7 @@ func (c *client) SubresourceDelete(ctx context.Context, resource, resourceID, su return c.DoRequest(ctx, &APIRequest{ Method: "DELETE", Endpoint: "/" + resource + "/" + resourceID + "/" + subresource + "/" + id, - Expected: Statuses{204}, + Expected: Statuses{http.StatusNoContent}, }, nil) } @@ -179,7 +179,7 @@ func (c *client) DoRequest(ctx context.Context, req *APIRequest, data any) error return nil } - err = parseJSON(ctx, res, data) + _, err = parseJSON(ctx, res, data) if err != nil { return errors.Wrap(ctx, err, "parse JSON of subresource response") } diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/http/errors.go b/vendor/github.com/Scalingo/go-scalingo/v11/http/errors.go similarity index 90% rename from vendor/github.com/Scalingo/go-scalingo/v10/http/errors.go rename to vendor/github.com/Scalingo/go-scalingo/v11/http/errors.go index dd0ac2731..2158a0cef 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/http/errors.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/http/errors.go @@ -7,7 +7,7 @@ import ( "net/http" "strings" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) @@ -125,56 +125,59 @@ func NewRequestFailedError(ctx context.Context, res *http.Response, req *APIRequ switch res.StatusCode { case http.StatusBadRequest: // 400 var badRequestError BadRequestError - err := parseJSON(ctx, res, &badRequestError) + _, err := parseJSON(ctx, res, &badRequestError) if err != nil { return err } return &RequestFailedError{Code: res.StatusCode, APIError: badRequestError, Req: req} case http.StatusUnauthorized: // 401 var apiErr APIError - err := parseJSON(ctx, res, &apiErr) + _, err := parseJSON(ctx, res, &apiErr) if err != nil { return err } return &RequestFailedError{Code: res.StatusCode, APIError: errors.New(ctx, "unauthorized - you are not authorized to do this operation"), Req: req, Message: apiErr.Error} case http.StatusPaymentRequired: // 402 var paymentRequiredErr PaymentRequiredError - err := parseJSON(ctx, res, &paymentRequiredErr) + _, err := parseJSON(ctx, res, &paymentRequiredErr) if err != nil { return err } return &RequestFailedError{Code: res.StatusCode, APIError: paymentRequiredErr, Req: req} case http.StatusForbidden: // 403 var forbiddenError ForbiddenError - err := parseJSON(ctx, res, &forbiddenError) + _, err := parseJSON(ctx, res, &forbiddenError) if err != nil { return err } return &RequestFailedError{Code: res.StatusCode, APIError: forbiddenError, Req: req} case http.StatusNotFound: // 404 var notFoundErr NotFoundError - err := parseJSON(ctx, res, ¬FoundErr) + _, err := parseJSON(ctx, res, ¬FoundErr) if err != nil { return err } return &RequestFailedError{Code: res.StatusCode, APIError: notFoundErr, Req: req} case http.StatusConflict: // 409 var conflictErr ConflictError - err := parseJSON(ctx, res, &conflictErr) + _, err := parseJSON(ctx, res, &conflictErr) if err != nil { return err } return &RequestFailedError{Code: res.StatusCode, APIError: conflictErr, Req: req} case http.StatusUnprocessableEntity: // 422 var unprocessableError UnprocessableEntity - err := parseJSON(ctx, res, &unprocessableError) + body, err := parseJSON(ctx, res, &unprocessableError) if err != nil { return err } + if len(unprocessableError.Errors) == 0 { + return errors.Newf(ctx, "invalid body when returning a 422 Unprocessable Content: %v", body) + } return &RequestFailedError{Code: res.StatusCode, APIError: unprocessableError, Req: req} case http.StatusTooManyRequests: // 429 var tooManyRequestsError TooManyRequestsError - err := parseJSON(ctx, res, &tooManyRequestsError) + _, err := parseJSON(ctx, res, &tooManyRequestsError) if err != nil { return err } diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/http/httpmock/client_mock.go b/vendor/github.com/Scalingo/go-scalingo/v11/http/httpmock/client_mock.go similarity index 54% rename from vendor/github.com/Scalingo/go-scalingo/v10/http/httpmock/client_mock.go rename to vendor/github.com/Scalingo/go-scalingo/v11/http/httpmock/client_mock.go index ecbc361fa..68fc9ff5f 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/http/httpmock/client_mock.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/http/httpmock/client_mock.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/Scalingo/go-scalingo/v10/http (interfaces: Client) +// Source: github.com/Scalingo/go-scalingo/v11/http (interfaces: Client) +// +// Generated by this command: +// +// mockgen --build_flags=--mod=mod -destination /home/etienne/Documents/Scalingo/golang/src/github.com/Scalingo/go-scalingo/http/httpmock/client_mock.go -package httpmock github.com/Scalingo/go-scalingo/v11/http Client +// // Package httpmock is a generated GoMock package. package httpmock @@ -9,14 +14,15 @@ import ( http0 "net/http" reflect "reflect" - http "github.com/Scalingo/go-scalingo/v10/http" - gomock "github.com/golang/mock/gomock" + http "github.com/Scalingo/go-scalingo/v11/http" + gomock "go.uber.org/mock/gomock" ) // MockClient is a mock of Client interface. type MockClient struct { ctrl *gomock.Controller recorder *MockClientMockRecorder + isgomock struct{} } // MockClientMockRecorder is the mock recorder for MockClient. @@ -51,32 +57,32 @@ func (mr *MockClientMockRecorder) BaseURL() *gomock.Call { } // Do mocks base method. -func (m *MockClient) Do(arg0 context.Context, arg1 *http.APIRequest) (*http0.Response, error) { +func (m *MockClient) Do(ctx context.Context, req *http.APIRequest) (*http0.Response, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Do", arg0, arg1) + ret := m.ctrl.Call(m, "Do", ctx, req) ret0, _ := ret[0].(*http0.Response) ret1, _ := ret[1].(error) return ret0, ret1 } // Do indicates an expected call of Do. -func (mr *MockClientMockRecorder) Do(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) Do(ctx, req any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Do", reflect.TypeOf((*MockClient)(nil).Do), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Do", reflect.TypeOf((*MockClient)(nil).Do), ctx, req) } // DoRequest mocks base method. -func (m *MockClient) DoRequest(arg0 context.Context, arg1 *http.APIRequest, arg2 interface{}) error { +func (m *MockClient) DoRequest(ctx context.Context, req *http.APIRequest, data any) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DoRequest", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "DoRequest", ctx, req, data) ret0, _ := ret[0].(error) return ret0 } // DoRequest indicates an expected call of DoRequest. -func (mr *MockClientMockRecorder) DoRequest(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) DoRequest(ctx, req, data any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DoRequest", reflect.TypeOf((*MockClient)(nil).DoRequest), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DoRequest", reflect.TypeOf((*MockClient)(nil).DoRequest), ctx, req, data) } // HTTPClient mocks base method. @@ -108,143 +114,143 @@ func (mr *MockClientMockRecorder) IsAuthenticatedClient() *gomock.Call { } // ResourceAdd mocks base method. -func (m *MockClient) ResourceAdd(arg0 context.Context, arg1 string, arg2, arg3 interface{}) error { +func (m *MockClient) ResourceAdd(ctx context.Context, resource string, payload, data any) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ResourceAdd", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "ResourceAdd", ctx, resource, payload, data) ret0, _ := ret[0].(error) return ret0 } // ResourceAdd indicates an expected call of ResourceAdd. -func (mr *MockClientMockRecorder) ResourceAdd(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) ResourceAdd(ctx, resource, payload, data any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResourceAdd", reflect.TypeOf((*MockClient)(nil).ResourceAdd), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResourceAdd", reflect.TypeOf((*MockClient)(nil).ResourceAdd), ctx, resource, payload, data) } // ResourceDelete mocks base method. -func (m *MockClient) ResourceDelete(arg0 context.Context, arg1, arg2 string) error { +func (m *MockClient) ResourceDelete(ctx context.Context, resource, resourceID string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ResourceDelete", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "ResourceDelete", ctx, resource, resourceID) ret0, _ := ret[0].(error) return ret0 } // ResourceDelete indicates an expected call of ResourceDelete. -func (mr *MockClientMockRecorder) ResourceDelete(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) ResourceDelete(ctx, resource, resourceID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResourceDelete", reflect.TypeOf((*MockClient)(nil).ResourceDelete), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResourceDelete", reflect.TypeOf((*MockClient)(nil).ResourceDelete), ctx, resource, resourceID) } // ResourceGet mocks base method. -func (m *MockClient) ResourceGet(arg0 context.Context, arg1, arg2 string, arg3, arg4 interface{}) error { +func (m *MockClient) ResourceGet(ctx context.Context, resource, resourceID string, payload, data any) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ResourceGet", arg0, arg1, arg2, arg3, arg4) + ret := m.ctrl.Call(m, "ResourceGet", ctx, resource, resourceID, payload, data) ret0, _ := ret[0].(error) return ret0 } // ResourceGet indicates an expected call of ResourceGet. -func (mr *MockClientMockRecorder) ResourceGet(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) ResourceGet(ctx, resource, resourceID, payload, data any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResourceGet", reflect.TypeOf((*MockClient)(nil).ResourceGet), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResourceGet", reflect.TypeOf((*MockClient)(nil).ResourceGet), ctx, resource, resourceID, payload, data) } // ResourceList mocks base method. -func (m *MockClient) ResourceList(arg0 context.Context, arg1 string, arg2, arg3 interface{}) error { +func (m *MockClient) ResourceList(ctx context.Context, resource string, payload, data any) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ResourceList", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "ResourceList", ctx, resource, payload, data) ret0, _ := ret[0].(error) return ret0 } // ResourceList indicates an expected call of ResourceList. -func (mr *MockClientMockRecorder) ResourceList(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) ResourceList(ctx, resource, payload, data any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResourceList", reflect.TypeOf((*MockClient)(nil).ResourceList), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResourceList", reflect.TypeOf((*MockClient)(nil).ResourceList), ctx, resource, payload, data) } // ResourceUpdate mocks base method. -func (m *MockClient) ResourceUpdate(arg0 context.Context, arg1, arg2 string, arg3, arg4 interface{}) error { +func (m *MockClient) ResourceUpdate(ctx context.Context, resource, resourceID string, payload, data any) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ResourceUpdate", arg0, arg1, arg2, arg3, arg4) + ret := m.ctrl.Call(m, "ResourceUpdate", ctx, resource, resourceID, payload, data) ret0, _ := ret[0].(error) return ret0 } // ResourceUpdate indicates an expected call of ResourceUpdate. -func (mr *MockClientMockRecorder) ResourceUpdate(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) ResourceUpdate(ctx, resource, resourceID, payload, data any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResourceUpdate", reflect.TypeOf((*MockClient)(nil).ResourceUpdate), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResourceUpdate", reflect.TypeOf((*MockClient)(nil).ResourceUpdate), ctx, resource, resourceID, payload, data) } // SubresourceAdd mocks base method. -func (m *MockClient) SubresourceAdd(arg0 context.Context, arg1, arg2, arg3 string, arg4, arg5 interface{}) error { +func (m *MockClient) SubresourceAdd(ctx context.Context, resource, resourceID, subresource string, payload, data any) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SubresourceAdd", arg0, arg1, arg2, arg3, arg4, arg5) + ret := m.ctrl.Call(m, "SubresourceAdd", ctx, resource, resourceID, subresource, payload, data) ret0, _ := ret[0].(error) return ret0 } // SubresourceAdd indicates an expected call of SubresourceAdd. -func (mr *MockClientMockRecorder) SubresourceAdd(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) SubresourceAdd(ctx, resource, resourceID, subresource, payload, data any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubresourceAdd", reflect.TypeOf((*MockClient)(nil).SubresourceAdd), arg0, arg1, arg2, arg3, arg4, arg5) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubresourceAdd", reflect.TypeOf((*MockClient)(nil).SubresourceAdd), ctx, resource, resourceID, subresource, payload, data) } // SubresourceDelete mocks base method. -func (m *MockClient) SubresourceDelete(arg0 context.Context, arg1, arg2, arg3, arg4 string) error { +func (m *MockClient) SubresourceDelete(ctx context.Context, resource, resourceID, subresource, id string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SubresourceDelete", arg0, arg1, arg2, arg3, arg4) + ret := m.ctrl.Call(m, "SubresourceDelete", ctx, resource, resourceID, subresource, id) ret0, _ := ret[0].(error) return ret0 } // SubresourceDelete indicates an expected call of SubresourceDelete. -func (mr *MockClientMockRecorder) SubresourceDelete(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) SubresourceDelete(ctx, resource, resourceID, subresource, id any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubresourceDelete", reflect.TypeOf((*MockClient)(nil).SubresourceDelete), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubresourceDelete", reflect.TypeOf((*MockClient)(nil).SubresourceDelete), ctx, resource, resourceID, subresource, id) } // SubresourceGet mocks base method. -func (m *MockClient) SubresourceGet(arg0 context.Context, arg1, arg2, arg3, arg4 string, arg5, arg6 interface{}) error { +func (m *MockClient) SubresourceGet(ctx context.Context, resource, resourceID, subresource, id string, payload, data any) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SubresourceGet", arg0, arg1, arg2, arg3, arg4, arg5, arg6) + ret := m.ctrl.Call(m, "SubresourceGet", ctx, resource, resourceID, subresource, id, payload, data) ret0, _ := ret[0].(error) return ret0 } // SubresourceGet indicates an expected call of SubresourceGet. -func (mr *MockClientMockRecorder) SubresourceGet(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) SubresourceGet(ctx, resource, resourceID, subresource, id, payload, data any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubresourceGet", reflect.TypeOf((*MockClient)(nil).SubresourceGet), arg0, arg1, arg2, arg3, arg4, arg5, arg6) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubresourceGet", reflect.TypeOf((*MockClient)(nil).SubresourceGet), ctx, resource, resourceID, subresource, id, payload, data) } // SubresourceList mocks base method. -func (m *MockClient) SubresourceList(arg0 context.Context, arg1, arg2, arg3 string, arg4, arg5 interface{}) error { +func (m *MockClient) SubresourceList(ctx context.Context, resource, resourceID, subresource string, payload, data any) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SubresourceList", arg0, arg1, arg2, arg3, arg4, arg5) + ret := m.ctrl.Call(m, "SubresourceList", ctx, resource, resourceID, subresource, payload, data) ret0, _ := ret[0].(error) return ret0 } // SubresourceList indicates an expected call of SubresourceList. -func (mr *MockClientMockRecorder) SubresourceList(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) SubresourceList(ctx, resource, resourceID, subresource, payload, data any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubresourceList", reflect.TypeOf((*MockClient)(nil).SubresourceList), arg0, arg1, arg2, arg3, arg4, arg5) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubresourceList", reflect.TypeOf((*MockClient)(nil).SubresourceList), ctx, resource, resourceID, subresource, payload, data) } // SubresourceUpdate mocks base method. -func (m *MockClient) SubresourceUpdate(arg0 context.Context, arg1, arg2, arg3, arg4 string, arg5, arg6 interface{}) error { +func (m *MockClient) SubresourceUpdate(ctx context.Context, resource, resourceID, subresource, id string, payload, data any) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SubresourceUpdate", arg0, arg1, arg2, arg3, arg4, arg5, arg6) + ret := m.ctrl.Call(m, "SubresourceUpdate", ctx, resource, resourceID, subresource, id, payload, data) ret0, _ := ret[0].(error) return ret0 } // SubresourceUpdate indicates an expected call of SubresourceUpdate. -func (mr *MockClientMockRecorder) SubresourceUpdate(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface{}) *gomock.Call { +func (mr *MockClientMockRecorder) SubresourceUpdate(ctx, resource, resourceID, subresource, id, payload, data any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubresourceUpdate", reflect.TypeOf((*MockClient)(nil).SubresourceUpdate), arg0, arg1, arg2, arg3, arg4, arg5, arg6) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubresourceUpdate", reflect.TypeOf((*MockClient)(nil).SubresourceUpdate), ctx, resource, resourceID, subresource, id, payload, data) } // TokenGenerator mocks base method. diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/http/tokens.go b/vendor/github.com/Scalingo/go-scalingo/v11/http/tokens.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/http/tokens.go rename to vendor/github.com/Scalingo/go-scalingo/v11/http/tokens.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/invoices.go b/vendor/github.com/Scalingo/go-scalingo/v11/invoices.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/invoices.go rename to vendor/github.com/Scalingo/go-scalingo/v11/invoices.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/io/indent.go b/vendor/github.com/Scalingo/go-scalingo/v11/io/indent.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/io/indent.go rename to vendor/github.com/Scalingo/go-scalingo/v11/io/indent.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/io/status.go b/vendor/github.com/Scalingo/go-scalingo/v11/io/status.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/io/status.go rename to vendor/github.com/Scalingo/go-scalingo/v11/io/status.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/keys.go b/vendor/github.com/Scalingo/go-scalingo/v11/keys.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/keys.go rename to vendor/github.com/Scalingo/go-scalingo/v11/keys.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/log_drains.go b/vendor/github.com/Scalingo/go-scalingo/v11/log_drains.go similarity index 98% rename from vendor/github.com/Scalingo/go-scalingo/v10/log_drains.go rename to vendor/github.com/Scalingo/go-scalingo/v11/log_drains.go index d30c0132d..29fcb223d 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/log_drains.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/log_drains.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - httpclient "github.com/Scalingo/go-scalingo/v10/http" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/logs-archives.go b/vendor/github.com/Scalingo/go-scalingo/v11/logs-archives.go similarity index 65% rename from vendor/github.com/Scalingo/go-scalingo/v10/logs-archives.go rename to vendor/github.com/Scalingo/go-scalingo/v11/logs-archives.go index 0d967ad1b..e2a7e6c27 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/logs-archives.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/logs-archives.go @@ -2,11 +2,9 @@ package scalingo import ( "context" - "encoding/json" - "io" "strconv" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) @@ -31,6 +29,7 @@ type LogsArchivesResponse struct { } func (c *Client) LogsArchivesByCursor(ctx context.Context, app string, cursor string) (*LogsArchivesResponse, error) { + var logsRes LogsArchivesResponse req := &http.APIRequest{ Endpoint: "/apps/" + app + "/logs_archives", Params: map[string]string{ @@ -38,22 +37,10 @@ func (c *Client) LogsArchivesByCursor(ctx context.Context, app string, cursor st }, } - res, err := c.ScalingoAPI().Do(ctx, req) + err := c.ScalingoAPI().DoRequest(ctx, req, &logsRes) if err != nil { return nil, errors.Wrap(ctx, err, "list logs archives by cursor") } - defer res.Body.Close() - - body, err := io.ReadAll(res.Body) - if err != nil { - return nil, errors.Wrap(ctx, err, "read logs archives response body") - } - - var logsRes = LogsArchivesResponse{} - err = json.Unmarshal(body, &logsRes) - if err != nil { - return nil, errors.Wrap(ctx, err, "decode logs archives response") - } return &logsRes, nil } @@ -70,22 +57,11 @@ func (c *Client) LogsArchives(ctx context.Context, app string, page int) (*LogsA }, } - res, err := c.ScalingoAPI().Do(ctx, req) + var logsRes LogsArchivesResponse + err := c.ScalingoAPI().DoRequest(ctx, req, &logsRes) if err != nil { return nil, errors.Wrap(ctx, err, "list logs archives") } - defer res.Body.Close() - - body, err := io.ReadAll(res.Body) - if err != nil { - return nil, errors.Wrap(ctx, err, "read logs archives response body") - } - - var logsRes = LogsArchivesResponse{} - err = json.Unmarshal(body, &logsRes) - if err != nil { - return nil, errors.Wrap(ctx, err, "decode logs archives response") - } return &logsRes, nil } diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/logs.go b/vendor/github.com/Scalingo/go-scalingo/v11/logs.go similarity index 75% rename from vendor/github.com/Scalingo/go-scalingo/v10/logs.go rename to vendor/github.com/Scalingo/go-scalingo/v11/logs.go index 04f07e3f0..54de0c605 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/logs.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/logs.go @@ -2,10 +2,11 @@ package scalingo import ( "context" - "net/http" + stderrors "errors" + "io" "net/url" - httpclient "github.com/Scalingo/go-scalingo/v10/http" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) @@ -13,7 +14,7 @@ type LogsService interface { LogsURL(ctx context.Context, app string) (*LogsURLRes, error) // Logs returns the raw http.Response from the request to the API. This response body contains the requested log lines in raw text. // It has been decided to let the user of this function decides how to best read the body (type is io.ReadCloser) depending on their context. - Logs(ctx context.Context, logsURL string, n int, filter string) (*http.Response, error) + Logs(ctx context.Context, logsURL string, n int, filter string) (io.ReadCloser, error) } var _ LogsService = (*Client)(nil) @@ -33,7 +34,9 @@ func (c *Client) LogsURL(ctx context.Context, app string) (*LogsURLRes, error) { return &logsURLRes, nil } -func (c *Client) Logs(ctx context.Context, logsURL string, n int, filter string) (*http.Response, error) { +var ErrNoLogs = stderrors.New("application didn't logged anything yet") + +func (c *Client) Logs(ctx context.Context, logsURL string, n int, filter string) (io.ReadCloser, error) { u, err := url.Parse(logsURL) if err != nil { return nil, errors.Wrap(ctx, err, "parse logs URL") @@ -50,5 +53,14 @@ func (c *Client) Logs(ctx context.Context, logsURL string, n int, filter string) "filter": filter, }, } - return c.ScalingoAPI().Do(ctx, req) + res, err := c.ScalingoAPI().Do(ctx, req) + if err != nil { + return nil, errors.Wrap(ctx, err, "request Scalingo API to get the application logs") + } + + if res.StatusCode == 404 || res.StatusCode == 204 { + return nil, ErrNoLogs + } + + return res.Body, nil } diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/maintenance.go b/vendor/github.com/Scalingo/go-scalingo/v11/maintenance.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/maintenance.go rename to vendor/github.com/Scalingo/go-scalingo/v11/maintenance.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/metrics.go b/vendor/github.com/Scalingo/go-scalingo/v11/metrics.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/metrics.go rename to vendor/github.com/Scalingo/go-scalingo/v11/metrics.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/mocks.json b/vendor/github.com/Scalingo/go-scalingo/v11/mocks.json similarity index 98% rename from vendor/github.com/Scalingo/go-scalingo/v10/mocks.json rename to vendor/github.com/Scalingo/go-scalingo/v11/mocks.json index 4f931c0f7..c0a2fe7e0 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/mocks.json +++ b/vendor/github.com/Scalingo/go-scalingo/v11/mocks.json @@ -1,6 +1,6 @@ { "base_directory": "github.com/Scalingo/go-scalingo", - "base_package": "github.com/Scalingo/go-scalingo/v10", + "base_package": "github.com/Scalingo/go-scalingo/v11", "mocks": [ { "interface": "Client", diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/mocks_sig.json b/vendor/github.com/Scalingo/go-scalingo/v11/mocks_sig.json similarity index 87% rename from vendor/github.com/Scalingo/go-scalingo/v10/mocks_sig.json rename to vendor/github.com/Scalingo/go-scalingo/v11/mocks_sig.json index 0df1d08f2..58315b9ca 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/mocks_sig.json +++ b/vendor/github.com/Scalingo/go-scalingo/v11/mocks_sig.json @@ -3,7 +3,7 @@ "github.com/Scalingo/go-scalingo.AddonProvidersService": "f0 56 1c c9 ae 9b 6e a5 2f 98 fa 72 1f a2 f0 e6 a7 23 b4 4c", "github.com/Scalingo/go-scalingo.AddonsService": "e5 fd 9a 36 39 fc 08 7d 37 ef 0d a9 5c a5 ba dc 53 db e8 39", "github.com/Scalingo/go-scalingo.AlertsService": "31 44 7d d3 3f 5b 0b 61 26 03 79 65 a2 16 77 a1 66 66 e8 05", - "github.com/Scalingo/go-scalingo.AppsService": "bd ac 01 ef a1 ae 45 1e b8 66 b7 d1 ec e3 71 31 c2 62 01 5f", + "github.com/Scalingo/go-scalingo.AppsService": "22 f1 ba 14 dd 25 00 06 c4 2e 51 66 16 a1 15 3c ed 86 8b 93", "github.com/Scalingo/go-scalingo.AutoscalersService": "9f cf 1b 7a dc 9d e3 d3 62 89 41 0f d4 30 83 28 7b 40 f1 72", "github.com/Scalingo/go-scalingo.BackupsService": "66 59 74 49 68 65 69 e4 b0 97 8e a2 45 e6 ff fc 71 85 06 16", "github.com/Scalingo/go-scalingo.CollaboratorsService": "c9 3a 93 de 00 2d e8 87 9c cc bd 3f f0 0e a1 48 78 a4 d7 3a", @@ -11,13 +11,13 @@ "github.com/Scalingo/go-scalingo.ContainersService": "ef 14 ae 81 c9 b4 6a 13 48 e8 bf 44 7d b5 b2 a6 4d e5 02 11", "github.com/Scalingo/go-scalingo.CronTasksService": "9b d9 a3 ca 9f 9a f7 73 cb b1 aa 80 df 90 21 ff 14 92 b4 4d", "github.com/Scalingo/go-scalingo.DatabasesService": "7c 84 0b 87 60 d6 b9 c7 3a a9 53 d2 3a 1c b4 e4 46 f1 83 28", - "github.com/Scalingo/go-scalingo.DeploymentsService": "05 ef e7 51 7d 05 3c 4e 6d 5e 66 5c 36 ba ed 14 33 a8 bc 7a", + "github.com/Scalingo/go-scalingo.DeploymentsService": "e1 c5 95 e5 0e 4d db 1e ec 9a 83 d8 e5 41 cc 24 ce f6 ea ba", "github.com/Scalingo/go-scalingo.DomainsService": "b5 19 0f 10 5b f2 48 74 c6 c2 7b 27 7d 3b b8 ff 10 80 b3 6f", "github.com/Scalingo/go-scalingo.EventsService": "13 7a 12 83 bf 3f 84 49 dc db 64 c3 d5 e8 4a c0 08 8c 78 f6", "github.com/Scalingo/go-scalingo.KeysService": "b9 5f 5d 8e 88 9d db 82 d6 69 e5 bd 94 6c 7e 08 14 69 23 48", "github.com/Scalingo/go-scalingo.LogDrainsService": "d4 05 d0 5e a7 7f b7 3e 58 19 07 8d 25 c5 af ca dc d3 6e d9", "github.com/Scalingo/go-scalingo.LogsArchivesService": "35 b6 c3 7b 41 1a 47 5c 3c df ab a6 d6 93 1e 6e b1 b1 f9 11", - "github.com/Scalingo/go-scalingo.LogsService": "03 7f 3f 3c 0d ac 3d 00 0f ca d9 ec b8 94 3e 46 48 4a 26 11", + "github.com/Scalingo/go-scalingo.LogsService": "8e ec dc 9f 21 7e 20 d8 76 25 a4 92 4f 25 58 e0 a3 7d f0 20", "github.com/Scalingo/go-scalingo.NotificationPlatformsService": "9b a8 93 13 ed 36 09 92 be dc cb 95 17 02 93 28 18 53 ae 01", "github.com/Scalingo/go-scalingo.NotifiersService": "b7 82 f2 c1 a1 81 70 05 ed 5a 65 c0 56 13 de 6e 2c 13 ca 1f", "github.com/Scalingo/go-scalingo.OperationsService": "28 1a bc 62 4c bd 9f e2 ef 45 90 7f 0d 82 5f 30 23 07 93 2a", @@ -28,7 +28,7 @@ "github.com/Scalingo/go-scalingo.SourcesService": "05 1f 06 73 0a 43 2a 6a 35 d2 b9 41 d2 be 8e 7c ad b0 63 3e", "github.com/Scalingo/go-scalingo.TokensService": "32 2d 05 42 b4 9c a9 3b 1b 6c ce 0e da 18 cf 6f 8f cb fc 2a", "github.com/Scalingo/go-scalingo.UsersService": "9e c5 75 1e aa 05 dd a7 a3 17 5f 4e 82 80 e2 34 55 a2 70 df", - "github.com/Scalingo/go-scalingo.VariablesService": "77 27 0b 8a 6b ac c9 c8 c3 b0 e0 f8 cf 7d 6e a0 63 9d 95 03", + "github.com/Scalingo/go-scalingo.VariablesService": "8c d1 eb bc dc ab a9 7e 98 c5 8e 58 03 63 1f 35 5b f4 e6 2a", "github.com/Scalingo/go-scalingo/http.Client": "26 26 d6 21 12 7a b4 88 dc 46 fe 51 21 d6 00 94 94 a1 7f 89", "github.com/Scalingo/go-scalingo/http.TokensService": "e0 cf 0b 06 6f 07 a7 2b f2 c9 14 0f 3e aa d1 6b 83 5b 95 73" } \ No newline at end of file diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/notification_platforms.go b/vendor/github.com/Scalingo/go-scalingo/v11/notification_platforms.go similarity index 67% rename from vendor/github.com/Scalingo/go-scalingo/v10/notification_platforms.go rename to vendor/github.com/Scalingo/go-scalingo/v11/notification_platforms.go index af05280b2..a0202bebb 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/notification_platforms.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/notification_platforms.go @@ -2,10 +2,9 @@ package scalingo import ( "context" - "encoding/json" - "github.com/Scalingo/go-scalingo/v10/debug" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/debug" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) @@ -34,44 +33,31 @@ type PlatformsRes struct { } func (c *Client) NotificationPlatformsList(ctx context.Context) ([]*NotificationPlatform, error) { + var platformsRes PlatformsRes req := &http.APIRequest{ NoAuth: true, Endpoint: "/notification_platforms", } - res, err := c.ScalingoAPI().Do(ctx, req) + err := c.ScalingoAPI().DoRequest(ctx, req, &platformsRes) if err != nil { return nil, errors.Wrap(ctx, err, "list notification platforms") } - defer res.Body.Close() - var response PlatformsRes - err = json.NewDecoder(res.Body).Decode(&response) - if err != nil { - return nil, errors.Wrap(ctx, err, "decode notification platforms response") - } - - return response.NotificationPlatforms, nil + return platformsRes.NotificationPlatforms, nil } func (c *Client) NotificationPlatformByName(ctx context.Context, name string) ([]*NotificationPlatform, error) { debug.Printf("[NotificationPlatformByName] name: %s", name) + var platformsRes PlatformsRes req := &http.APIRequest{ NoAuth: true, Endpoint: "/notification_platforms/search", Params: map[string]string{"name": name}, } - res, err := c.ScalingoAPI().Do(ctx, req) + err := c.ScalingoAPI().DoRequest(ctx, req, &platformsRes) if err != nil { return nil, errors.Wrap(ctx, err, "search notification platforms by name") } - defer res.Body.Close() - - debug.Printf("[NotificationPlatformByName] response: %+v", res.Body) - var response PlatformsRes - err = json.NewDecoder(res.Body).Decode(&response) - if err != nil { - return nil, errors.Wrap(ctx, err, "decode notification platform search response") - } - return response.NotificationPlatforms, nil + return platformsRes.NotificationPlatforms, nil } diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/notifier_types.go b/vendor/github.com/Scalingo/go-scalingo/v11/notifier_types.go similarity index 99% rename from vendor/github.com/Scalingo/go-scalingo/v10/notifier_types.go rename to vendor/github.com/Scalingo/go-scalingo/v11/notifier_types.go index 48e008865..2cbf75949 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/notifier_types.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/notifier_types.go @@ -3,7 +3,7 @@ package scalingo import ( "encoding/json" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" ) // Used to omit attributes diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/notifiers.go b/vendor/github.com/Scalingo/go-scalingo/v11/notifiers.go similarity index 98% rename from vendor/github.com/Scalingo/go-scalingo/v10/notifiers.go rename to vendor/github.com/Scalingo/go-scalingo/v11/notifiers.go index 8767a8609..bec14089a 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/notifiers.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/notifiers.go @@ -5,7 +5,7 @@ import ( "encoding/json" "time" - "github.com/Scalingo/go-scalingo/v10/debug" + "github.com/Scalingo/go-scalingo/v11/debug" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/operations.go b/vendor/github.com/Scalingo/go-scalingo/v11/operations.go similarity index 97% rename from vendor/github.com/Scalingo/go-scalingo/v10/operations.go rename to vendor/github.com/Scalingo/go-scalingo/v11/operations.go index 059619f84..bf78090ad 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/operations.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/operations.go @@ -4,7 +4,7 @@ import ( "context" "time" - httpclient "github.com/Scalingo/go-scalingo/v10/http" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/owner.go b/vendor/github.com/Scalingo/go-scalingo/v11/owner.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/owner.go rename to vendor/github.com/Scalingo/go-scalingo/v11/owner.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/privatenetworks.go b/vendor/github.com/Scalingo/go-scalingo/v11/privatenetworks.go similarity index 62% rename from vendor/github.com/Scalingo/go-scalingo/v10/privatenetworks.go rename to vendor/github.com/Scalingo/go-scalingo/v11/privatenetworks.go index a24e22f97..a1327de40 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/privatenetworks.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/privatenetworks.go @@ -2,17 +2,13 @@ package scalingo import ( "context" - "net/http" - "net/url" - "strconv" - httpclient "github.com/Scalingo/go-scalingo/v10/http" "github.com/Scalingo/go-utils/errors/v3" "github.com/Scalingo/go-utils/pagination" ) type PrivateNetworksService interface { - PrivateNetworksDomainsList(ctx context.Context, app string, page uint, perPage uint) (pagination.Paginated[[]PrivateNetworkDomain], error) + PrivateNetworksDomainsList(ctx context.Context, app string, paginationReq pagination.Request) (pagination.Paginated[[]PrivateNetworkDomain], error) } var _ PrivateNetworksService = (*Client)(nil) @@ -23,28 +19,23 @@ type PrivateNetworkDomainsRes struct { Domains pagination.Paginated[[]PrivateNetworkDomain] `json:"domain_names"` } -func (c *Client) PrivateNetworksDomainsList(ctx context.Context, app string, page uint, perPage uint) (pagination.Paginated[[]PrivateNetworkDomain], error) { - var err error +func (c *Client) PrivateNetworksDomainsList(ctx context.Context, app string, paginationReq pagination.Request) (pagination.Paginated[[]PrivateNetworkDomain], error) { validationErr := errors.NewValidationErrorsBuilder() - if page < 1 { + if paginationReq.Page < 1 { validationErr.Set("page", "must be greater than zero") return pagination.Paginated[[]PrivateNetworkDomain]{}, validationErr.Build() } - if perPage < 1 || perPage > 50 { + if paginationReq.PerPage < 1 || paginationReq.PerPage > 50 { validationErr.Set("per_page", "must be between 1 and 50") return pagination.Paginated[[]PrivateNetworkDomain]{}, validationErr.Build() } - params := url.Values{} - params.Set("page", strconv.Itoa(int(page))) - params.Set("per-page", strconv.Itoa(int(perPage))) - req := &httpclient.APIRequest{ - Method: http.MethodGet, - Endpoint: "/apps/" + app + "/private_network_domain_names?" + params.Encode(), - } var domainRes PrivateNetworkDomainsRes - err = c.ScalingoAPI().DoRequest(ctx, req, &domainRes) + err := c.ScalingoAPI().SubresourceList(ctx, + "apps", app, "private_network_domain_names", paginationReq.ToURLValues(), + &domainRes, + ) if err != nil { return pagination.Paginated[[]PrivateNetworkDomain]{}, errors.Wrap(ctx, err, "make api call to list the private network domain names") } diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/projects.go b/vendor/github.com/Scalingo/go-scalingo/v11/projects.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/projects.go rename to vendor/github.com/Scalingo/go-scalingo/v11/projects.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/regions.go b/vendor/github.com/Scalingo/go-scalingo/v11/regions.go similarity index 97% rename from vendor/github.com/Scalingo/go-scalingo/v10/regions.go rename to vendor/github.com/Scalingo/go-scalingo/v11/regions.go index f548077c0..9568f3228 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/regions.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/regions.go @@ -5,7 +5,7 @@ import ( stderrors "errors" "sync" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/resources.go b/vendor/github.com/Scalingo/go-scalingo/v11/resources.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/resources.go rename to vendor/github.com/Scalingo/go-scalingo/v11/resources.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/review_apps.go b/vendor/github.com/Scalingo/go-scalingo/v11/review_apps.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/review_apps.go rename to vendor/github.com/Scalingo/go-scalingo/v11/review_apps.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/run.go b/vendor/github.com/Scalingo/go-scalingo/v11/run.go similarity index 73% rename from vendor/github.com/Scalingo/go-scalingo/v10/run.go rename to vendor/github.com/Scalingo/go-scalingo/v11/run.go index 54d058d64..9d389538a 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/run.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/run.go @@ -2,11 +2,10 @@ package scalingo import ( "context" - "encoding/json" "strings" - "github.com/Scalingo/go-scalingo/v10/http" - errors "github.com/Scalingo/go-utils/errors/v3" + "github.com/Scalingo/go-scalingo/v11/http" + "github.com/Scalingo/go-utils/errors/v3" ) type RunsService interface { @@ -31,6 +30,7 @@ type RunRes struct { } func (c *Client) Run(ctx context.Context, opts RunOpts) (*RunRes, error) { + var runRes RunRes req := &http.APIRequest{ Method: "POST", Endpoint: "/apps/" + opts.App + "/run", @@ -42,19 +42,10 @@ func (c *Client) Run(ctx context.Context, opts RunOpts) (*RunRes, error) { "has_uploads": opts.HasUploads, }, } - res, err := c.ScalingoAPI().Do(ctx, req) + err := c.ScalingoAPI().DoRequest(ctx, req, &runRes) if err != nil { return nil, errors.Wrapf(ctx, err, "request endpoint %v", req.Endpoint) } - defer res.Body.Close() - - var runRes RunRes - err = json.NewDecoder(res.Body).Decode(&runRes) - if err != nil { - return nil, errors.Wrap(ctx, err, "decode response body") - } - - runRes.OperationURL = res.Header.Get("Location") return &runRes, nil } diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/scm_integrations.go b/vendor/github.com/Scalingo/go-scalingo/v11/scm_integrations.go similarity index 98% rename from vendor/github.com/Scalingo/go-scalingo/v10/scm_integrations.go rename to vendor/github.com/Scalingo/go-scalingo/v11/scm_integrations.go index fa633d5f7..5f20b1d07 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/scm_integrations.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/scm_integrations.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/scm_repo_link.go b/vendor/github.com/Scalingo/go-scalingo/v11/scm_repo_link.go similarity index 97% rename from vendor/github.com/Scalingo/go-scalingo/v10/scm_repo_link.go rename to vendor/github.com/Scalingo/go-scalingo/v11/scm_repo_link.go index af33e340a..1e2238340 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/scm_repo_link.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/scm_repo_link.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" "github.com/Scalingo/go-utils/pagination" ) @@ -168,15 +168,14 @@ func (c *Client) SCMRepoLinkUpdate(ctx context.Context, app string, params SCMRe } func (c *Client) SCMRepoLinkDelete(ctx context.Context, app string) error { - res, err := c.ScalingoAPI().Do(ctx, &http.APIRequest{ + err := c.ScalingoAPI().DoRequest(ctx, &http.APIRequest{ Method: "DELETE", Endpoint: "/apps/" + app + "/scm_repo_link", Expected: http.Statuses{204}, - }) + }, nil) if err != nil { return errors.Wrap(ctx, err, "delete this SCM repo link") } - defer res.Body.Close() return nil } @@ -210,16 +209,15 @@ func (c *Client) SCMRepoLinkManualDeploy(ctx context.Context, app, branch string } func (c *Client) SCMRepoLinkManualReviewApp(ctx context.Context, app, pullRequestID string) error { - res, err := c.ScalingoAPI().Do(ctx, &http.APIRequest{ + err := c.ScalingoAPI().DoRequest(ctx, &http.APIRequest{ Method: "POST", Endpoint: "/apps/" + app + "/scm_repo_link/manual_review_app", Expected: http.Statuses{200}, Params: map[string]string{"pull_request_id": pullRequestID}, - }) + }, nil) if err != nil { return errors.Wrap(ctx, err, "trigger manual review app deployment") } - defer res.Body.Close() return nil } diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/signup.go b/vendor/github.com/Scalingo/go-scalingo/v11/signup.go similarity index 84% rename from vendor/github.com/Scalingo/go-scalingo/v10/signup.go rename to vendor/github.com/Scalingo/go-scalingo/v11/signup.go index fd5cf661d..79b8ca78d 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/signup.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/signup.go @@ -3,7 +3,7 @@ package scalingo import ( "context" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) @@ -26,11 +26,10 @@ func (c *Client) SignUp(ctx context.Context, email, password string) error { }, }, } - res, err := c.ScalingoAPI().Do(ctx, req) + err := c.ScalingoAPI().DoRequest(ctx, req, nil) if err != nil { return errors.Wrap(ctx, err, "sign up user") } - defer res.Body.Close() return nil } diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/sources.go b/vendor/github.com/Scalingo/go-scalingo/v11/sources.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/sources.go rename to vendor/github.com/Scalingo/go-scalingo/v11/sources.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/stacks.go b/vendor/github.com/Scalingo/go-scalingo/v11/stacks.go similarity index 96% rename from vendor/github.com/Scalingo/go-scalingo/v10/stacks.go rename to vendor/github.com/Scalingo/go-scalingo/v11/stacks.go index f8581f073..b4e9fbfd3 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/stacks.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/stacks.go @@ -4,7 +4,7 @@ import ( "context" "time" - httpclient "github.com/Scalingo/go-scalingo/v10/http" + httpclient "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/static_token.go b/vendor/github.com/Scalingo/go-scalingo/v11/static_token.go similarity index 100% rename from vendor/github.com/Scalingo/go-scalingo/v10/static_token.go rename to vendor/github.com/Scalingo/go-scalingo/v11/static_token.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/tokens.go b/vendor/github.com/Scalingo/go-scalingo/v11/tokens.go similarity index 87% rename from vendor/github.com/Scalingo/go-scalingo/v10/tokens.go rename to vendor/github.com/Scalingo/go-scalingo/v11/tokens.go index c8c48821d..391a2f1ed 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/tokens.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/tokens.go @@ -2,11 +2,10 @@ package scalingo import ( "context" - "encoding/json" "strconv" "time" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) @@ -74,6 +73,7 @@ func (c *Client) TokensList(ctx context.Context) (Tokens, error) { } func (c *Client) TokenExchange(ctx context.Context, token string) (string, error) { + var btRes BearerTokenRes req := &http.APIRequest{ NoAuth: true, Method: "POST", @@ -81,17 +81,10 @@ func (c *Client) TokenExchange(ctx context.Context, token string) (string, error Password: token, } - res, err := c.AuthAPI().Do(ctx, req) + err := c.AuthAPI().DoRequest(ctx, req, &btRes) if err != nil { return "", errors.Wrap(ctx, err, "make request POST /v1/tokens/exchange") } - defer res.Body.Close() - - var btRes BearerTokenRes - err = json.NewDecoder(res.Body).Decode(&btRes) - if err != nil { - return "", errors.Wrap(ctx, err, "invalid response from authentication service") - } return btRes.Token, nil } @@ -109,20 +102,14 @@ func (c *Client) TokenCreateWithLogin(ctx context.Context, params TokenCreatePar Params: map[string]any{"token": params}, } - resp, err := c.AuthAPI().Do(ctx, req) + var tokenRes TokenRes + err := c.AuthAPI().DoRequest(ctx, req, &tokenRes) if err != nil { if http.IsOTPRequired(err) { return Token{}, http.ErrOTPRequired } return Token{}, errors.Wrap(ctx, err, "create token with login") } - defer resp.Body.Close() - - var tokenRes TokenRes - err = json.NewDecoder(resp.Body).Decode(&tokenRes) - if err != nil { - return Token{}, errors.Wrap(ctx, err, "invalid response from authentication service") - } return tokenRes.Token, nil } diff --git a/vendor/github.com/Scalingo/go-scalingo/v10/users.go b/vendor/github.com/Scalingo/go-scalingo/v11/users.go similarity index 73% rename from vendor/github.com/Scalingo/go-scalingo/v10/users.go rename to vendor/github.com/Scalingo/go-scalingo/v11/users.go index 74fae01ee..7d45595f8 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v10/users.go +++ b/vendor/github.com/Scalingo/go-scalingo/v11/users.go @@ -2,9 +2,8 @@ package scalingo import ( "context" - "encoding/json" - "github.com/Scalingo/go-scalingo/v10/http" + "github.com/Scalingo/go-scalingo/v11/http" "github.com/Scalingo/go-utils/errors/v3" ) @@ -29,21 +28,15 @@ type SelfResponse struct { } func (c *Client) Self(ctx context.Context) (*User, error) { + var selfRes SelfResponse req := &http.APIRequest{ Endpoint: "/users/self", } - res, err := c.AuthAPI().Do(ctx, req) + err := c.AuthAPI().DoRequest(ctx, req, &selfRes) if err != nil { return nil, errors.Wrap(ctx, err, "get current user") } - defer res.Body.Close() - - var u SelfResponse - err = json.NewDecoder(res.Body).Decode(&u) - if err != nil { - return nil, errors.Wrap(ctx, err, "decode current user response") - } - return u.User, nil + return selfRes.User, nil } type UpdateUserParams struct { @@ -68,19 +61,13 @@ func (c *Client) UpdateUser(ctx context.Context, params UpdateUserParams) (*User }, Expected: http.Statuses{200}, } - res, err := c.AuthAPI().Do(ctx, req) + var updateUserRes UpdateUserResponse + err := c.AuthAPI().DoRequest(ctx, req, &updateUserRes) if err != nil { return nil, errors.Wrap(ctx, err, "execute the query to update the user") } - defer res.Body.Close() - - var u UpdateUserResponse - err = json.NewDecoder(res.Body).Decode(&u) - if err != nil { - return nil, errors.Wrap(ctx, err, "decode response of the query to update the user") - } - return u.User, nil + return updateUserRes.User, nil } func (c *Client) UserStopFreeTrial(ctx context.Context) error { @@ -91,11 +78,10 @@ func (c *Client) UserStopFreeTrial(ctx context.Context) error { Expected: http.Statuses{200}, } - res, err := c.AuthAPI().Do(ctx, req) + err := c.AuthAPI().DoRequest(ctx, req, nil) if err != nil { return errors.Wrap(ctx, err, "execute the query to stop user free trial") } - defer res.Body.Close() return nil } diff --git a/vendor/github.com/Scalingo/go-scalingo/v11/version.go b/vendor/github.com/Scalingo/go-scalingo/v11/version.go new file mode 100644 index 000000000..b54991bf5 --- /dev/null +++ b/vendor/github.com/Scalingo/go-scalingo/v11/version.go @@ -0,0 +1,3 @@ +package scalingo + +var Version = "11.0.0" diff --git a/vendor/github.com/golang/mock/CONTRIBUTORS b/vendor/github.com/golang/mock/CONTRIBUTORS deleted file mode 100644 index def849cab..000000000 --- a/vendor/github.com/golang/mock/CONTRIBUTORS +++ /dev/null @@ -1,37 +0,0 @@ -# This is the official list of people who can contribute (and typically -# have contributed) code to the gomock repository. -# The AUTHORS file lists the copyright holders; this file -# lists people. For example, Google employees are listed here -# but not in AUTHORS, because Google holds the copyright. -# -# The submission process automatically checks to make sure -# that people submitting code are listed in this file (by email address). -# -# Names should be added to this file only after verifying that -# the individual or the individual's organization has agreed to -# the appropriate Contributor License Agreement, found here: -# -# http://code.google.com/legal/individual-cla-v1.0.html -# http://code.google.com/legal/corporate-cla-v1.0.html -# -# The agreement for individuals can be filled out on the web. -# -# When adding J Random Contributor's name to this file, -# either J's name or J's organization's name should be -# added to the AUTHORS file, depending on whether the -# individual or corporate CLA was used. - -# Names should be added to this file like so: -# Name -# -# An entry with two email addresses specifies that the -# first address should be used in the submit logs and -# that the second address should be recognized as the -# same person when interacting with Rietveld. - -# Please keep the list sorted. - -Aaron Jacobs -Alex Reece -David Symonds -Ryan Barrett diff --git a/vendor/github.com/golang/mock/AUTHORS b/vendor/go.uber.org/mock/AUTHORS similarity index 100% rename from vendor/github.com/golang/mock/AUTHORS rename to vendor/go.uber.org/mock/AUTHORS diff --git a/vendor/github.com/golang/mock/LICENSE b/vendor/go.uber.org/mock/LICENSE similarity index 100% rename from vendor/github.com/golang/mock/LICENSE rename to vendor/go.uber.org/mock/LICENSE diff --git a/vendor/github.com/golang/mock/gomock/call.go b/vendor/go.uber.org/mock/gomock/call.go similarity index 78% rename from vendor/github.com/golang/mock/gomock/call.go rename to vendor/go.uber.org/mock/gomock/call.go index 13c9f44b1..e1fe222af 100644 --- a/vendor/github.com/golang/mock/gomock/call.go +++ b/vendor/go.uber.org/mock/gomock/call.go @@ -25,7 +25,7 @@ import ( type Call struct { t TestHelper // for triggering test failures on invalid call setup - receiver interface{} // the receiver of the method call + receiver any // the receiver of the method call method string // the name of the method methodType reflect.Type // the type of the method args []Matcher // the args @@ -41,12 +41,12 @@ type Call struct { // actions are called when this Call is called. Each action gets the args and // can set the return values by returning a non-nil slice. Actions run in the // order they are created. - actions []func([]interface{}) []interface{} + actions []func([]any) []any } // newCall creates a *Call. It requires the method type in order to support // unexported methods. -func newCall(t TestHelper, receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call { +func newCall(t TestHelper, receiver any, method string, methodType reflect.Type, args ...any) *Call { t.Helper() // TODO: check arity, types. @@ -67,16 +67,18 @@ func newCall(t TestHelper, receiver interface{}, method string, methodType refle // and this line changes, i.e. this code is wrapped in another anonymous function. // 0 is us, 1 is RecordCallWithMethodType(), 2 is the generated recorder, and 3 is the user's test. origin := callerInfo(3) - actions := []func([]interface{}) []interface{}{func([]interface{}) []interface{} { + actions := []func([]any) []any{func([]any) []any { // Synthesize the zero value for each of the return args' types. - rets := make([]interface{}, methodType.NumOut()) + rets := make([]any, methodType.NumOut()) for i := 0; i < methodType.NumOut(); i++ { rets[i] = reflect.Zero(methodType.Out(i)).Interface() } return rets }} - return &Call{t: t, receiver: receiver, method: method, methodType: methodType, - args: mArgs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions} + return &Call{ + t: t, receiver: receiver, method: method, methodType: methodType, + args: mArgs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions, + } } // AnyTimes allows the expectation to be called 0 or more times @@ -107,20 +109,26 @@ func (c *Call) MaxTimes(n int) *Call { // DoAndReturn declares the action to run when the call is matched. // The return values from this function are returned by the mocked function. -// It takes an interface{} argument to support n-arity functions. -func (c *Call) DoAndReturn(f interface{}) *Call { +// It takes an any argument to support n-arity functions. +// The anonymous function must match the function signature mocked method. +func (c *Call) DoAndReturn(f any) *Call { // TODO: Check arity and types here, rather than dying badly elsewhere. v := reflect.ValueOf(f) - c.addAction(func(args []interface{}) []interface{} { + c.addAction(func(args []any) []any { c.t.Helper() - vArgs := make([]reflect.Value, len(args)) ft := v.Type() if c.methodType.NumIn() != ft.NumIn() { - c.t.Fatalf("wrong number of arguments in DoAndReturn func for %T.%v: got %d, want %d [%s]", - c.receiver, c.method, ft.NumIn(), c.methodType.NumIn(), c.origin) + if ft.IsVariadic() { + c.t.Fatalf("wrong number of arguments in DoAndReturn func for %T.%v The function signature must match the mocked method, a variadic function cannot be used.", + c.receiver, c.method) + } else { + c.t.Fatalf("wrong number of arguments in DoAndReturn func for %T.%v: got %d, want %d [%s]", + c.receiver, c.method, ft.NumIn(), c.methodType.NumIn(), c.origin) + } return nil } + vArgs := make([]reflect.Value, len(args)) for i := 0; i < len(args); i++ { if args[i] != nil { vArgs[i] = reflect.ValueOf(args[i]) @@ -130,7 +138,7 @@ func (c *Call) DoAndReturn(f interface{}) *Call { } } vRets := v.Call(vArgs) - rets := make([]interface{}, len(vRets)) + rets := make([]any, len(vRets)) for i, ret := range vRets { rets[i] = ret.Interface() } @@ -142,20 +150,26 @@ func (c *Call) DoAndReturn(f interface{}) *Call { // Do declares the action to run when the call is matched. The function's // return values are ignored to retain backward compatibility. To use the // return values call DoAndReturn. -// It takes an interface{} argument to support n-arity functions. -func (c *Call) Do(f interface{}) *Call { +// It takes an any argument to support n-arity functions. +// The anonymous function must match the function signature mocked method. +func (c *Call) Do(f any) *Call { // TODO: Check arity and types here, rather than dying badly elsewhere. v := reflect.ValueOf(f) - c.addAction(func(args []interface{}) []interface{} { + c.addAction(func(args []any) []any { c.t.Helper() - if c.methodType.NumIn() != v.Type().NumIn() { - c.t.Fatalf("wrong number of arguments in Do func for %T.%v: got %d, want %d [%s]", - c.receiver, c.method, v.Type().NumIn(), c.methodType.NumIn(), c.origin) + ft := v.Type() + if c.methodType.NumIn() != ft.NumIn() { + if ft.IsVariadic() { + c.t.Fatalf("wrong number of arguments in Do func for %T.%v The function signature must match the mocked method, a variadic function cannot be used.", + c.receiver, c.method) + } else { + c.t.Fatalf("wrong number of arguments in Do func for %T.%v: got %d, want %d [%s]", + c.receiver, c.method, ft.NumIn(), c.methodType.NumIn(), c.origin) + } return nil } vArgs := make([]reflect.Value, len(args)) - ft := v.Type() for i := 0; i < len(args); i++ { if args[i] != nil { vArgs[i] = reflect.ValueOf(args[i]) @@ -171,7 +185,7 @@ func (c *Call) Do(f interface{}) *Call { } // Return declares the values to be returned by the mocked function call. -func (c *Call) Return(rets ...interface{}) *Call { +func (c *Call) Return(rets ...any) *Call { c.t.Helper() mt := c.methodType @@ -203,7 +217,7 @@ func (c *Call) Return(rets ...interface{}) *Call { } } - c.addAction(func([]interface{}) []interface{} { + c.addAction(func([]any) []any { return rets }) @@ -217,9 +231,9 @@ func (c *Call) Times(n int) *Call { } // SetArg declares an action that will set the nth argument's value, -// indirected through a pointer. Or, in the case of a slice, SetArg -// will copy value's elements into the nth argument. -func (c *Call) SetArg(n int, value interface{}) *Call { +// indirected through a pointer. Or, in the case of a slice and map, SetArg +// will copy value's elements/key-value pairs into the nth argument. +func (c *Call) SetArg(n int, value any) *Call { c.t.Helper() mt := c.methodType @@ -239,20 +253,20 @@ func (c *Call) SetArg(n int, value interface{}) *Call { c.t.Fatalf("SetArg(%d, ...) argument is a %v, not assignable to %v [%s]", n, vt, dt, c.origin) } - case reflect.Interface: - // nothing to do - case reflect.Slice: + case reflect.Interface, reflect.Slice, reflect.Map: // nothing to do default: - c.t.Fatalf("SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice type %v [%s]", + c.t.Fatalf("SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice non-map type %v [%s]", n, at, c.origin) } - c.addAction(func(args []interface{}) []interface{} { + c.addAction(func(args []any) []any { v := reflect.ValueOf(value) switch reflect.TypeOf(args[n]).Kind() { case reflect.Slice: setSlice(args[n], v) + case reflect.Map: + setMap(args[n], v) default: reflect.ValueOf(args[n]).Elem().Set(v) } @@ -307,7 +321,7 @@ func (c *Call) String() string { // Tests if the given call matches the expected call. // If yes, returns nil. If no, returns error with message explaining why it does not match. -func (c *Call) matches(args []interface{}) error { +func (c *Call) matches(args []any) error { if !c.methodType.IsVariadic() { if len(args) != len(c.args) { return fmt.Errorf("expected call at %s has the wrong number of arguments. Got: %d, want: %d", @@ -413,30 +427,77 @@ func (c *Call) dropPrereqs() (preReqs []*Call) { return } -func (c *Call) call() []func([]interface{}) []interface{} { +func (c *Call) call() []func([]any) []any { c.numCalls++ return c.actions } // InOrder declares that the given calls should occur in order. -func InOrder(calls ...*Call) { +// It panics if the type of any of the arguments isn't *Call or a generated +// mock with an embedded *Call. +func InOrder(args ...any) { + calls := make([]*Call, 0, len(args)) + for i := 0; i < len(args); i++ { + if call := getCall(args[i]); call != nil { + calls = append(calls, call) + continue + } + panic(fmt.Sprintf( + "invalid argument at position %d of type %T, InOrder expects *gomock.Call or generated mock types with an embedded *gomock.Call", + i, + args[i], + )) + } for i := 1; i < len(calls); i++ { calls[i].After(calls[i-1]) } } -func setSlice(arg interface{}, v reflect.Value) { +// getCall checks if the parameter is a *Call or a generated struct +// that wraps a *Call and returns the *Call pointer - if neither, it returns nil. +func getCall(arg any) *Call { + if call, ok := arg.(*Call); ok { + return call + } + t := reflect.ValueOf(arg) + if t.Kind() != reflect.Ptr && t.Kind() != reflect.Interface { + return nil + } + t = t.Elem() + for i := 0; i < t.NumField(); i++ { + f := t.Field(i) + if !f.CanInterface() { + continue + } + if call, ok := f.Interface().(*Call); ok { + return call + } + } + return nil +} + +func setSlice(arg any, v reflect.Value) { va := reflect.ValueOf(arg) for i := 0; i < v.Len(); i++ { va.Index(i).Set(v.Index(i)) } } -func (c *Call) addAction(action func([]interface{}) []interface{}) { +func setMap(arg any, v reflect.Value) { + va := reflect.ValueOf(arg) + for _, e := range va.MapKeys() { + va.SetMapIndex(e, reflect.Value{}) + } + for _, e := range v.MapKeys() { + va.SetMapIndex(e, v.MapIndex(e)) + } +} + +func (c *Call) addAction(action func([]any) []any) { c.actions = append(c.actions, action) } -func formatGottenArg(m Matcher, arg interface{}) string { +func formatGottenArg(m Matcher, arg any) string { got := fmt.Sprintf("%v (%T)", arg, arg) if gs, ok := m.(GotFormatter); ok { got = gs.Got(arg) diff --git a/vendor/github.com/golang/mock/gomock/callset.go b/vendor/go.uber.org/mock/gomock/callset.go similarity index 70% rename from vendor/github.com/golang/mock/gomock/callset.go rename to vendor/go.uber.org/mock/gomock/callset.go index 49dba787a..f5cc592d6 100644 --- a/vendor/github.com/golang/mock/gomock/callset.go +++ b/vendor/go.uber.org/mock/gomock/callset.go @@ -18,40 +18,69 @@ import ( "bytes" "errors" "fmt" + "sync" ) // callSet represents a set of expected calls, indexed by receiver and method // name. type callSet struct { // Calls that are still expected. - expected map[callSetKey][]*Call + expected map[callSetKey][]*Call + expectedMu *sync.Mutex // Calls that have been exhausted. exhausted map[callSetKey][]*Call + // when set to true, existing call expectations are overridden when new call expectations are made + allowOverride bool } // callSetKey is the key in the maps in callSet type callSetKey struct { - receiver interface{} + receiver any fname string } func newCallSet() *callSet { - return &callSet{make(map[callSetKey][]*Call), make(map[callSetKey][]*Call)} + return &callSet{ + expected: make(map[callSetKey][]*Call), + expectedMu: &sync.Mutex{}, + exhausted: make(map[callSetKey][]*Call), + } +} + +func newOverridableCallSet() *callSet { + return &callSet{ + expected: make(map[callSetKey][]*Call), + expectedMu: &sync.Mutex{}, + exhausted: make(map[callSetKey][]*Call), + allowOverride: true, + } } // Add adds a new expected call. func (cs callSet) Add(call *Call) { key := callSetKey{call.receiver, call.method} + + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + m := cs.expected if call.exhausted() { m = cs.exhausted } + if cs.allowOverride { + m[key] = make([]*Call, 0) + } + m[key] = append(m[key], call) } // Remove removes an expected call. func (cs callSet) Remove(call *Call) { key := callSetKey{call.receiver, call.method} + + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + calls := cs.expected[key] for i, c := range calls { if c == call { @@ -64,9 +93,12 @@ func (cs callSet) Remove(call *Call) { } // FindMatch searches for a matching call. Returns error with explanation message if no call matched. -func (cs callSet) FindMatch(receiver interface{}, method string, args []interface{}) (*Call, error) { +func (cs callSet) FindMatch(receiver any, method string, args []any) (*Call, error) { key := callSetKey{receiver, method} + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + // Search through the expected calls. expected := cs.expected[key] var callsErrors bytes.Buffer @@ -101,6 +133,9 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac // Failures returns the calls that are not satisfied. func (cs callSet) Failures() []*Call { + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + failures := make([]*Call, 0, len(cs.expected)) for _, calls := range cs.expected { for _, call := range calls { @@ -111,3 +146,19 @@ func (cs callSet) Failures() []*Call { } return failures } + +// Satisfied returns true in case all expected calls in this callSet are satisfied. +func (cs callSet) Satisfied() bool { + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + + for _, calls := range cs.expected { + for _, call := range calls { + if !call.satisfied() { + return false + } + } + } + + return true +} diff --git a/vendor/github.com/golang/mock/gomock/controller.go b/vendor/go.uber.org/mock/gomock/controller.go similarity index 65% rename from vendor/github.com/golang/mock/gomock/controller.go rename to vendor/go.uber.org/mock/gomock/controller.go index f054200d5..674c3298c 100644 --- a/vendor/github.com/golang/mock/gomock/controller.go +++ b/vendor/go.uber.org/mock/gomock/controller.go @@ -12,44 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package gomock is a mock framework for Go. -// -// Standard usage: -// (1) Define an interface that you wish to mock. -// type MyInterface interface { -// SomeMethod(x int64, y string) -// } -// (2) Use mockgen to generate a mock from the interface. -// (3) Use the mock in a test: -// func TestMyThing(t *testing.T) { -// mockCtrl := gomock.NewController(t) -// defer mockCtrl.Finish() -// -// mockObj := something.NewMockMyInterface(mockCtrl) -// mockObj.EXPECT().SomeMethod(4, "blah") -// // pass mockObj to a real object and play with it. -// } -// -// By default, expected calls are not enforced to run in any particular order. -// Call order dependency can be enforced by use of InOrder and/or Call.After. -// Call.After can create more varied call order dependencies, but InOrder is -// often more convenient. -// -// The following examples create equivalent call order dependencies. -// -// Example of using Call.After to chain expected call order: -// -// firstCall := mockObj.EXPECT().SomeMethod(1, "first") -// secondCall := mockObj.EXPECT().SomeMethod(2, "second").After(firstCall) -// mockObj.EXPECT().SomeMethod(3, "third").After(secondCall) -// -// Example of using InOrder to declare expected call order: -// -// gomock.InOrder( -// mockObj.EXPECT().SomeMethod(1, "first"), -// mockObj.EXPECT().SomeMethod(2, "second"), -// mockObj.EXPECT().SomeMethod(3, "third"), -// ) package gomock import ( @@ -63,8 +25,8 @@ import ( // A TestReporter is something that can be used to report test failures. It // is satisfied by the standard library's *testing.T. type TestReporter interface { - Errorf(format string, args ...interface{}) - Fatalf(format string, args ...interface{}) + Errorf(format string, args ...any) + Fatalf(format string, args ...any) } // TestHelper is a TestReporter that has the Helper method. It is satisfied @@ -86,27 +48,23 @@ type cleanuper interface { // A Controller represents the top-level control of a mock ecosystem. It // defines the scope and lifetime of mock objects, as well as their // expectations. It is safe to call Controller's methods from multiple -// goroutines. Each test should create a new Controller and invoke Finish via -// defer. +// goroutines. Each test should create a new Controller. // -// func TestFoo(t *testing.T) { -// ctrl := gomock.NewController(t) -// defer ctrl.Finish() -// // .. -// } +// func TestFoo(t *testing.T) { +// ctrl := gomock.NewController(t) +// // .. +// } // -// func TestBar(t *testing.T) { -// t.Run("Sub-Test-1", st) { -// ctrl := gomock.NewController(st) -// defer ctrl.Finish() -// // .. -// }) -// t.Run("Sub-Test-2", st) { -// ctrl := gomock.NewController(st) -// defer ctrl.Finish() -// // .. -// }) -// }) +// func TestBar(t *testing.T) { +// t.Run("Sub-Test-1", st) { +// ctrl := gomock.NewController(st) +// // .. +// }) +// t.Run("Sub-Test-2", st) { +// ctrl := gomock.NewController(st) +// // .. +// }) +// }) type Controller struct { // T should only be called within a generated mock. It is not intended to // be used in user code and may be changed in future versions. T is the @@ -119,12 +77,11 @@ type Controller struct { finished bool } -// NewController returns a new Controller. It is the preferred way to create a -// Controller. +// NewController returns a new Controller. It is the preferred way to create a Controller. // -// New in go1.14+, if you are passing a *testing.T into this function you no -// longer need to call ctrl.Finish() in your test methods. -func NewController(t TestReporter) *Controller { +// Passing [*testing.T] registers cleanup function to automatically call [Controller.Finish] +// when the test and all its subtests complete. +func NewController(t TestReporter, opts ...ControllerOption) *Controller { h, ok := t.(TestHelper) if !ok { h = &nopTestHelper{t} @@ -133,6 +90,9 @@ func NewController(t TestReporter) *Controller { T: h, expectedCalls: newCallSet(), } + for _, opt := range opts { + opt.apply(ctrl) + } if c, ok := isCleanuper(ctrl.T); ok { c.Cleanup(func() { ctrl.T.Helper() @@ -143,15 +103,33 @@ func NewController(t TestReporter) *Controller { return ctrl } +// ControllerOption configures how a Controller should behave. +type ControllerOption interface { + apply(*Controller) +} + +type overridableExpectationsOption struct{} + +// WithOverridableExpectations allows for overridable call expectations +// i.e., subsequent call expectations override existing call expectations +func WithOverridableExpectations() overridableExpectationsOption { + return overridableExpectationsOption{} +} + +func (o overridableExpectationsOption) apply(ctrl *Controller) { + ctrl.expectedCalls = newOverridableCallSet() +} + type cancelReporter struct { t TestHelper cancel func() } -func (r *cancelReporter) Errorf(format string, args ...interface{}) { +func (r *cancelReporter) Errorf(format string, args ...any) { r.t.Errorf(format, args...) } -func (r *cancelReporter) Fatalf(format string, args ...interface{}) { + +func (r *cancelReporter) Fatalf(format string, args ...any) { defer r.cancel() r.t.Fatalf(format, args...) } @@ -176,17 +154,18 @@ type nopTestHelper struct { t TestReporter } -func (h *nopTestHelper) Errorf(format string, args ...interface{}) { +func (h *nopTestHelper) Errorf(format string, args ...any) { h.t.Errorf(format, args...) } -func (h *nopTestHelper) Fatalf(format string, args ...interface{}) { + +func (h *nopTestHelper) Fatalf(format string, args ...any) { h.t.Fatalf(format, args...) } func (h nopTestHelper) Helper() {} // RecordCall is called by a mock. It should not be called by user code. -func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...interface{}) *Call { +func (ctrl *Controller) RecordCall(receiver any, method string, args ...any) *Call { ctrl.T.Helper() recv := reflect.ValueOf(receiver) @@ -200,7 +179,7 @@ func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ... } // RecordCallWithMethodType is called by a mock. It should not be called by user code. -func (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call { +func (ctrl *Controller) RecordCallWithMethodType(receiver any, method string, methodType reflect.Type, args ...any) *Call { ctrl.T.Helper() call := newCall(ctrl.T, receiver, method, methodType, args...) @@ -213,11 +192,11 @@ func (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method st } // Call is called by a mock. It should not be called by user code. -func (ctrl *Controller) Call(receiver interface{}, method string, args ...interface{}) []interface{} { +func (ctrl *Controller) Call(receiver any, method string, args ...any) []any { ctrl.T.Helper() // Nest this code so we can use defer to make sure the lock is released. - actions := func() []func([]interface{}) []interface{} { + actions := func() []func([]any) []any { ctrl.T.Helper() ctrl.mu.Lock() defer ctrl.mu.Unlock() @@ -228,12 +207,16 @@ func (ctrl *Controller) Call(receiver interface{}, method string, args ...interf // and this line changes, i.e. this code is wrapped in another anonymous function. // 0 is us, 1 is controller.Call(), 2 is the generated mock, and 3 is the user's test. origin := callerInfo(3) - ctrl.T.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s", receiver, method, args, origin, err) + stringArgs := make([]string, len(args)) + for i, arg := range args { + stringArgs[i] = getString(arg) + } + ctrl.T.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s", receiver, method, stringArgs, origin, err) } // Two things happen here: - // * the matching call no longer needs to check prerequite calls, - // * and the prerequite calls are no longer expected, so remove them. + // * the matching call no longer needs to check prerequisite calls, + // * and the prerequisite calls are no longer expected, so remove them. preReqCalls := expected.dropPrereqs() for _, preReqCall := range preReqCalls { ctrl.expectedCalls.Remove(preReqCall) @@ -246,7 +229,7 @@ func (ctrl *Controller) Call(receiver interface{}, method string, args ...interf return actions }() - var rets []interface{} + var rets []any for _, action := range actions { if r := action(args); r != nil { rets = r @@ -256,12 +239,11 @@ func (ctrl *Controller) Call(receiver interface{}, method string, args ...interf return rets } -// Finish checks to see if all the methods that were expected to be called -// were called. It should be invoked for each Controller. It is not idempotent -// and therefore can only be invoked once. +// Finish checks to see if all the methods that were expected to be called were called. +// It is not idempotent and therefore can only be invoked once. // -// New in go1.14+, if you are passing a *testing.T into NewController function you no -// longer need to call ctrl.Finish() in your test methods. +// Note: If you pass a *testing.T into [NewController], you no longer +// need to call ctrl.Finish() in your test methods. func (ctrl *Controller) Finish() { // If we're currently panicking, probably because this is a deferred call. // This must be recovered in the deferred function. @@ -269,7 +251,15 @@ func (ctrl *Controller) Finish() { ctrl.finish(false, err) } -func (ctrl *Controller) finish(cleanup bool, panicErr interface{}) { +// Satisfied returns whether all expected calls bound to this Controller have been satisfied. +// Calling Finish is then guaranteed to not fail due to missing calls. +func (ctrl *Controller) Satisfied() bool { + ctrl.mu.Lock() + defer ctrl.mu.Unlock() + return ctrl.expectedCalls.Satisfied() +} + +func (ctrl *Controller) finish(cleanup bool, panicErr any) { ctrl.T.Helper() ctrl.mu.Lock() diff --git a/vendor/go.uber.org/mock/gomock/doc.go b/vendor/go.uber.org/mock/gomock/doc.go new file mode 100644 index 000000000..696dda388 --- /dev/null +++ b/vendor/go.uber.org/mock/gomock/doc.go @@ -0,0 +1,60 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package gomock is a mock framework for Go. +// +// Standard usage: +// +// (1) Define an interface that you wish to mock. +// type MyInterface interface { +// SomeMethod(x int64, y string) +// } +// (2) Use mockgen to generate a mock from the interface. +// (3) Use the mock in a test: +// func TestMyThing(t *testing.T) { +// mockCtrl := gomock.NewController(t) +// mockObj := something.NewMockMyInterface(mockCtrl) +// mockObj.EXPECT().SomeMethod(4, "blah") +// // pass mockObj to a real object and play with it. +// } +// +// By default, expected calls are not enforced to run in any particular order. +// Call order dependency can be enforced by use of InOrder and/or Call.After. +// Call.After can create more varied call order dependencies, but InOrder is +// often more convenient. +// +// The following examples create equivalent call order dependencies. +// +// Example of using Call.After to chain expected call order: +// +// firstCall := mockObj.EXPECT().SomeMethod(1, "first") +// secondCall := mockObj.EXPECT().SomeMethod(2, "second").After(firstCall) +// mockObj.EXPECT().SomeMethod(3, "third").After(secondCall) +// +// Example of using InOrder to declare expected call order: +// +// gomock.InOrder( +// mockObj.EXPECT().SomeMethod(1, "first"), +// mockObj.EXPECT().SomeMethod(2, "second"), +// mockObj.EXPECT().SomeMethod(3, "third"), +// ) +// +// The standard TestReporter most users will pass to `NewController` is a +// `*testing.T` from the context of the test. Note that this will use the +// standard `t.Error` and `t.Fatal` methods to report what happened in the test. +// In some cases this can leave your testing package in a weird state if global +// state is used since `t.Fatal` is like calling panic in the middle of a +// function. In these cases it is recommended that you pass in your own +// `TestReporter`. +package gomock diff --git a/vendor/github.com/golang/mock/gomock/matchers.go b/vendor/go.uber.org/mock/gomock/matchers.go similarity index 62% rename from vendor/github.com/golang/mock/gomock/matchers.go rename to vendor/go.uber.org/mock/gomock/matchers.go index 2822fb2c8..d52495f39 100644 --- a/vendor/github.com/golang/mock/gomock/matchers.go +++ b/vendor/go.uber.org/mock/gomock/matchers.go @@ -17,6 +17,7 @@ package gomock import ( "fmt" "reflect" + "regexp" "strings" ) @@ -24,7 +25,7 @@ import ( // It is used to represent the valid or expected arguments to a mocked method. type Matcher interface { // Matches returns whether x is a match. - Matches(x interface{}) bool + Matches(x any) bool // String describes what the matcher matches. String() string @@ -35,7 +36,7 @@ type Matcher interface { // printing . func WantFormatter(s fmt.Stringer, m Matcher) Matcher { type matcher interface { - Matches(x interface{}) bool + Matches(x any) bool } return struct { @@ -63,16 +64,16 @@ func (f StringerFunc) String() string { type GotFormatter interface { // Got is invoked with the received value. The result is used when // printing the failure message. - Got(got interface{}) string + Got(got any) string } // GotFormatterFunc type is an adapter to allow the use of ordinary // functions as a GotFormatter. If f is a function with the appropriate // signature, GotFormatterFunc(f) is a GotFormatter that calls f. -type GotFormatterFunc func(got interface{}) string +type GotFormatterFunc func(got any) string // Got implements GotFormatter. -func (f GotFormatterFunc) Got(got interface{}) string { +func (f GotFormatterFunc) Got(got any) string { return f(got) } @@ -89,7 +90,7 @@ func GotFormatterAdapter(s GotFormatter, m Matcher) Matcher { type anyMatcher struct{} -func (anyMatcher) Matches(interface{}) bool { +func (anyMatcher) Matches(any) bool { return true } @@ -97,11 +98,27 @@ func (anyMatcher) String() string { return "is anything" } +type condMatcher[T any] struct { + fn func(x T) bool +} + +func (c condMatcher[T]) Matches(x any) bool { + typed, ok := x.(T) + if !ok { + return false + } + return c.fn(typed) +} + +func (c condMatcher[T]) String() string { + return "adheres to a custom condition" +} + type eqMatcher struct { - x interface{} + x any } -func (e eqMatcher) Matches(x interface{}) bool { +func (e eqMatcher) Matches(x any) bool { // In case, some value is nil if e.x == nil || x == nil { return reflect.DeepEqual(e.x, x) @@ -120,12 +137,12 @@ func (e eqMatcher) Matches(x interface{}) bool { } func (e eqMatcher) String() string { - return fmt.Sprintf("is equal to %v (%T)", e.x, e.x) + return fmt.Sprintf("is equal to %s (%T)", getString(e.x), e.x) } type nilMatcher struct{} -func (nilMatcher) Matches(x interface{}) bool { +func (nilMatcher) Matches(x any) bool { if x == nil { return true } @@ -148,7 +165,7 @@ type notMatcher struct { m Matcher } -func (n notMatcher) Matches(x interface{}) bool { +func (n notMatcher) Matches(x any) bool { return !n.m.Matches(x) } @@ -156,11 +173,30 @@ func (n notMatcher) String() string { return "not(" + n.m.String() + ")" } +type regexMatcher struct { + regex *regexp.Regexp +} + +func (m regexMatcher) Matches(x any) bool { + switch t := x.(type) { + case string: + return m.regex.MatchString(t) + case []byte: + return m.regex.Match(t) + default: + return false + } +} + +func (m regexMatcher) String() string { + return "matches regex " + m.regex.String() +} + type assignableToTypeOfMatcher struct { targetType reflect.Type } -func (m assignableToTypeOfMatcher) Matches(x interface{}) bool { +func (m assignableToTypeOfMatcher) Matches(x any) bool { return reflect.TypeOf(x).AssignableTo(m.targetType) } @@ -168,11 +204,32 @@ func (m assignableToTypeOfMatcher) String() string { return "is assignable to " + m.targetType.Name() } +type anyOfMatcher struct { + matchers []Matcher +} + +func (am anyOfMatcher) Matches(x any) bool { + for _, m := range am.matchers { + if m.Matches(x) { + return true + } + } + return false +} + +func (am anyOfMatcher) String() string { + ss := make([]string, 0, len(am.matchers)) + for _, matcher := range am.matchers { + ss = append(ss, matcher.String()) + } + return strings.Join(ss, " | ") +} + type allMatcher struct { matchers []Matcher } -func (am allMatcher) Matches(x interface{}) bool { +func (am allMatcher) Matches(x any) bool { for _, m := range am.matchers { if !m.Matches(x) { return false @@ -193,7 +250,7 @@ type lenMatcher struct { i int } -func (m lenMatcher) Matches(x interface{}) bool { +func (m lenMatcher) Matches(x any) bool { v := reflect.ValueOf(x) switch v.Kind() { case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice, reflect.String: @@ -208,10 +265,10 @@ func (m lenMatcher) String() string { } type inAnyOrderMatcher struct { - x interface{} + x any } -func (m inAnyOrderMatcher) Matches(x interface{}) bool { +func (m inAnyOrderMatcher) Matches(x any) bool { given, ok := m.prepareValue(x) if !ok { return false @@ -257,7 +314,7 @@ func (m inAnyOrderMatcher) Matches(x interface{}) bool { return extraInGiven == 0 && missingFromWanted == 0 } -func (m inAnyOrderMatcher) prepareValue(x interface{}) (reflect.Value, bool) { +func (m inAnyOrderMatcher) prepareValue(x any) (reflect.Value, bool) { xValue := reflect.ValueOf(x) switch xValue.Kind() { case reflect.Slice, reflect.Array: @@ -280,12 +337,45 @@ func All(ms ...Matcher) Matcher { return allMatcher{ms} } // Any returns a matcher that always matches. func Any() Matcher { return anyMatcher{} } +// Cond returns a matcher that matches when the given function returns true +// after passing it the parameter to the mock function. +// This is particularly useful in case you want to match over a field of a custom struct, or dynamic logic. +// +// Example usage: +// +// Cond(func(x int){return x == 1}).Matches(1) // returns true +// Cond(func(x int){return x == 2}).Matches(1) // returns false +func Cond[T any](fn func(x T) bool) Matcher { return condMatcher[T]{fn} } + +// AnyOf returns a composite Matcher that returns true if at least one of the +// matchers returns true. +// +// Example usage: +// +// AnyOf(1, 2, 3).Matches(2) // returns true +// AnyOf(1, 2, 3).Matches(10) // returns false +// AnyOf(Nil(), Len(2)).Matches(nil) // returns true +// AnyOf(Nil(), Len(2)).Matches("hi") // returns true +// AnyOf(Nil(), Len(2)).Matches("hello") // returns false +func AnyOf(xs ...any) Matcher { + ms := make([]Matcher, 0, len(xs)) + for _, x := range xs { + if m, ok := x.(Matcher); ok { + ms = append(ms, m) + } else { + ms = append(ms, Eq(x)) + } + } + return anyOfMatcher{ms} +} + // Eq returns a matcher that matches on equality. // // Example usage: -// Eq(5).Matches(5) // returns true -// Eq(5).Matches(4) // returns false -func Eq(x interface{}) Matcher { return eqMatcher{x} } +// +// Eq(5).Matches(5) // returns true +// Eq(5).Matches(4) // returns false +func Eq(x any) Matcher { return eqMatcher{x} } // Len returns a matcher that matches on length. This matcher returns false if // is compared to a type that is not an array, chan, map, slice, or string. @@ -296,35 +386,50 @@ func Len(i int) Matcher { // Nil returns a matcher that matches if the received value is nil. // // Example usage: -// var x *bytes.Buffer -// Nil().Matches(x) // returns true -// x = &bytes.Buffer{} -// Nil().Matches(x) // returns false +// +// var x *bytes.Buffer +// Nil().Matches(x) // returns true +// x = &bytes.Buffer{} +// Nil().Matches(x) // returns false func Nil() Matcher { return nilMatcher{} } // Not reverses the results of its given child matcher. // // Example usage: -// Not(Eq(5)).Matches(4) // returns true -// Not(Eq(5)).Matches(5) // returns false -func Not(x interface{}) Matcher { +// +// Not(Eq(5)).Matches(4) // returns true +// Not(Eq(5)).Matches(5) // returns false +func Not(x any) Matcher { if m, ok := x.(Matcher); ok { return notMatcher{m} } return notMatcher{Eq(x)} } +// Regex checks whether parameter matches the associated regex. +// +// Example usage: +// +// Regex("[0-9]{2}:[0-9]{2}").Matches("23:02") // returns true +// Regex("[0-9]{2}:[0-9]{2}").Matches([]byte{'2', '3', ':', '0', '2'}) // returns true +// Regex("[0-9]{2}:[0-9]{2}").Matches("hello world") // returns false +// Regex("[0-9]{2}").Matches(21) // returns false as it's not a valid type +func Regex(regexStr string) Matcher { + return regexMatcher{regex: regexp.MustCompile(regexStr)} +} + // AssignableToTypeOf is a Matcher that matches if the parameter to the mock // function is assignable to the type of the parameter to this function. // // Example usage: -// var s fmt.Stringer = &bytes.Buffer{} -// AssignableToTypeOf(s).Matches(time.Second) // returns true -// AssignableToTypeOf(s).Matches(99) // returns false // -// var ctx = reflect.TypeOf((*context.Context)(nil)).Elem() -// AssignableToTypeOf(ctx).Matches(context.Background()) // returns true -func AssignableToTypeOf(x interface{}) Matcher { +// var s fmt.Stringer = &bytes.Buffer{} +// AssignableToTypeOf(s).Matches(time.Second) // returns true +// AssignableToTypeOf(s).Matches(99) // returns false +// +// var ctx = reflect.TypeOf((*context.Context)(nil)).Elem() +// AssignableToTypeOf(ctx).Matches(context.Background()) // returns true +func AssignableToTypeOf(x any) Matcher { if xt, ok := x.(reflect.Type); ok { return assignableToTypeOfMatcher{xt} } @@ -334,8 +439,9 @@ func AssignableToTypeOf(x interface{}) Matcher { // InAnyOrder is a Matcher that returns true for collections of the same elements ignoring the order. // // Example usage: -// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 3, 2}) // returns true -// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 2}) // returns false -func InAnyOrder(x interface{}) Matcher { +// +// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 3, 2}) // returns true +// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 2}) // returns false +func InAnyOrder(x any) Matcher { return inAnyOrderMatcher{x} } diff --git a/vendor/go.uber.org/mock/gomock/string.go b/vendor/go.uber.org/mock/gomock/string.go new file mode 100644 index 000000000..ec4ca7e4d --- /dev/null +++ b/vendor/go.uber.org/mock/gomock/string.go @@ -0,0 +1,36 @@ +package gomock + +import ( + "fmt" + "reflect" +) + +// getString is a safe way to convert a value to a string for printing results +// If the value is a a mock, getString avoids calling the mocked String() method, +// which avoids potential deadlocks +func getString(x any) string { + if isGeneratedMock(x) { + return fmt.Sprintf("%T", x) + } + if s, ok := x.(fmt.Stringer); ok { + return s.String() + } + return fmt.Sprintf("%v", x) +} + +// isGeneratedMock checks if the given type has a "isgomock" field, +// indicating it is a generated mock. +func isGeneratedMock(x any) bool { + typ := reflect.TypeOf(x) + if typ == nil { + return false + } + if typ.Kind() == reflect.Ptr { + typ = typ.Elem() + } + if typ.Kind() != reflect.Struct { + return false + } + _, isgomock := typ.FieldByName("isgomock") + return isgomock +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 8053377b6..47d14149d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -37,14 +37,14 @@ github.com/ProtonMail/go-crypto/openpgp/packet github.com/ProtonMail/go-crypto/openpgp/s2k github.com/ProtonMail/go-crypto/openpgp/x25519 github.com/ProtonMail/go-crypto/openpgp/x448 -# github.com/Scalingo/go-scalingo/v10 v10.0.0 +# github.com/Scalingo/go-scalingo/v11 v11.0.0 ## explicit; go 1.24.0 -github.com/Scalingo/go-scalingo/v10 -github.com/Scalingo/go-scalingo/v10/billing -github.com/Scalingo/go-scalingo/v10/debug -github.com/Scalingo/go-scalingo/v10/http -github.com/Scalingo/go-scalingo/v10/http/httpmock -github.com/Scalingo/go-scalingo/v10/io +github.com/Scalingo/go-scalingo/v11 +github.com/Scalingo/go-scalingo/v11/billing +github.com/Scalingo/go-scalingo/v11/debug +github.com/Scalingo/go-scalingo/v11/http +github.com/Scalingo/go-scalingo/v11/http/httpmock +github.com/Scalingo/go-scalingo/v11/io # github.com/Scalingo/go-utils/errors/v3 v3.2.0 ## explicit; go 1.24 github.com/Scalingo/go-utils/errors/v3 @@ -190,9 +190,6 @@ github.com/golang-jwt/jwt/v5 # github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 ## explicit; go 1.20 github.com/golang/groupcache/lru -# github.com/golang/mock v1.6.0 -## explicit; go 1.11 -github.com/golang/mock/gomock # github.com/google/go-github/v47 v47.1.0 ## explicit; go 1.17 github.com/google/go-github/v47/github @@ -288,6 +285,9 @@ github.com/urfave/cli/v3 # github.com/xanzy/ssh-agent v0.3.3 ## explicit; go 1.16 github.com/xanzy/ssh-agent +# go.uber.org/mock v0.6.0 +## explicit; go 1.23.0 +go.uber.org/mock/gomock # golang.org/x/crypto v0.48.0 ## explicit; go 1.24.0 golang.org/x/crypto/argon2 @@ -327,8 +327,8 @@ golang.org/x/sys/windows # golang.org/x/term v0.40.0 ## explicit; go 1.24.0 golang.org/x/term -# golang.org/x/text v0.34.0 -## explicit; go 1.24.0 +# golang.org/x/text v0.35.0 +## explicit; go 1.25.0 golang.org/x/text/cases golang.org/x/text/internal golang.org/x/text/internal/language