~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to services/usrmgt-server

Added module ivle.config, which takes care of some work interfacing with
    configobj, including searching for the file and opening the object.
ivle.conf.conf now uses this instead of having its own search.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import sys
5
5
import logging
6
6
 
7
 
import ivle.config
 
7
import ivle.conf
8
8
import ivle.database
9
9
import ivle.chat
10
10
import ivle.makeuser
11
11
 
12
 
config = ivle.config.Config()
13
 
 
14
12
# usage:
15
13
#   usrmgt-server <port> <magic>
16
14
 
29
27
#   - Rebuild svn auth file
30
28
#   - Rebuild passwd + push to nodes.
31
29
 
32
 
def activate_user(store, props, config):
 
30
def activate_user(store, props):
33
31
    """Create the on-disk stuff for the given user.
34
32
       Sets the state of the user in the db from pending to enabled.
35
 
    @param config: An ivle.config.Config object.
36
33
       Expected properties:
37
34
        login       - the user name for the jail
38
35
                      STRING REQUIRED
39
 
    @return: None
 
36
       Return Value: None
40
37
    """
41
38
 
42
39
    os.umask(0022) # Bad, but start_server sets it worse.
49
46
    user = ivle.database.User.get_by_login(store, login)
50
47
 
51
48
    # make svn config/auth
52
 
    repopath = os.path.join(config['paths']['svn']['repo_path'],
53
 
                            'users', login)
 
49
    repopath = os.path.join(ivle.conf.svn_repo_path, 'users', login)
54
50
    logging.debug("Creating user's Subversion repository")
55
51
    ivle.makeuser.make_svn_repo(repopath, throw_on_error=True)
56
52
 
57
 
    rebuild_svn_config(store, props, config)
 
53
    rebuild_svn_config(store, props)
58
54
 
59
55
    logging.debug("Adding Subversion authentication")
60
 
    passwd = ivle.makeuser.make_svn_auth(store, login, config,
 
56
    passwd = ivle.makeuser.make_svn_auth(store, login,
61
57
                                         throw_on_error=True)
62
58
 
63
59
    logging.debug("Creating jail")
64
 
    ivle.makeuser.make_jail(user, config)
 
60
    ivle.makeuser.make_jail(user)
65
61
 
66
62
    logging.info("Enabling user")
67
63
    user.state = u'enabled'
68
64
 
69
65
    return {"response": "okay"}
70
66
 
71
 
def rebuild_svn_config(store, props, config):
 
67
def rebuild_svn_config(store, props):
72
68
    """Rebuilds the svn config file
73
 
    @param config: An ivle.config.Config object.
74
 
    @return: response (okay, failure)
 
69
    Return value:
 
70
        response (okay, failure)
75
71
    """
76
72
    try:
77
 
        ivle.makeuser.rebuild_svn_config(store, config)
 
73
        ivle.makeuser.rebuild_svn_config(store)
78
74
    except Exception, e:
79
75
        logging.warning('Rebuild of Subversion authorization config failed!')
80
76
        return{'response': 'failure', 'msg': repr(e)}
81
77
 
82
78
    return {'response': 'okay'}
83
79
 
84
 
def rebuild_svn_group_config(store, props, config):
 
80
def rebuild_svn_group_config(store, props):
85
81
    """Rebuilds the svn group config file
86
 
    @param config: An ivle.config.Config object.
87
 
    @return: response (okay, failure)
 
82
    Return value:
 
83
        response (okay, failure)
88
84
    """
89
85
    try:
90
 
        ivle.makeuser.rebuild_svn_group_config(store, config)
 
86
        ivle.makeuser.rebuild_svn_group_config(store)
91
87
    except Exception, e:
92
88
        logging.warning(
93
89
            'Rebuild of Subversion group authorization config failed!')
95
91
 
96
92
    return {'response': 'okay'}
97
93
 
98
 
def create_group_repository(store, props, config):
 
94
def create_group_repository(store, props):
99
95
    """Creates on disk repository for the given group
100
 
    @param config: An ivle.config.Config object.
101
96
    Expected properties:
102
97
        subj_short_name, year, semester, groupnm
103
 
    @return: response (okay, failure)
 
98
    Return value:
 
99
        response (okay, failure)
104
100
    """
105
101
 
106
102
    subj_short_name = props['subj_short_name']
109
105
    groupnm = props['groupnm']
110
106
 
111
107
    namespace = "_".join([subj_short_name, year, semester, groupnm])
112
 
    repopath = os.path.join(config['paths']['svn']['repo_path'],
113
 
                            'groups', namespace)
 
108
    repopath = os.path.join(ivle.conf.svn_repo_path, 'groups', namespace)
114
109
    logging.debug("Creating Subversion repository %s"%repopath)
115
110
    try:
116
111
        ivle.makeuser.make_svn_repo(repopath)
129
124
    }
130
125
 
131
126
def initializer():
132
 
    logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
133
 
    logging.info("Starting usrmgt server on port %d (pid = %d)" %
134
 
                 (config['usrmgt']['port'], pid))
135
 
 
136
127
    try:
137
128
        pidfile = open('/var/run/usrmgt-server.pid', 'w')
138
129
        pidfile.write('%d\n' % os.getpid())
144
135
def dispatch(props):
145
136
    logging.debug(repr(props))
146
137
 
147
 
    store = ivle.database.get_store(config)
 
138
    store = ivle.database.get_store()
148
139
    action = props.keys()[0]
149
 
    res = actions[action](store, props[action], config)
 
140
    res = actions[action](store, props[action])
150
141
 
151
142
    if res['response'] == 'okay':
152
143
        store.commit()
158
149
if __name__ == "__main__":
159
150
    pid = os.getpid()
160
151
 
161
 
    ivle.chat.start_server(config['usrmgt']['port'],config['usrmgt']['magic'],
 
152
    logging.basicConfig(filename="/var/log/usrmgt.log", level=logging.INFO)
 
153
    logging.info("Starting usrmgt server on port %d (pid = %d)" %
 
154
                 (ivle.conf.usrmgt_port, pid))
 
155
 
 
156
    ivle.chat.start_server(ivle.conf.usrmgt_port, ivle.conf.usrmgt_magic,
162
157
                           True, dispatch, initializer)