-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
54 lines (48 loc) · 1.23 KB
/
main.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
package main
import (
"errors"
"log"
"net/http"
"os"
"path/filepath"
"strings"
"github.com/uc-cdis/hatchery/hatchery"
)
func verifyPath(path string) (string, error) {
c := filepath.Clean(path)
r, err := filepath.EvalSymlinks(c)
if err != nil {
return c, errors.New("Unsafe or invalid path specified")
}
return r, nil
}
func main() {
configPath := "/hatchery.json"
if len(os.Args) > 2 && strings.HasSuffix(os.Args[1], "-config") {
configPath = os.Args[2]
} else if len(os.Args) > 1 {
os.Stderr.WriteString(
`Use: hatchery -config path/to/hatchery.json
- also harvests dockstore/bla.yml app definitions where dockstore/
is in the same folder as hatchery.json
`)
return
}
logger := log.New(os.Stdout, "", log.LstdFlags)
cleanPath, err := verifyPath(configPath)
if err != nil {
logger.Printf("Failed to load config - got %s", err.Error())
return
}
config, err := hatchery.LoadConfig(cleanPath, logger)
if err != nil {
config.Logger.Printf("Failed to load config - got %s", err.Error())
return
}
hatchery.Config = config
config.Logger.Printf("Setting up routes")
hatchery.RegisterSystem()
hatchery.RegisterHatchery()
config.Logger.Printf("Running main")
log.Fatal(http.ListenAndServe("0.0.0.0:8000", nil))
}