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

Function Provision

notifiers/create.go:19–73  ·  view source on GitHub ↗
(ctx context.Context, app, platformName string, params ProvisionParams)

Source from the content-addressed store, hash-verified

17}
18
19func Provision(ctx context.Context, app, platformName string, params ProvisionParams) error {
20 c, err := config.ScalingoClient(ctx)
21 if err != nil {
22 return errors.Wrapf(ctx, err, "fail to get Scalingo client")
23 }
24 debug.Printf("[Provision] params: %+v", params)
25
26 if app == "" {
27 return errors.New(ctx, "no app defined")
28 }
29 if platformName == "" {
30 return errors.New(ctx, "no platform defined")
31 }
32
33 eventTypes, err := c.EventTypesList(ctx)
34 if err != nil {
35 return errors.Wrapf(ctx, err, "fail to list event types")
36 }
37 for _, name := range params.SelectedEventNames {
38 for _, t := range eventTypes {
39 if t.Name == name {
40 params.SelectedEventIDs = append(params.SelectedEventIDs, t.ID)
41 break
42 }
43 }
44 }
45
46 if len(params.CollaboratorUsernames) > 0 {
47 params.UserIDs, err = collaboratorUserIDs(ctx, c, app, params.CollaboratorUsernames)
48 if err != nil {
49 return errors.Wrapf(ctx, err, "invalid collaborator usernames")
50 }
51 }
52
53 platforms, err := c.NotificationPlatformByName(ctx, platformName)
54 if err != nil {
55 return errors.Wrapf(ctx, err, "find notification platform %s", platformName)
56 }
57 if len(platforms) <= 0 {
58 return errors.Newf(ctx, "notification platform \"%s\" has not been found", platformName)
59 }
60 params.PlatformID = platforms[0].ID
61
62 baseNotifier, err := c.NotifierProvision(ctx, app, params.NotifierParams)
63 if err != nil {
64 return errors.Wrapf(ctx, err, "create notifier on app %s", app)
65 }
66 notifier := baseNotifier.Specialize()
67
68 displayDetails(notifier, eventTypes)
69
70 io.Info()
71 io.Status("Notifier has been created.")
72 return nil
73}
74
75func collaboratorUserIDs(ctx context.Context, c *scalingo.Client, app string, usernames []string) ([]string, error) {
76 ids := make([]string, 0, len(usernames))

Callers 1

notifiers.goFile · 0.92

Calls 5

ScalingoClientFunction · 0.92
InfoFunction · 0.92
StatusFunction · 0.92
collaboratorUserIDsFunction · 0.85
displayDetailsFunction · 0.85

Tested by

no test coverage detected