diff --git a/config.json.example b/config.json.example new file mode 100644 index 0000000..2631acc --- /dev/null +++ b/config.json.example @@ -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": "" +} + diff --git a/main.go b/main.go index e1b1e23..5754285 100644 --- a/main.go +++ b/main.go @@ -60,47 +60,21 @@ const SESSION_NAME = "guichet_session" var store sessions.Store = nil func readConfig() ConfigFile { + // Default configuration values for certain fields config_file := ConfigFile{ HttpBindAddr: ":9991", LdapServerAddr: "ldap://127.0.0.1:389", - LdapTLS: false, - BaseDN: "dc=example,dc=com", - UserBaseDN: "ou=users,dc=example,dc=com", UserNameAttr: "uid", - GroupBaseDN: "ou=groups,dc=example,dc=com", GroupNameAttr: "gid", - InvitationBaseDN: "ou=invitations,dc=example,dc=com", InvitationNameAttr: "cn", - InvitedMailFormat: "{}@example.com", 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) if os.IsNotExist(err) { - // Generate default config file - 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 + 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) } if err != nil {