-
Notifications
You must be signed in to change notification settings - Fork 70
/
install_context.go
62 lines (54 loc) · 1.31 KB
/
install_context.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
package types
import (
"os"
"strings"
)
const (
ApmKeyword = "Apm"
DeployedByTagKey = "nr_deployed_by"
DefaultDeployedBy = "newrelic-cli"
TagSeparator = ":"
BuiltinTags = DeployedByTagKey + TagSeparator + DefaultDeployedBy
EnvInstallCustomAttributes = "INSTALL_CUSTOM_ATTRIBUTES"
)
// nolint: maligned
type InstallerContext struct {
AssumeYes bool
RecipeNames []string
RecipePaths []string
// LocalRecipes is the path to a local recipe directory from which to load recipes.
LocalRecipes string
deployedBy string
}
func (i *InstallerContext) RecipePathsProvided() bool {
return len(i.RecipePaths) > 0
}
func (i *InstallerContext) RecipeNamesProvided() bool {
return len(i.RecipeNames) > 0
}
func (i *InstallerContext) SetTags(tags []string) {
csv := ""
for _, value := range tags {
parts := strings.Split(value, TagSeparator)
if len(parts) == 2 {
if parts[0] == DeployedByTagKey {
i.deployedBy = parts[1]
}
if len(csv) > 0 {
csv += ","
}
csv += value
}
}
if !strings.Contains(csv, DeployedByTagKey) {
i.deployedBy = DefaultDeployedBy
if len(csv) > 0 {
csv += ","
}
csv += BuiltinTags
}
os.Setenv(EnvInstallCustomAttributes, csv)
}
func (i *InstallerContext) GetDeployedBy() string {
return i.deployedBy
}