]> khamidou — GitHub mirrors - kite.git/commitdiff
added a small script to add an user to the app
authorkarim hamidou <khamidou@gmail.com>
Wed, 14 May 2014 09:13:05 +0000 (11:13 +0200)
committerkarim hamidou <khamidou@gmail.com>
Wed, 14 May 2014 09:13:05 +0000 (11:13 +0200)
manifests/default.pp
puppet_modules/app_config/manifests/init.pp [new file with mode: 0644]
puppet_modules/app_config/templates/config.erb [new file with mode: 0644]
puppet_modules/postfix/manifests/init.pp
src/back/kite/kite-adduser.py [new file with mode: 0644]

index 8a900deded96218f51ac4d20aa5dd24c34d5dfdc..fea4aebd04c4abe7d2dc962786fa6ab1f62ab356 100644 (file)
@@ -93,3 +93,9 @@ class {'supervisord':
     appdir => "/home/kite/app/back/kite/",
     require => File["/home/kite/app"]
 }
+
+# application-config values
+class {'app_config':
+    server_name => $server_name,
+    require => File["/home/kite/app"]
+}
diff --git a/puppet_modules/app_config/manifests/init.pp b/puppet_modules/app_config/manifests/init.pp
new file mode 100644 (file)
index 0000000..47dc544
--- /dev/null
@@ -0,0 +1,9 @@
+# a class configuring the kite config files
+
+class app_config ($server_name) {
+    file {"/home/kite/app/back/kite/config.py":
+        owner => "kite",
+        group => "kite",
+        content => template('app_config/config.erb'),
+    }
+}
diff --git a/puppet_modules/app_config/templates/config.erb b/puppet_modules/app_config/templates/config.erb
new file mode 100644 (file)
index 0000000..769da28
--- /dev/null
@@ -0,0 +1,2 @@
+SERVER_NAME = "<%= @server_name %>"
+ROOT_DIR = "/home/kite"
index 3d3d69a9c1c5f0336d56511d36f0a18ca80ebea2..95fa9e083abb6265b30b2fbbe8b639f75a6d2161 100644 (file)
@@ -23,7 +23,8 @@ class postfix ($server_name, $appdir) {
               false => "test \"x$(postconf -h ${name})\" == 'x${value}'",
               true  => "test \"x$(egrep '^${name} ' /etc/postfix/main.cf | cut -d= -f2 | cut -d' ' -f2)\" == 'x${value}'",
             },
-            notify  => Service["postfix"],
+            # don't notify the service for every little config change. Instead, we do it once when we're updating the postmap
+            #notify  => Service["postfix"],
             require => Package["postfix"]
           }
     }
diff --git a/src/back/kite/kite-adduser.py b/src/back/kite/kite-adduser.py
new file mode 100644 (file)
index 0000000..ce710bb
--- /dev/null
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+# add an user to Kite and Postfix
+import sys
+import os
+import getopt
+import config
+from cabinet import DatetimeCabinet
+
+def usage():
+    print "%s: Add an user to kite and postfix. required arguments: --username user --password pass" % sys.argv[0]
+    sys.exit(-1)
+
+def add_kite_user(username, password):
+    usersdb = DatetimeCabinet("/home/kite/users.db")
+    usersdb[username] = {"password": password} # FIXME: hash password
+    usersdb.sync()
+   
+def add_postfix_user(username):
+    # FIXME: do something a little more serious than a superficial grep
+    # for instance, slurp the file, get the first column and check the 
+    # username isn't in it.
+    with open('/etc/postfix/vmaps', 'r') as fd: 
+        if username in fd.read():
+            print "User already exists"
+            return
+
+    with open('/etc/postfix/vmaps', 'a') as fd:
+        fd.write("%s@%s %s/\n" % (username, config.SERVER_NAME, username))
+
+    os.system("postmap /etc/postfix/vmaps") 
+    os.system("service postfix reload")
+
+try:
+    opts, args = getopt.getopt(sys.argv[1:], 'u:p:', ['username=', 'password='])
+except getopt.GetoptError:
+    usage()
+
+username = None
+password = None
+
+for opt, arg in opts:
+    if opt in ('-u', '--username'):
+        username = arg
+    elif opt in ('-p', '--password'):
+        password = arg
+
+if username == None or password == None:
+    usage()
+
+add_postfix_user(username)
+add_kite_user(username, password)