aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-08-16 14:36:14 +0200
committerAlex Auvolat <alex@adnab.me>2021-08-16 14:36:14 +0200
commit9e3279b9c04bb07d108fa820a72841b4082c0979 (patch)
tree3d9a774cb12ea315bf525f21fbad4390a31ae6dd
parentf00702b51c8904f9fb42a90a6e22301ae8d4014a (diff)
downloadguichet-9e3279b9c04bb07d108fa820a72841b4082c0979.tar.gz
guichet-9e3279b9c04bb07d108fa820a72841b4082c0979.zip
Fail when no config file is given, add example in repo
-rw-r--r--config.json.example28
-rw-r--r--main.go30
2 files changed, 30 insertions, 28 deletions
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 {