28
29
# - Rebuild svn auth file
29
30
# - Rebuild passwd + push to nodes.
31
def activate_user(store, props):
32
def activate_user(store, props, config):
32
33
"""Create the on-disk stuff for the given user.
33
34
Sets the state of the user in the db from pending to enabled.
35
@param config: An ivle.config.Config object.
34
36
Expected properties:
35
37
login - the user name for the jail
40
42
os.umask(0022) # Bad, but start_server sets it worse.
47
49
user = ivle.database.User.get_by_login(store, login)
49
51
# make svn config/auth
50
repopath = os.path.join(ivle.conf.svn_repo_path, 'users', login)
52
repopath = os.path.join(config['paths']['svn']['repo_path'],
51
54
logging.debug("Creating user's Subversion repository")
52
55
ivle.makeuser.make_svn_repo(repopath, throw_on_error=True)
54
rebuild_svn_config(store, props)
57
rebuild_svn_config(store, props, config)
56
59
logging.debug("Adding Subversion authentication")
57
passwd = ivle.makeuser.make_svn_auth(store, login,
60
passwd = ivle.makeuser.make_svn_auth(store, login, config,
58
61
throw_on_error=True)
60
63
logging.debug("Creating jail")
61
ivle.makeuser.make_jail(user)
64
ivle.makeuser.make_jail(user, config)
63
66
logging.info("Enabling user")
64
67
user.state = u'enabled'
66
69
return {"response": "okay"}
68
def rebuild_svn_config(store, props):
71
def rebuild_svn_config(store, props, config):
69
72
"""Rebuilds the svn config file
71
response (okay, failure)
73
@param config: An ivle.config.Config object.
74
@return: response (okay, failure)
74
ivle.makeuser.rebuild_svn_config(store)
77
ivle.makeuser.rebuild_svn_config(store, config)
75
78
except Exception, e:
76
79
logging.warning('Rebuild of Subversion authorization config failed!')
77
80
return{'response': 'failure', 'msg': repr(e)}
79
82
return {'response': 'okay'}
81
def rebuild_svn_group_config(store, props):
84
def rebuild_svn_group_config(store, props, config):
82
85
"""Rebuilds the svn group config file
84
response (okay, failure)
86
@param config: An ivle.config.Config object.
87
@return: response (okay, failure)
87
ivle.makeuser.rebuild_svn_group_config(store)
90
ivle.makeuser.rebuild_svn_group_config(store, config)
88
91
except Exception, e:
90
93
'Rebuild of Subversion group authorization config failed!')
93
96
return {'response': 'okay'}
95
def create_group_repository(store, props):
98
def create_group_repository(store, props, config):
96
99
"""Creates on disk repository for the given group
100
@param config: An ivle.config.Config object.
97
101
Expected properties:
98
102
subj_short_name, year, semester, groupnm
100
response (okay, failure)
103
@return: response (okay, failure)
103
106
subj_short_name = props['subj_short_name']
106
109
groupnm = props['groupnm']
108
111
namespace = "_".join([subj_short_name, year, semester, groupnm])
109
repopath = os.path.join(ivle.conf.svn_repo_path, 'groups', namespace)
112
repopath = os.path.join(config['paths']['svn']['repo_path'],
110
114
logging.debug("Creating Subversion repository %s"%repopath)
112
116
ivle.makeuser.make_svn_repo(repopath)
127
131
def initializer():
128
132
logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
129
133
logging.info("Starting usrmgt server on port %d (pid = %d)" %
130
(ivle.conf.usrmgt_port, pid))
134
(config['usrmgt']['port'], pid))
133
137
pidfile = open('/var/run/usrmgt-server.pid', 'w')
140
144
def dispatch(props):
141
145
logging.debug(repr(props))
143
store = ivle.database.get_store(ivle.config.Config())
147
store = ivle.database.get_store(config)
144
148
action = props.keys()[0]
145
res = actions[action](store, props[action])
149
res = actions[action](store, props[action], config)
147
151
if res['response'] == 'okay':
154
158
if __name__ == "__main__":
155
159
pid = os.getpid()
157
ivle.chat.start_server(ivle.conf.usrmgt_port, ivle.conf.usrmgt_magic,
161
ivle.chat.start_server(config['usrmgt']['port'],config['usrmgt']['magic'],
158
162
True, dispatch, initializer)