Skip to content

Commit

Permalink
Merge pull request #932 from Scalingo/fix/931/consent_for_modifications
Browse files Browse the repository at this point in the history
fix(consent) Add consent for more commands
  • Loading branch information
john-scalingo authored Apr 12, 2023
2 parents f7b2a03 + 7d2f247 commit 90f1a99
Show file tree
Hide file tree
Showing 20 changed files with 113 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/Scalingo/cli/addons"
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/Scalingo/cli/detect"
"github.com/Scalingo/cli/utils"
)

var (
Expand Down Expand Up @@ -54,6 +55,8 @@ var (
return cli.ShowCommandHelp(c, "addons-add")
}

utils.CheckForConsent(c.Context, currentApp)

err := addons.Provision(c.Context, currentApp, c.Args().First(), c.Args().Slice()[1])
if err != nil {
errorQuit(err)
Expand Down Expand Up @@ -84,6 +87,8 @@ var (
return cli.ShowCommandHelp(c, "addons-remove")
}

utils.CheckForConsent(c.Context, currentApp)

err := addons.Destroy(c.Context, currentApp, c.Args().First())
if err != nil {
errorQuit(err)
Expand Down
16 changes: 16 additions & 0 deletions cmd/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/Scalingo/cli/alerts"
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/Scalingo/cli/detect"
"github.com/Scalingo/cli/utils"
scalingo "github.com/Scalingo/go-scalingo/v6"
)

Expand Down Expand Up @@ -71,6 +72,9 @@ var (
}

currentApp := detect.CurrentApp(c)

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

remindEvery := c.Duration("r")
durationBeforeTrigger := c.Duration("duration-before-trigger")
err := alerts.Add(c.Context, currentApp, scalingo.AlertAddParams{
Expand Down Expand Up @@ -128,6 +132,9 @@ var (

alertID := c.Args().First()
currentApp := detect.CurrentApp(c)

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

params := scalingo.AlertUpdateParams{}
if c.IsSet("c") {
ct := c.String("c")
Expand Down Expand Up @@ -195,6 +202,9 @@ var (
}

currentApp := detect.CurrentApp(c)

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

disabled := false
err := alerts.Update(c.Context, currentApp, c.Args().First(), scalingo.AlertUpdateParams{
Disabled: &disabled,
Expand Down Expand Up @@ -231,6 +241,9 @@ var (
}

currentApp := detect.CurrentApp(c)

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

disabled := true
err := alerts.Update(c.Context, currentApp, c.Args().First(), scalingo.AlertUpdateParams{
Disabled: &disabled,
Expand Down Expand Up @@ -263,6 +276,9 @@ var (
}

currentApp := detect.CurrentApp(c)

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

err := alerts.Remove(c.Context, currentApp, c.Args().First())
if err != nil {
errorQuit(err)
Expand Down
19 changes: 19 additions & 0 deletions cmd/autoscalers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/Scalingo/cli/autoscalers"
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/Scalingo/cli/detect"
"github.com/Scalingo/cli/utils"
"github.com/Scalingo/go-scalingo/v6"
)

Expand All @@ -21,6 +22,9 @@ var (
cli.ShowCommandHelp(c, "autoscalers")
return nil
}
currentApp := detect.CurrentApp(c)

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

err := autoscalers.List(c.Context, detect.CurrentApp(c))
if err != nil {
Expand Down Expand Up @@ -59,6 +63,9 @@ var (
}

currentApp := detect.CurrentApp(c)

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

err := autoscalers.Add(c.Context, currentApp, scalingo.AutoscalerAddParams{
ContainerType: c.String("c"),
Metric: c.String("m"),
Expand Down Expand Up @@ -106,6 +113,9 @@ var (
}

currentApp := detect.CurrentApp(c)

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

params := scalingo.AutoscalerUpdateParams{}
if c.IsSet("m") {
m := c.String("m")
Expand Down Expand Up @@ -158,6 +168,9 @@ var (
}

currentApp := detect.CurrentApp(c)

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

disabled := false
err := autoscalers.Update(c.Context, currentApp, c.Args().First(), scalingo.AutoscalerUpdateParams{
Disabled: &disabled,
Expand Down Expand Up @@ -193,6 +206,9 @@ var (
}

currentApp := detect.CurrentApp(c)

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

disabled := true
err := autoscalers.Update(c.Context, currentApp, c.Args().First(), scalingo.AutoscalerUpdateParams{
Disabled: &disabled,
Expand Down Expand Up @@ -225,6 +241,9 @@ var (
}

currentApp := detect.CurrentApp(c)

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

err := autoscalers.Remove(c.Context, currentApp, c.Args().First())
if err != nil {
errorQuit(err)
Expand Down
2 changes: 2 additions & 0 deletions cmd/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ var (
currentApp := detect.CurrentApp(c)
addonName := addonNameFromFlags(c, true)

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeDBs)

err := db.CreateBackup(c.Context, currentApp, addonName)
if err != nil {
errorQuit(err)
Expand Down
3 changes: 3 additions & 0 deletions cmd/collaborators.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/Scalingo/cli/collaborators"
"github.com/Scalingo/cli/detect"
"github.com/Scalingo/cli/utils"
)

var (
Expand Down Expand Up @@ -47,6 +48,7 @@ var (
if c.Args().Len() != 1 {
cli.ShowCommandHelp(c, "collaborators-add")
} else {
utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)
err := collaborators.Add(c.Context, currentApp, c.Args().First())
if err != nil {
errorQuit(err)
Expand Down Expand Up @@ -75,6 +77,7 @@ var (
if c.Args().Len() != 1 {
cli.ShowCommandHelp(c, "collaborators-remove")
} else {
utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)
err := collaborators.Remove(c.Context, currentApp, c.Args().First())
if err != nil {
errorQuit(err)
Expand Down
4 changes: 4 additions & 0 deletions cmd/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/Scalingo/cli/db"
"github.com/Scalingo/cli/detect"
"github.com/Scalingo/cli/utils"
"github.com/Scalingo/go-scalingo/v6"
)

Expand All @@ -35,6 +36,7 @@ var (

Action: func(c *cli.Context) error {
currentApp := detect.CurrentApp(c)
utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeDBs)
addonName := addonNameFromFlags(c, true)
if c.NArg() != 1 {
errorQuit(errors.New("feature argument should be specified"))
Expand Down Expand Up @@ -64,6 +66,7 @@ var (

Action: func(c *cli.Context) error {
currentApp := detect.CurrentApp(c)
utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeDBs)
addonName := addonNameFromFlags(c, true)
if c.NArg() != 1 {
errorQuit(errors.New("feature argument should be specified"))
Expand Down Expand Up @@ -100,6 +103,7 @@ var (

Action: func(c *cli.Context) error {
currentApp := detect.CurrentApp(c)
utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeDBs)
addonName := addonNameFromFlags(c, true)

params := scalingo.DatabaseUpdatePeriodicBackupsConfigParams{}
Expand Down
7 changes: 5 additions & 2 deletions cmd/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/Scalingo/cli/deployments"
"github.com/Scalingo/cli/detect"
"github.com/Scalingo/cli/utils"
scalingo "github.com/Scalingo/go-scalingo/v6"
"github.com/Scalingo/go-scalingo/v6/io"
)
Expand All @@ -28,6 +29,7 @@ var (
cli.ShowCommandHelp(c, "deployment-delete-cache")
} else {
currentApp := detect.CurrentApp(c)
utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)
err := deployments.ResetCache(c.Context, currentApp)
if err != nil {
errorQuit(err)
Expand Down Expand Up @@ -121,8 +123,8 @@ var (
},
Description: CommandDescription{
Description: `Trigger the deployment of a custom archive for your application.
The version reference is optional (generated from timestamp if none).
The version reference is optional (generated from timestamp if none).
It is a reference to the code you are deploying, version, commit SHA, etc.`,
Examples: []string{
"scalingo --app my-app deploy archive.tar.gz v1.0.0",
Expand All @@ -145,6 +147,7 @@ It is a reference to the code you are deploying, version, commit SHA, etc.`,
gitRef = args.Slice()[1]
}
currentApp := detect.CurrentApp(c)
utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)
opts := deployments.DeployOpts{NoFollow: c.Bool("no-follow")}
if c.Bool("war") || strings.HasSuffix(archivePath, ".war") {
io.Status(fmt.Sprintf("Deploying WAR archive: %s", archivePath))
Expand Down
2 changes: 2 additions & 0 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/Scalingo/cli/apps"
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/Scalingo/cli/detect"
"github.com/Scalingo/cli/utils"
)

var (
Expand Down Expand Up @@ -36,6 +37,7 @@ var (
currentApp = detect.CurrentApp(c)
}

utils.CheckForConsent(c.Context, currentApp)
err := apps.Destroy(c.Context, currentApp, c.Bool("force"))
if err != nil {
errorQuit(err)
Expand Down
7 changes: 7 additions & 0 deletions cmd/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/Scalingo/cli/detect"
"github.com/Scalingo/cli/domains"
"github.com/Scalingo/cli/utils"
)

var (
Expand Down Expand Up @@ -56,6 +57,7 @@ var (

Action: func(c *cli.Context) error {
currentApp := detect.CurrentApp(c)
utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)
var err error
if c.Args().Len() == 1 {
cert := c.String("cert")
Expand Down Expand Up @@ -95,6 +97,7 @@ var (

Action: func(c *cli.Context) error {
currentApp := detect.CurrentApp(c)
utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)
var err error
if c.Args().Len() == 1 {
err = domains.Remove(c.Context, currentApp, c.Args().First())
Expand Down Expand Up @@ -134,6 +137,7 @@ var (

Action: func(c *cli.Context) error {
currentApp := detect.CurrentApp(c)
utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)
var err error
if c.Args().Len() == 2 && c.Args().Slice()[1] == "disable" {
err = domains.DisableSSL(c.Context, currentApp, c.Args().First())
Expand Down Expand Up @@ -171,6 +175,7 @@ This domain is called the canonical domain. This command sets the canonical doma
cli.ShowCommandHelp(c, "set-canonical-domain")
return nil
}
utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

err := domains.SetCanonical(c.Context, currentApp, c.Args().First())
if err != nil {
Expand Down Expand Up @@ -201,6 +206,8 @@ This domain is called the canonical domain. This command sets the canonical doma
return nil
}

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

err := domains.UnsetCanonical(c.Context, currentApp)
if err != nil {
errorQuit(err)
Expand Down
9 changes: 9 additions & 0 deletions cmd/integration_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/Scalingo/cli/integrationlink"
"github.com/Scalingo/cli/io"
"github.com/Scalingo/cli/scmintegrations"
"github.com/Scalingo/cli/utils"
"github.com/Scalingo/go-scalingo/v6"
"github.com/Scalingo/go-scalingo/v6/http"
scalingoerrors "github.com/Scalingo/go-utils/errors/v2"
Expand Down Expand Up @@ -98,6 +99,7 @@ List of available integrations:
}

currentApp := detect.CurrentApp(c)
utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)
integrationURL := c.Args().First()
integrationURLParsed, err := url.Parse(integrationURL)
if err != nil {
Expand Down Expand Up @@ -299,6 +301,7 @@ List of available integrations:
}

currentApp := detect.CurrentApp(c)
utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)
params := integrationlink.CheckAndFillParams(c)

if allowReviewAppsFromForks && !awareOfSecurityRisks {
Expand Down Expand Up @@ -338,6 +341,9 @@ List of available integrations:
}

currentApp := detect.CurrentApp(c)

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

err := integrationlink.Delete(c.Context, currentApp)
if err != nil {
errorQuit(err)
Expand Down Expand Up @@ -401,6 +407,9 @@ List of available integrations:
}

currentApp := detect.CurrentApp(c)

utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeContainers)

pullRequestID := c.Args().First()

err := integrationlink.ManualReviewApp(c.Context, currentApp, pullRequestID)
Expand Down
7 changes: 7 additions & 0 deletions cmd/log_drains.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/Scalingo/cli/detect"
"github.com/Scalingo/cli/logdrains"
"github.com/Scalingo/cli/utils"
"github.com/Scalingo/go-scalingo/v6"
)

Expand Down Expand Up @@ -40,6 +41,8 @@ Use the parameter "--with-addons" to list log drains of all addons connected to
return nil
}

utils.CheckForConsent(c.Context, currentApp)

addonID := addonNameFromFlags(c)

err := logdrains.List(c.Context, currentApp, logdrains.ListAddonOpts{
Expand Down Expand Up @@ -104,6 +107,8 @@ Warning: At the moment, only databases addons are able to forward logs to a drai

addonID := addonNameFromFlags(c)

utils.CheckForConsent(c.Context, currentApp)

if addonID != "" && (c.Bool("with-addons") || c.Bool("with-databases")) {
cli.ShowCommandHelp(c, "log-drains-add")
return nil
Expand Down Expand Up @@ -176,6 +181,8 @@ Warning: At the moment, only databases addons are able to forward logs to a drai
return nil
}

utils.CheckForConsent(c.Context, currentApp)

message := "This operation will delete the log drain " + drain
if addonID == "" && !c.Bool("only-app") {
// addons + app
Expand Down
Loading

0 comments on commit 90f1a99

Please sign in to comment.