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

« back to all changes in this revision

Viewing changes to services/usrmgt-server

  • Committer: Matt Giuca
  • Date: 2009-12-08 12:17:02 UTC
  • Revision ID: matt.giuca@gmail.com-20091208121702-pg0c7gog32zw9xrq
doc: Minor.

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