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
42
if not os.path.exists(config['paths']['jails']['template']):
45
'message': 'Template jail has not been built -- '
46
'do you need to run ivle-buildjail?'}
40
48
os.umask(0022) # Bad, but start_server sets it worse.
42
50
login = props['login']
47
55
user = ivle.database.User.get_by_login(store, login)
49
57
# make svn config/auth
50
repopath = os.path.join(ivle.conf.svn_repo_path, 'users', login)
58
repopath = os.path.join(config['paths']['svn']['repo_path'],
51
60
logging.debug("Creating user's Subversion repository")
52
61
ivle.makeuser.make_svn_repo(repopath, throw_on_error=True)
54
rebuild_svn_config(store, props)
63
rebuild_svn_config(store, props, config)
56
65
logging.debug("Adding Subversion authentication")
57
passwd = ivle.makeuser.make_svn_auth(store, login,
66
passwd = ivle.makeuser.make_svn_auth(store, login, config,
58
67
throw_on_error=True)
60
69
logging.debug("Creating jail")
61
ivle.makeuser.make_jail(user)
70
ivle.makeuser.make_jail(user, config)
63
72
logging.info("Enabling user")
64
73
user.state = u'enabled'
66
75
return {"response": "okay"}
68
def rebuild_svn_config(store, props):
77
def rebuild_svn_config(store, props, config):
69
78
"""Rebuilds the svn config file
71
response (okay, failure)
79
@param config: An ivle.config.Config object.
80
@return: response (okay, failure)
74
ivle.makeuser.rebuild_svn_config(store)
83
ivle.makeuser.rebuild_svn_config(store, config)
75
84
except Exception, e:
76
85
logging.warning('Rebuild of Subversion authorization config failed!')
77
86
return{'response': 'failure', 'msg': repr(e)}
79
88
return {'response': 'okay'}
81
def rebuild_svn_group_config(store, props):
90
def rebuild_svn_group_config(store, props, config):
82
91
"""Rebuilds the svn group config file
84
response (okay, failure)
92
@param config: An ivle.config.Config object.
93
@return: response (okay, failure)
87
ivle.makeuser.rebuild_svn_group_config(store)
96
ivle.makeuser.rebuild_svn_group_config(store, config)
88
97
except Exception, e:
90
99
'Rebuild of Subversion group authorization config failed!')
93
102
return {'response': 'okay'}
95
def create_group_repository(store, props):
104
def create_group_repository(store, props, config):
96
105
"""Creates on disk repository for the given group
106
@param config: An ivle.config.Config object.
97
107
Expected properties:
98
108
subj_short_name, year, semester, groupnm
100
response (okay, failure)
109
@return: response (okay, failure)
103
112
subj_short_name = props['subj_short_name']
106
115
groupnm = props['groupnm']
108
117
namespace = "_".join([subj_short_name, year, semester, groupnm])
109
repopath = os.path.join(ivle.conf.svn_repo_path, 'groups', namespace)
118
repopath = os.path.join(config['paths']['svn']['repo_path'],
110
120
logging.debug("Creating Subversion repository %s"%repopath)
112
122
ivle.makeuser.make_svn_repo(repopath)
127
137
def initializer():
128
138
logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
129
139
logging.info("Starting usrmgt server on port %d (pid = %d)" %
130
(ivle.conf.usrmgt_port, pid))
140
(config['usrmgt']['port'], pid))
133
143
pidfile = open('/var/run/usrmgt-server.pid', 'w')
140
150
def dispatch(props):
141
151
logging.debug(repr(props))
143
store = ivle.database.get_store(ivle.config.Config())
153
store = ivle.database.get_store(config)
144
154
action = props.keys()[0]
145
res = actions[action](store, props[action])
155
res = actions[action](store, props[action], config)
147
157
if res['response'] == 'okay':
154
164
if __name__ == "__main__":
155
165
pid = os.getpid()
157
ivle.chat.start_server(ivle.conf.usrmgt_port, ivle.conf.usrmgt_magic,
167
ivle.chat.start_server(config['usrmgt']['port'],config['usrmgt']['magic'],
158
168
True, dispatch, initializer)