-
Notifications
You must be signed in to change notification settings - Fork 69
/
script_evaluator.go
51 lines (40 loc) · 1.35 KB
/
script_evaluator.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
package recipes
import (
"context"
log "github.com/sirupsen/logrus"
"github.com/newrelic/newrelic-cli/internal/install/execution"
"github.com/newrelic/newrelic-cli/internal/install/types"
"github.com/newrelic/newrelic-cli/internal/utils"
)
type ScriptEvaluator struct {
executor execution.RecipeExecutor
}
func NewScriptEvaluator() *ScriptEvaluator {
return newScriptEvaluator(execution.NewShRecipeExecutor())
}
func newScriptEvaluator(executor execution.RecipeExecutor) *ScriptEvaluator {
return &ScriptEvaluator{
executor: executor,
}
}
func (se *ScriptEvaluator) DetectionStatus(ctx context.Context, r *types.OpenInstallationRecipe) (statusResult execution.RecipeStatusType) {
defer func() {
if err := recover(); err != nil {
log.Debugf("recipe %s failed script evaluation with panic %s", r.Name, err)
statusResult = execution.RecipeStatusTypes.NULL
}
}()
if err := se.executor.ExecutePreInstall(ctx, *r, types.RecipeVars{}); err != nil {
log.Debugf("recipe %s failed script evaluation %s", r.Name, err)
if utils.IsExitStatusCode(132, err) {
statusResult = execution.RecipeStatusTypes.DETECTED
} else if utils.IsExitStatusCode(131, err) {
statusResult = execution.RecipeStatusTypes.UNSUPPORTED
} else {
statusResult = execution.RecipeStatusTypes.NULL
}
return
}
statusResult = execution.RecipeStatusTypes.AVAILABLE
return
}