Fail when no config file is given, add example in repo

This commit is contained in:
Alex 2021-08-16 14:36:14 +02:00
parent f00702b51c
commit 9e3279b9c0
No known key found for this signature in database
GPG key ID: EDABF9711E244EB1
2 changed files with 30 additions and 28 deletions

28
config.json.example Normal file
View file

@ -0,0 +1,28 @@
{
"http_bind_addr": ":9991",
"ldap_server_addr": "ldap://127.0.0.1:389",
"base_dn": "dc=example,dc=com",
"user_base_dn": "ou=users,dc=example,dc=com",
"user_name_attr": "uid",
"group_base_dn": "ou=groups,dc=example,dc=com",
"group_name_attr": "gid",
"invitation_base_dn": "ou=invitations,dc=example,dc=com",
"invitation_name_attr": "cn",
"invited_mail_format": "{}@example.com",
"invited_auto_groups": [
"cn=email,ou=groups,dc=example,dc=com"
],
"web_address": "https://guichet.example.com",
"mail_from": "welcome@example.com",
"smtp_server": "smtp.example.com",
"smtp_username": "guichet",
"smtp_password": "",
"admin_account": "uid=admin,dc=example,dc=com",
"group_can_admin": "gid=admin,ou=groups,dc=example,dc=com",
"group_can_invite": ""
}

30
main.go
View file

@ -60,47 +60,21 @@ const SESSION_NAME = "guichet_session"
var store sessions.Store = nil var store sessions.Store = nil
func readConfig() ConfigFile { func readConfig() ConfigFile {
// Default configuration values for certain fields
config_file := ConfigFile{ config_file := ConfigFile{
HttpBindAddr: ":9991", HttpBindAddr: ":9991",
LdapServerAddr: "ldap://127.0.0.1:389", LdapServerAddr: "ldap://127.0.0.1:389",
LdapTLS: false,
BaseDN: "dc=example,dc=com",
UserBaseDN: "ou=users,dc=example,dc=com",
UserNameAttr: "uid", UserNameAttr: "uid",
GroupBaseDN: "ou=groups,dc=example,dc=com",
GroupNameAttr: "gid", GroupNameAttr: "gid",
InvitationBaseDN: "ou=invitations,dc=example,dc=com",
InvitationNameAttr: "cn", InvitationNameAttr: "cn",
InvitedMailFormat: "{}@example.com",
InvitedAutoGroups: []string{}, InvitedAutoGroups: []string{},
WebAddress: "https://guichet.example.com",
MailFrom: "guichet@example.com",
SMTPServer: "smtp.example.com",
AdminAccount: "uid=admin,dc=example,dc=com",
GroupCanInvite: "",
GroupCanAdmin: "gid=admin,ou=groups,dc=example,dc=com",
} }
_, err := os.Stat(*configFlag) _, err := os.Stat(*configFlag)
if os.IsNotExist(err) { if os.IsNotExist(err) {
// Generate default config file log.Fatalf("Could not find Guichet configuration file at %s. Please create this file, for example starting with config.json.example and customizing it for your deployment.", *configFlag)
log.Printf("Generating default config file as %s", *configFlag)
bytes, err := json.MarshalIndent(&config_file, "", " ")
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile(*configFlag, bytes, 0644)
if err != nil {
log.Fatal(err)
}
return config_file
} }
if err != nil { if err != nil {