-
Notifications
You must be signed in to change notification settings - Fork 70
/
script_evaluator.go
43 lines (32 loc) · 1.09 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
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) execution.RecipeStatusType {
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) {
return execution.RecipeStatusTypes.DETECTED
}
if utils.IsExitStatusCode(131, err) {
return execution.RecipeStatusTypes.UNSUPPORTED
}
return execution.RecipeStatusTypes.NULL
}
return execution.RecipeStatusTypes.AVAILABLE
}