forked from forj-oss/forjj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forjj-options.go
69 lines (58 loc) · 1.7 KB
/
forjj-options.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
package main
import (
"github.com/forj-oss/forjj-modules/trace"
)
const (
forjj_options_file = "Forjfile.yml"
)
// This data structure is going to be saved in the infra repository anytime a global update is done.
type ForjjOptions struct {
Defaults map[string]string
//Drivers map[string]*drivers.Driver
}
func (a *Forj) GetUniqDriverName(driverType string) (od string) {
var found_one_driver *string
for instance, d := range a.drivers {
if d.DriverType == driverType {
switch {
case found_one_driver == nil:
found_one_driver = &od
od = instance
case *found_one_driver != "":
od = ""
}
}
}
switch {
case found_one_driver == nil:
gotrace.Trace("No %s instance found.", driverType)
case *found_one_driver == "":
gotrace.Trace("Too many %s instances found.", driverType)
default:
gotrace.Trace("One upstream instance found: %s", *found_one_driver)
}
return
}
// SetDefault Forjj-option: Set default
// - instance
// - flow
func (a *Forj) SetDefault(action string) {
if od := a.GetUniqDriverName("upstream"); od != "" {
a.o.Defaults["instance"] = od
}
// Set Defaults for repositories.
if v, found, _, _ := a.cli.GetStringValue(infra, "", flow_obj); found && v != "" {
a.o.Defaults[flow_obj] = v
}
}
// LoadForge loads the forjj options definitions from the LoadContext().
func (a *Forj) LoadForge() (err error) {
if v := a.forjfile_tmpl_path; v != "" && a.w.InfraPath() == v {
gotrace.Info("If your Forfile template has defined local settings and/or credentials data, those data will " +
"be moved to the internal forjj workspace.")
return
}
deployTo, _, _ := a.GetPrefs(deployToArg) // cli or Forjfile(empty) or cli default
_, err = a.f.Load(deployTo)
return
}