forked from CenturyLinkLabs/panamax-remote-agent-go
/
main.go
88 lines (73 loc) · 1.69 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
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
package main // import "github.com/CenturyLinkLabs/panamax-remote-agent-go"
import (
"flag"
"log"
"os"
"regexp"
"github.com/CenturyLinkLabs/panamax-remote-agent-go/adapter"
"github.com/CenturyLinkLabs/panamax-remote-agent-go/agent"
"github.com/CenturyLinkLabs/panamax-remote-agent-go/api"
"github.com/CenturyLinkLabs/panamax-remote-agent-go/repo"
)
func main() {
sf := flag.Bool("secure", true, "whether or not to use SSL and BasicAuth, defaults to true")
flag.Parse()
p, err := repo.MakeDeploymentStore(dbLocation())
if err != nil {
log.Fatal(err)
}
c := adapter.MakeClient(adapterEndpoint())
dm := agent.MakeDeploymentManager(p, c, version())
s := makeServer(dm, sf)
s.Start(serverPort())
}
func makeServer(dm agent.Manager, sf *bool) api.Server {
log.Printf("secure?: %t", *sf)
if *sf {
return api.MakeServer(
dm,
username(),
password(),
certFile(),
keyFile(),
)
}
return api.MakeInsecureServer(dm)
}
func version() string {
return os.Getenv("REMOTE_AGENT_VERSION")
}
func username() string {
return os.Getenv("REMOTE_AGENT_ID")
}
func password() string {
return os.Getenv("REMOTE_AGENT_API_KEY")
}
func keyFile() string {
return "/usr/local/share/certs/pmx_remote_agent.key"
}
func certFile() string {
return "/usr/local/share/certs/pmx_remote_agent.crt"
}
func dbLocation() string {
l := os.Getenv("DB_LOCATION")
if l == "" {
l = "db/agent.db"
}
return l
}
func serverPort() string {
p := os.Getenv("SERVER_PORT")
if p == "" {
p = "3000"
}
return ":" + p
}
func adapterEndpoint() string {
url := os.Getenv("ADAPTER_PORT")
if url == "" {
url = "tcp://localhost:3001"
}
r, _ := regexp.Compile("^tcp")
return r.ReplaceAllString(url, "http")
}