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

Function Provision

addons/provision.go:13–55  ·  view source on GitHub ↗
(ctx context.Context, app, addon, plan string)

Source from the content-addressed store, hash-verified

11)
12
13func Provision(ctx context.Context, app, addon, plan string) error {
14 if app == "" {
15 return errors.New(ctx, "no app defined")
16 } else if addon == "" {
17 return errors.New(ctx, "no addon defined")
18 } else if plan == "" {
19 return errors.New(ctx, "no plan defined")
20 }
21
22 c, err := config.ScalingoClient(ctx)
23 if err != nil {
24 return errors.Wrapf(ctx, err, "fail to get Scalingo client")
25 }
26
27 planID, err := utils.FindPlan(ctx, c, addon, plan)
28 if err != nil {
29 return errors.Wrap(ctx, err, "find plan")
30 }
31
32 params, err := c.AddonProvision(ctx, app, scalingo.AddonProvisionParams{
33 AddonProviderID: addon,
34 PlanID: planID,
35 })
36 if err != nil {
37 if !utils.IsPaymentRequiredAndFreeTrialExceededError(err) {
38 return errors.Wrapf(ctx, err, "Fail to provision addon %v", addon)
39 }
40 // If error is Payment Required and user tries to exceed its free trial
41 return utils.AskAndStopFreeTrial(ctx, c, func() error {
42 return Provision(ctx, app, addon, plan)
43 })
44 }
45
46 io.Status("Addon", addon, "has been provisionned")
47 io.Info("ID:", params.Addon.ResourceID)
48 if len(params.Variables) > 0 {
49 io.Info("Modified variables:", params.Variables)
50 }
51 if len(params.Message) > 0 {
52 io.Info("Message from addon provider:", params.Message)
53 }
54 return nil
55}

Callers 1

addons.goFile · 0.92

Calls 6

ScalingoClientFunction · 0.92
FindPlanFunction · 0.92
AskAndStopFreeTrialFunction · 0.92
StatusFunction · 0.92
InfoFunction · 0.92

Tested by

no test coverage detected