-
Notifications
You must be signed in to change notification settings - Fork 54
/
config.go
77 lines (61 loc) · 1.69 KB
/
config.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
package engine
import (
"encoding/json"
"io/ioutil"
"os"
"github.com/project-flogo/core/support"
)
// Config is the configuration for the Engine, assumes all necessary imports have been add to go code
type Config struct {
Name string `json:"name"`
Type string `json:"type"`
Description string `json:"description"`
StopEngineOnError bool `json:"stopEngineOnError,omitempty"`
RunnerType string `json:"runnerType,omitempty"`
Imports []string `json:"imports,omitempty"`
ActionSettings map[string]map[string]interface{} `json:"actionSettings,omitempty"`
Services []*ServiceConfig `json:"services,omitempty"`
}
// ServiceConfig is the configuration for Engine Services
type ServiceConfig struct {
Ref string
Enabled bool
Settings map[string]interface{}
}
func LoadEngineConfig(engineJson string, compressed bool) (*Config, error) {
var jsonBytes []byte
if engineJson == "" {
// a json string wasn't provided, so lets lookup the file in path
configPath := GetFlogoEngineConfigPath()
if _, err := os.Stat(configPath); err == nil {
flogo, err := os.Open(configPath)
if err != nil {
return nil, err
}
jsonBytes, err = ioutil.ReadAll(flogo)
if err != nil {
return nil, err
}
}
} else {
if compressed {
var err error
jsonBytes, err = support.DecodeAndUnzip(engineJson)
if err != nil {
return nil, err
}
} else {
jsonBytes = []byte(engineJson)
}
}
cfg := &Config{}
cfg.StopEngineOnError = StopEngineOnError()
cfg.RunnerType = GetRunnerType()
if jsonBytes != nil {
err := json.Unmarshal(jsonBytes, &cfg)
if err != nil {
return nil, err
}
}
return cfg, nil
}