EnableFeature is the command handler to enable a database feature on a given database addon, like 'force-ssl' or 'public-availability'
(ctx context.Context, c *cli.Command, app, addon, feature string)
| 16 | // EnableFeature is the command handler to enable a database feature on a given |
| 17 | // database addon, like 'force-ssl' or 'public-availability' |
| 18 | func EnableFeature(ctx context.Context, c *cli.Command, app, addon, feature string) error { |
| 19 | spinner := spinner.New(spinner.CharSets[11], 100*time.Millisecond) |
| 20 | spinner.Suffix = " Enabling database feature" |
| 21 | spinner.Start() |
| 22 | defer spinner.Stop() |
| 23 | |
| 24 | client, err := config.ScalingoClient(ctx) |
| 25 | if err != nil { |
| 26 | return errors.Wrapf(ctx, err, "fail to get Scalingo client") |
| 27 | } |
| 28 | |
| 29 | res, err := client.DatabaseEnableFeature(ctx, app, addon, feature) |
| 30 | if err != nil { |
| 31 | return errors.Wrapf(ctx, err, "fail to enable feature '%v'", feature) |
| 32 | } |
| 33 | spinner.Stop() |
| 34 | |
| 35 | switch res.Status { |
| 36 | case scalingo.DatabaseFeatureStatusActivated: |
| 37 | io.Statusf("Feature %v has been enabled\n", feature) |
| 38 | case scalingo.DatabaseFeatureStatusFailed: |
| 39 | io.Warningf("Feature %v failed to get activated, please contact our support\n", feature) |
| 40 | case scalingo.DatabaseFeatureStatusPending: |
| 41 | io.Statusf("Feature %v is being enabled\n", feature) |
| 42 | default: |
| 43 | io.Status(res.Message) |
| 44 | } |
| 45 | |
| 46 | if res.Status == scalingo.DatabaseFeatureStatusPending && c.Bool("synchronous") { |
| 47 | io.Infof("Waiting for operation completion...") |
| 48 | err = waitFeatureUntilActivated(ctx, client, app, addon, feature) |
| 49 | if err != nil { |
| 50 | return errors.Wrapf(ctx, err, "fail to wait for feature '%v' to be enabled", feature) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return nil |
| 55 | } |
| 56 | |
| 57 | func waitFeatureUntilActivated(ctx context.Context, client *scalingo.Client, app, addon, feature string) error { |
| 58 | ticker := time.NewTicker(3 * time.Second) |
no test coverage detected