Also use config from environment
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
7de1404f4d
commit
ee30a37c41
40
main.go
40
main.go
@ -12,6 +12,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
@ -65,7 +66,7 @@ func StripPrefix(prefix string, h http.Handler) http.Handler {
|
|||||||
func main() {
|
func main() {
|
||||||
var bind = flag.String("bind", "127.0.0.1:8080", "Bind port/socket")
|
var bind = flag.String("bind", "127.0.0.1:8080", "Bind port/socket")
|
||||||
var baseURL = flag.String("baseurl", "/", "URL prepended to each URL")
|
var baseURL = flag.String("baseurl", "/", "URL prepended to each URL")
|
||||||
var configfile = flag.String("config", "config.json", "path to the configuration file")
|
var configfile = flag.String("config", "", "path to the configuration file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Sanitize options
|
// Sanitize options
|
||||||
@ -79,6 +80,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load config file
|
// Load config file
|
||||||
|
if configfile != nil && *configfile != "" {
|
||||||
if fd, err := os.Open(*configfile); err != nil {
|
if fd, err := os.Open(*configfile); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
} else if cnt, err := ioutil.ReadAll(fd); err != nil {
|
} else if cnt, err := ioutil.ReadAll(fd); err != nil {
|
||||||
@ -86,6 +88,42 @@ func main() {
|
|||||||
} else if err := json.Unmarshal(cnt, &myLDAP); err != nil {
|
} else if err := json.Unmarshal(cnt, &myLDAP); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read configuration from environment
|
||||||
|
if val, ok := os.LookupEnv("LDAP_HOST"); ok {
|
||||||
|
myLDAP.Host = val
|
||||||
|
}
|
||||||
|
if val, ok := os.LookupEnv("LDAP_PORT"); ok {
|
||||||
|
if port, err := strconv.Atoi(val); err == nil {
|
||||||
|
myLDAP.Port = port
|
||||||
|
} else {
|
||||||
|
log.Println("Invalid value for LDAP_PORT:", val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if val, ok := os.LookupEnv("LDAP_STARTTLS"); ok {
|
||||||
|
myLDAP.Starttls = val == "1" || val == "on" || val == "true"
|
||||||
|
}
|
||||||
|
if val, ok := os.LookupEnv("LDAP_SSL"); ok {
|
||||||
|
myLDAP.Ssl = val == "1" || val == "on" || val == "true"
|
||||||
|
}
|
||||||
|
if val, ok := os.LookupEnv("LDAP_BASEDN"); ok {
|
||||||
|
myLDAP.BaseDN = val
|
||||||
|
}
|
||||||
|
if val, ok := os.LookupEnv("LDAP_SERVICEDN"); ok {
|
||||||
|
myLDAP.ServiceDN = val
|
||||||
|
}
|
||||||
|
if val, ok := os.LookupEnv("LDAP_SERVICE_PASSWORD_FILE"); ok {
|
||||||
|
if fd, err := os.Open(val); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
} else if cnt, err := ioutil.ReadAll(fd); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
} else {
|
||||||
|
myLDAP.ServicePassword = string(cnt)
|
||||||
|
}
|
||||||
|
} else if val, ok := os.LookupEnv("LDAP_SERVICE_PASSWORD"); ok {
|
||||||
|
myLDAP.ServicePassword = val
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare graceful shutdown
|
// Prepare graceful shutdown
|
||||||
interrupt := make(chan os.Signal, 1)
|
interrupt := make(chan os.Signal, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user