From 8b19395e22b6b81ab7fd82b409af9969fd49c92a Mon Sep 17 00:00:00 2001 From: karim hamidou Date: Wed, 14 May 2014 11:13:05 +0200 Subject: [PATCH] added a small script to add an user to the app --- manifests/default.pp | 6 +++ puppet_modules/app_config/manifests/init.pp | 9 ++++ .../app_config/templates/config.erb | 2 + puppet_modules/postfix/manifests/init.pp | 3 +- src/back/kite/kite-adduser.py | 51 +++++++++++++++++++ 5 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 puppet_modules/app_config/manifests/init.pp create mode 100644 puppet_modules/app_config/templates/config.erb create mode 100644 src/back/kite/kite-adduser.py diff --git a/manifests/default.pp b/manifests/default.pp index 8a900de..fea4aeb 100644 --- a/manifests/default.pp +++ b/manifests/default.pp @@ -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 index 0000000..47dc544 --- /dev/null +++ b/puppet_modules/app_config/manifests/init.pp @@ -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 index 0000000..769da28 --- /dev/null +++ b/puppet_modules/app_config/templates/config.erb @@ -0,0 +1,2 @@ +SERVER_NAME = "<%= @server_name %>" +ROOT_DIR = "/home/kite" diff --git a/puppet_modules/postfix/manifests/init.pp b/puppet_modules/postfix/manifests/init.pp index 3d3d69a..95fa9e0 100644 --- a/puppet_modules/postfix/manifests/init.pp +++ b/puppet_modules/postfix/manifests/init.pp @@ -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 index 0000000..ce710bb --- /dev/null +++ b/src/back/kite/kite-adduser.py @@ -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) -- 2.43.0