This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.go
84 lines (72 loc) · 1.46 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
package main
import (
"crypto/tls"
"crypto/x509"
"flag"
"io/ioutil"
"log"
"net"
"os"
"github.com/BurntSushi/toml"
"github.com/jsternberg/ansible-agent/ansible"
)
var (
flConfig = flag.String("c", "", "Server configuration file")
)
func realMain() int {
flag.Parse()
config := DefaultConfig()
if *flConfig != "" {
in, err := ioutil.ReadFile(*flConfig)
if err != nil {
log.Println(err)
return 1
}
if err := toml.Unmarshal(in, config); err != nil {
log.Println(err)
return 1
}
}
l, err := net.Listen("tcp", ":8700")
if err != nil {
log.Println(err)
return 1
}
if config.SSL.Enabled {
cert, err := tls.LoadX509KeyPair(config.SSL.Certificate, config.SSL.PrivateKey)
if err != nil {
log.Println(err)
return 1
}
tlsConfig := tls.Config{
Certificates: []tls.Certificate{cert},
ClientCAs: x509.NewCertPool(),
ClientAuth: tls.NoClientCert,
}
if config.SSL.ClientCA != "" {
data, err := ioutil.ReadFile(config.SSL.ClientCA)
if err != nil {
log.Println(err)
return 1
}
tlsConfig.ClientCAs.AppendCertsFromPEM(data)
tlsConfig.ClientAuth = tls.RequireAndVerifyClientCert
}
l = tls.NewListener(l, &tlsConfig)
}
server := ansible.NewServer()
if config.Ldap.Enabled {
if err := server.ConfigureLDAP(&config.Ldap); err != nil {
log.Println(err)
return 1
}
}
if err := server.Serve(l); err != nil {
log.Println(err)
return 1
}
return 0
}
func main() {
os.Exit(realMain())
}