MCPcopy Create free account
hub / github.com/Scalingo/cli / EnableFeature

Function EnableFeature

db/features.go:18–55  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

16// EnableFeature is the command handler to enable a database feature on a given
17// database addon, like 'force-ssl' or 'public-availability'
18func 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
57func waitFeatureUntilActivated(ctx context.Context, client *scalingo.Client, app, addon, feature string) error {
58 ticker := time.NewTicker(3 * time.Second)

Callers 1

databases.goFile · 0.92

Calls 8

ScalingoClientFunction · 0.92
StatusfFunction · 0.92
WarningfFunction · 0.92
StatusFunction · 0.92
InfofFunction · 0.92
StartMethod · 0.80
StopMethod · 0.80

Tested by

no test coverage detected