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

« back to all changes in this revision

Viewing changes to services/usrmgt-server

  • Committer: matt.giuca
  • Date: 2009-01-18 23:03:54 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1166
setup.install: Merged change from Storm branch (should have been committed
    directly to trunk). Small bugfix.

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