-
Notifications
You must be signed in to change notification settings - Fork 23
/
conf.go
156 lines (135 loc) · 4.62 KB
/
conf.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Package conf parses start up args and config file
package conf
import (
"flag"
"fmt"
"github.com/MG-RAST/golib/goconfig/config"
"os"
"strconv"
"strings"
)
type idxOpts struct {
unique bool
dropDups bool
sparse bool
}
var (
Conf = map[string]string{}
// Reload
RELOAD = ""
// Config File
CONFIG_FILE = ""
// Node Indices
NODE_IDXS map[string]idxOpts = nil
// Default Chunksize for size virtual index
CHUNK_SIZE int64 = 1048576
)
// Initialize is an explicit init. Enables outside use
// of shock-server packages. Parses config and populates
// the Conf variable.
func Initialize() {
flag.StringVar(&CONFIG_FILE, "conf", "/usr/local/shock/conf/shock.cfg", "path to config file")
flag.StringVar(&RELOAD, "reload", "", "path or url to shock data. WARNING this will drop all current data.")
flag.Parse()
c, err := config.ReadDefault(CONFIG_FILE)
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: error reading conf file: %v\n", err)
os.Exit(1)
}
// Address
Conf["api-ip"], _ = c.String("Address", "api-ip")
Conf["api-port"], _ = c.String("Address", "api-port")
// URLs
Conf["api-url"], _ = c.String("External", "api-url")
// SSL
Conf["ssl"], _ = c.String("SSL", "enable")
if Bool(Conf["ssl"]) {
Conf["ssl-key"], _ = c.String("SSL", "key")
Conf["ssl-cert"], _ = c.String("SSL", "cert")
}
// Access-Control
Conf["anon-write"], _ = c.String("Anonymous", "write")
Conf["anon-read"], _ = c.String("Anonymous", "read")
Conf["anon-user"], _ = c.String("Anonymous", "create-user")
// Auth
Conf["basic_auth"], _ = c.String("Auth", "basic")
Conf["globus_token_url"], _ = c.String("Auth", "globus_token_url")
Conf["globus_profile_url"], _ = c.String("Auth", "globus_profile_url")
Conf["mgrast_oauth_url"], _ = c.String("Auth", "mgrast_oauth_url")
// Admin
Conf["admin-email"], _ = c.String("Admin", "email")
Conf["admin-users"], _ = c.String("Admin", "users")
// Paths
Conf["site-path"], _ = c.String("Paths", "site")
Conf["data-path"], _ = c.String("Paths", "data")
Conf["logs-path"], _ = c.String("Paths", "logs")
Conf["local-paths"], _ = c.String("Paths", "local_paths")
Conf["pidfile"], _ = c.String("Paths", "pidfile")
// Runtime
Conf["GOMAXPROCS"], _ = c.String("Runtime", "GOMAXPROCS")
// Mongodb
Conf["mongodb-hosts"], _ = c.String("Mongodb", "hosts")
if Conf["mongodb-database"], err = c.String("Mongodb", "database"); err != nil {
fmt.Fprintf(os.Stderr, "ERROR: Mongodb database must be set in config file.")
os.Exit(1)
}
Conf["mongodb-user"], _ = c.String("Mongodb", "user")
Conf["mongodb-password"], _ = c.String("Mongodb", "password")
Conf["mongodb-attribute-indexes"], _ = c.String("Mongodb", "attribute_indexes")
// parse Node-Indices
NODE_IDXS = map[string]idxOpts{}
nodeIdx, _ := c.Options("Node-Indices")
for _, opt := range nodeIdx {
val, _ := c.String("Node-Indices", opt)
opts := idxOpts{}
for _, parts := range strings.Split(val, ",") {
p := strings.Split(parts, ":")
if p[0] == "unique" {
if p[1] == "true" {
opts.unique = true
} else {
opts.unique = false
}
} else if p[0] == "dropDups" {
if p[1] == "true" {
opts.dropDups = true
} else {
opts.dropDups = false
}
} else if p[0] == "sparse" {
if p[1] == "true" {
opts.sparse = true
} else {
opts.sparse = false
}
}
}
NODE_IDXS[opt] = opts
}
Conf["perf-log"], _ = c.String("Log", "perf_log")
}
// Bool is a convenience wrapper around strconv.ParseBool
func Bool(s string) bool {
b, _ := strconv.ParseBool(s)
return b
}
// Print prints the configuration loads to stdout
func Print() {
fmt.Printf("####### Anonymous ######\nread:\t%s\nwrite:\t%s\ncreate-user:\t%s\n\n", Conf["anon-read"], Conf["anon-write"], Conf["anon-user"])
if Conf["auth-type"] == "basic" {
fmt.Printf("##### Auth #####\ntype:\tbasic\n\n")
} else if Conf["auth-type"] == "globus" {
fmt.Printf("##### Auth #####\ntype:\tglobus\ntoken_url:\t%s\nprofile_url:\t%s\n\n", Conf["globus_token_url"], Conf["globus_profile_url"])
}
fmt.Printf("##### Paths #####\nsite:\t%s\ndata:\t%s\nlogs:\t%s\nlocal_paths:\t%s\n\n", Conf["site-path"], Conf["data-path"], Conf["logs-path"], Conf["local-paths"])
if Bool(Conf["ssl"]) {
fmt.Printf("##### SSL #####\nenabled:\t%s\nkey:\t%s\ncert:\t%s\n\n", Conf["ssl"], Conf["ssl-key"], Conf["ssl-cert"])
} else {
fmt.Printf("##### SSL #####\nenabled:\t%s\n\n", Conf["ssl"])
}
fmt.Printf("##### Mongodb #####\nhost(s):\t%s\ndatabase:\t%s\n\n", Conf["mongodb-hosts"], Conf["mongodb-database"])
fmt.Printf("##### Address #####\nip:\t%s\nport:\t%s\n\n", Conf["api-ip"], Conf["api-port"])
if Bool(Conf["perf-log"]) {
fmt.Printf("##### PerfLog enabled #####\n\n")
}
}