guichet/utils-config.go

54 lines
1.1 KiB
Go
Raw Normal View History

2023-07-26 06:31:43 +00:00
/*
config handles reading the config.json file at the root and processing the settings
*/
package main
import (
"encoding/json"
"flag"
"io/ioutil"
"log"
"os"
)
var configFlag = flag.String("config", "./config.json", "Configuration file path")
var config *ConfigFile
func readConfig() ConfigFile {
// Default configuration values for certain fields
config_file := ConfigFile{
HttpBindAddr: ":9991",
LdapServerAddr: "ldap://127.0.0.1:389",
UserNameAttr: "uid",
GroupNameAttr: "gid",
InvitationNameAttr: "cn",
InvitedAutoGroups: []string{},
Org: "ResDigita",
}
_, err := os.Stat(*configFlag)
if os.IsNotExist(err) {
log.Fatalf("Could not find Guichet configuration file at %s. Please create this file, for exemple starting with config.json.exemple and customizing it for your deployment.", *configFlag)
}
if err != nil {
log.Fatal(err)
}
bytes, err := ioutil.ReadFile(*configFlag)
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal(bytes, &config_file)
if err != nil {
log.Fatal(err)
}
return config_file
}