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

« back to all changes in this revision

Viewing changes to services/usrmgt-server

[Uber-commit of holiday work because I lacked a local copy of the branch.]

 ivle.makeuser: Don't use jailconf.py as a header for the in-jail conf.py;
     generate the whole thing using string formatting operators and include
     the template inline.

 ivle.makeuser.make_conf_py: XXX the inclusion of ivle.conf.jail_base in
     the jail. It is simply there to placate ivle.studpath, and needs
     to go before we can entirely remove the in-jail config.

 ivle-buildjail:
   - Add. Converted from setup.buildjail.
   - Build the jail in __base_build__ and rsync it to __base__ when
     done, rather than operating only in ./jail
   - Rename --rebuildjail/-j to --recreate/-r, as the whole script
     is now for jail rebuilding. Also add a warning to the usage string about
     the large volume likely to be downloaded.
   - Check existence before removing trees.
   - Don't copy jailconf.py over conf.py in the jail. Also make
     sure that we remove conf.pyc.

 setup.configure:
   - Stop generating jailconf.py at all.
   - Add a jail_system_build setting, defaulting to __base_build__ next to
     the existing __base__.
   - Don't use an OptionParser before calling the real function, as that
     adds options dynamically.

 setup.install:
   - Add an option (-R) to avoid writing out svn revision info to
     $PREFIX/share/ivle/revision.txt.
   - Remove jail-copying things.
   - Install all services to the host, rather than just usrmgt-server. We do
     this so we can build the jail from the host without the source tree.
   - Shuffle some things, and don't install phpBB3 twice.
   - Add a --root argument, to take an alternate root directory to install
     into (as given to autotools in $DESTDIR).

 setup.build:
   - Allow running as non-root.
   - Take a --no-compile option to not byte-compile Python files.

 setup.util:
   - Include usrmgt-server in the list of services.
   - Add make_install_path(), a wrapper around os.path.join() that ensures
     the second path is relative.
   - Install ivle-buildjail with the other binaries.

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
 
    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']
55
46
    user = ivle.database.User.get_by_login(store, login)
56
47
 
57
48
    # make svn config/auth
58
 
    repopath = os.path.join(config['paths']['svn']['repo_path'],
59
 
                            'users', login)
 
49
    repopath = os.path.join(ivle.conf.svn_repo_path, 'users', login)
60
50
    logging.debug("Creating user's Subversion repository")
61
51
    ivle.makeuser.make_svn_repo(repopath, throw_on_error=True)
62
52
 
63
 
    rebuild_svn_config(store, props, config)
 
53
    rebuild_svn_config(store, props)
64
54
 
65
55
    logging.debug("Adding Subversion authentication")
66
 
    passwd = ivle.makeuser.make_svn_auth(store, login, config,
 
56
    passwd = ivle.makeuser.make_svn_auth(store, login,
67
57
                                         throw_on_error=True)
68
58
 
69
59
    logging.debug("Creating jail")
70
 
    ivle.makeuser.make_jail(user, config)
 
60
    ivle.makeuser.make_jail(user)
71
61
 
72
62
    logging.info("Enabling user")
73
63
    user.state = u'enabled'
74
64
 
75
65
    return {"response": "okay"}
76
66
 
77
 
def rebuild_svn_config(store, props, config):
 
67
def rebuild_svn_config(store, props):
78
68
    """Rebuilds the svn config file
79
 
    @param config: An ivle.config.Config object.
80
 
    @return: response (okay, failure)
 
69
    Return value:
 
70
        response (okay, failure)
81
71
    """
82
72
    try:
83
 
        ivle.makeuser.rebuild_svn_config(store, config)
 
73
        ivle.makeuser.rebuild_svn_config(store)
84
74
    except Exception, e:
85
75
        logging.warning('Rebuild of Subversion authorization config failed!')
86
76
        return{'response': 'failure', 'msg': repr(e)}
87
77
 
88
78
    return {'response': 'okay'}
89
79
 
90
 
def rebuild_svn_group_config(store, props, config):
 
80
def rebuild_svn_group_config(store, props):
91
81
    """Rebuilds the svn group config file
92
 
    @param config: An ivle.config.Config object.
93
 
    @return: response (okay, failure)
 
82
    Return value:
 
83
        response (okay, failure)
94
84
    """
95
85
    try:
96
 
        ivle.makeuser.rebuild_svn_group_config(store, config)
 
86
        ivle.makeuser.rebuild_svn_group_config(store)
97
87
    except Exception, e:
98
88
        logging.warning(
99
89
            'Rebuild of Subversion group authorization config failed!')
101
91
 
102
92
    return {'response': 'okay'}
103
93
 
104
 
def create_group_repository(store, props, config):
 
94
def create_group_repository(store, props):
105
95
    """Creates on disk repository for the given group
106
 
    @param config: An ivle.config.Config object.
107
96
    Expected properties:
108
97
        subj_short_name, year, semester, groupnm
109
 
    @return: response (okay, failure)
 
98
    Return value:
 
99
        response (okay, failure)
110
100
    """
111
101
 
112
102
    subj_short_name = props['subj_short_name']
115
105
    groupnm = props['groupnm']
116
106
 
117
107
    namespace = "_".join([subj_short_name, year, semester, groupnm])
118
 
    repopath = os.path.join(config['paths']['svn']['repo_path'],
119
 
                            'groups', namespace)
 
108
    repopath = os.path.join(ivle.conf.svn_repo_path, 'groups', namespace)
120
109
    logging.debug("Creating Subversion repository %s"%repopath)
121
110
    try:
122
111
        ivle.makeuser.make_svn_repo(repopath)
135
124
    }
136
125
 
137
126
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
127
    try:
143
128
        pidfile = open('/var/run/usrmgt-server.pid', 'w')
144
129
        pidfile.write('%d\n' % os.getpid())
150
135
def dispatch(props):
151
136
    logging.debug(repr(props))
152
137
 
153
 
    store = ivle.database.get_store(config)
 
138
    store = ivle.database.get_store()
154
139
    action = props.keys()[0]
155
 
    res = actions[action](store, props[action], config)
 
140
    res = actions[action](store, props[action])
156
141
 
157
142
    if res['response'] == 'okay':
158
143
        store.commit()
164
149
if __name__ == "__main__":
165
150
    pid = os.getpid()
166
151
 
167
 
    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,
168
157
                           True, dispatch, initializer)