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
52
main.go
52
main.go
@ -12,6 +12,7 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
@ -65,7 +66,7 @@ func StripPrefix(prefix string, h http.Handler) http.Handler {
|
||||
func main() {
|
||||
var bind = flag.String("bind", "127.0.0.1:8080", "Bind port/socket")
|
||||
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()
|
||||
|
||||
// Sanitize options
|
||||
@ -79,12 +80,49 @@ func main() {
|
||||
}
|
||||
|
||||
// Load config file
|
||||
if fd, err := os.Open(*configfile); err != nil {
|
||||
log.Fatal(err)
|
||||
} else if cnt, err := ioutil.ReadAll(fd); err != nil {
|
||||
log.Fatal(err)
|
||||
} else if err := json.Unmarshal(cnt, &myLDAP); err != nil {
|
||||
log.Fatal(err)
|
||||
if configfile != nil && *configfile != "" {
|
||||
if fd, err := os.Open(*configfile); err != nil {
|
||||
log.Fatal(err)
|
||||
} else if cnt, err := ioutil.ReadAll(fd); err != nil {
|
||||
log.Fatal(err)
|
||||
} else if err := json.Unmarshal(cnt, &myLDAP); err != nil {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user