-
Notifications
You must be signed in to change notification settings - Fork 9
/
installer.go
117 lines (92 loc) · 2.78 KB
/
installer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package bundle
import (
"fmt"
"os"
"github.com/inancgumus/screen"
"github.com/pluralsh/plural-cli/pkg/api"
"github.com/pluralsh/plural-cli/pkg/bundle/tests"
"github.com/pluralsh/plural-cli/pkg/manifest"
"github.com/pluralsh/plural-cli/pkg/utils"
)
func Install(client api.Client, repo, name string, refresh bool) error {
recipe, err := client.GetRecipe(repo, name)
if err != nil {
return api.GetErrorResponse(err, "GetRecipe")
}
return doInstall(client, recipe, repo, name, refresh)
}
func doInstall(client api.Client, recipe *api.Recipe, repo, name string, refresh bool) error {
if recipe.Restricted && os.Getenv("CLOUD_SHELL") == "1" {
return fmt.Errorf("Cannot install this bundle for %s in cloud shell, this is often because it requires a file locally available on your machine like a git ssh key", repo)
}
path := manifest.ContextPath()
context, err := manifest.ReadContext(path)
if err != nil {
context = manifest.NewContext()
}
context.AddBundle(repo, name)
for _, section := range recipe.RecipeSections {
screen.Clear()
screen.MoveTopLeft()
utils.Highlight(section.Repository.Name)
fmt.Printf(" %s\n", section.Repository.Description)
ctx, ok := context.Configuration[section.Repository.Name]
if !ok {
ctx = map[string]interface{}{}
}
seen := make(map[string]bool)
for _, configItem := range section.Configuration {
if seen[configItem.Name] {
continue
}
if _, ok := ctx[configItem.Name]; ok && !refresh {
continue
}
seen[configItem.Name] = true
if err := Configure(ctx, configItem, context, repo); err != nil {
context.Configuration[section.Repository.Name] = ctx
if err := context.Write(path); err != nil {
return err
}
return err
}
}
context.Configuration[section.Repository.Name] = ctx
}
err = context.Write(path)
if err != nil {
return err
}
if err := performTests(context, recipe); err != nil {
return err
}
if err := client.InstallRecipe(recipe.Id); err != nil {
return fmt.Errorf("Install failed, does your plural user have install permissions? error: %w", api.GetErrorResponse(err, "InstallRecipe"))
}
if recipe.OidcSettings == nil {
return nil
}
confirm := false
if err := ConfigureOidc(repo, client, recipe, context.Configuration[repo], &confirm); err != nil {
return err
}
for _, r := range recipe.RecipeDependencies {
repo := r.Repository.Name
if err := ConfigureOidc(repo, client, r, context.Configuration[repo], &confirm); err != nil {
return err
}
}
return nil
}
func performTests(ctx *manifest.Context, recipe *api.Recipe) error {
if len(recipe.Tests) == 0 {
return nil
}
utils.Highlight("Found %d tests to run...\n", len(recipe.Tests))
for _, test := range recipe.Tests {
if err := tests.Perform(ctx, test); err != nil {
return err
}
}
return nil
}