예제 #1
0
 def testGetAllOptions(self):
     options.set_value('answer', '42')
     c = c_config.c_config(self.sa, ['get'])
     c.run()
     output = sys.stdout.getvalue()
     self.assertTrue('database_version' in output)
     self.assertTrue('git_dir' in output)
     self.assertTrue('42' in output)
예제 #2
0
	def testGetAllOptions(self):
		options.set_value('answer', '42')
		c = c_config.c_config(self.sa, ['get'])
		c.run()
		output = sys.stdout.getvalue()
		self.assertTrue('database_version' in output)
		self.assertTrue('git_dir' in output)
		self.assertTrue('42' in output)
예제 #3
0
	def subcmd_set(self, argv):
		from submin.models import options
		self.sa.ensure_storage()

		if len(argv) < 2:
			self.sa.execute(['help', 'config'])
			return

		options.set_value(argv[0], ' '.join(argv[1:]))
예제 #4
0
    def subcmd_set(self, argv):
        from submin.models import options
        self.sa.ensure_storage()

        if len(argv) < 2:
            self.sa.execute(['help', 'config'])
            return

        options.set_value(argv[0], ' '.join(argv[1:]))
예제 #5
0
    def settings_defaults(self, filename):
        # write the bootstrap settings file
        submin_settings = '''
import os
storage = "sql"
sqlite_path = os.path.join(os.path.dirname(__file__), "submin.db")
'''

        dirname = os.path.dirname(filename)
        mkdirs(dirname)

        file(filename, 'w').write(submin_settings)

        # after writing the bootstrap file, we setup all models
        self.sa.ensure_storage()
        from submin.models import storage
        storage.database_evolve()

        # And now we can use the models
        from submin.models import options
        import platform

        http_base = ''
        default_options = {
            'base_url_submin': http_base + '/submin',
            'base_url_svn': http_base + '/svn',
            'base_url_git': http_base + '/git',
            'base_url_trac': http_base + '/trac',
            'http_vhost': platform.node(),
            'auth_type': 'sql',
            'svn_dir': 'svn',
            'git_dir': 'git',
            'trac_dir': 'trac',
            'dir_bin': 'static/bin',
            'enabled_trac': 'no',
            'enabled_external': 'no',
            'external_server': 'ldaps://example.net',
            'external_base_dn': 'DC=example,DC=net',
            'external_group_dn': 'CN=SVN,OU=SVN,DC=example,DC=net',
            'external_user': '******',
            'external_passwd': 'secret',
            'external_upn_suffix': 'example.net',
            'session_salt': self.session_salt(),
            'env_path': '/bin:/usr/bin:/usr/local/bin:/opt/local/bin',
            'vcs_plugins': 'git,svn',
        }
        for (key, value) in default_options.iteritems():
            options.set_value(key, value)
        self.generate_cgi()
예제 #6
0
파일: trac.py 프로젝트: andy-deng/submin
	def setUp(self):
		self.submin_env = tempfile.mkdtemp(prefix='submin-unittest')
		self.conf_dir = os.path.join(self.submin_env, 'conf')
		os.mkdir(self.conf_dir)
		mock_settings.base_dir = self.submin_env
		storage.open(mock_settings)
		storage.database_evolve()

		options.set_value('vcs_plugins', 'svn')
		options.set_value('svn_dir', 'svn')
		options.set_value('trac_dir', 'trac')
		options.set_value('svn_authz_file', 'conf/authz')
		options.set_value('enabled_trac', 'yes')

		self.svn_dir = str(options.env_path('svn_dir'))
		self.trac_dir = str(options.env_path('trac_dir'))
		os.mkdir(self.svn_dir)
		os.mkdir(self.trac_dir)
예제 #7
0
    def setUp(self):
        self.submin_env = tempfile.mkdtemp(prefix='submin-unittest')
        self.conf_dir = os.path.join(self.submin_env, 'conf')
        os.mkdir(self.conf_dir)
        mock_settings.base_dir = self.submin_env
        storage.open(mock_settings)
        storage.database_evolve()

        options.set_value('vcs_plugins', 'svn')
        options.set_value('svn_dir', 'svn')
        options.set_value('trac_dir', 'trac')
        options.set_value('svn_authz_file', 'conf/authz')
        options.set_value('enabled_trac', 'yes')

        self.svn_dir = str(options.env_path('svn_dir'))
        self.trac_dir = str(options.env_path('trac_dir'))
        os.mkdir(self.svn_dir)
        os.mkdir(self.trac_dir)
예제 #8
0
파일: groups.py 프로젝트: andy-deng/submin
	def setUp(self):
		self.submin_env = Path(tempfile.mkdtemp(prefix='submin-unittest'))
		conf_dir = self.submin_env + 'conf'
		os.mkdir(conf_dir)
		mock_settings.base_dir = self.submin_env
		storage.open(mock_settings)
		storage.database_evolve()
		options.set_value('svn_authz_file', conf_dir + 'authz') # needed for export
		options.set_value('svn_dir', self.submin_env + 'svn') # needed for export
		options.set_value('git_dir', self.submin_env + 'git')
		options.set_value('vcs_plugins', 'svn, git')
예제 #9
0
	def settings_defaults(self, filename):
		# write the bootstrap settings file
		submin_settings = '''
import os
storage = "sql"
sqlite_path = os.path.join(os.path.dirname(__file__), "submin.db")
'''

		dirname = os.path.dirname(filename)
		mkdirs(dirname)

		file(filename, 'w').write(submin_settings)

		# after writing the bootstrap file, we setup all models
		self.sa.ensure_storage()
		from submin.models import storage
		storage.database_evolve()

		# And now we can use the models
		from submin.models import options
		import platform

		http_base = ''
		default_options = {
			'base_url_submin': http_base + '/submin',
			'base_url_svn': http_base + '/svn',
			'base_url_git': http_base + '/git',
			'base_url_trac': http_base + '/trac',
			'http_vhost': platform.node(),
			'auth_type': 'sql',
			'svn_dir': 'svn',
			'git_dir': 'git',
			'trac_dir': 'trac',
			'dir_bin': 'static/bin',
			'enabled_trac': 'no',
			'session_salt': self.session_salt(),
			'env_path': '/bin:/usr/bin:/usr/local/bin:/opt/local/bin',
			'vcs_plugins': 'git,svn',
		}
		for (key, value) in default_options.iteritems():
			options.set_value(key, value)
		self.generate_cgi()
예제 #10
0
 def setUp(self):
     self.submin_env = Path(tempfile.mkdtemp(prefix='submin-unittest'))
     conf_dir = self.submin_env + 'conf'
     os.mkdir(conf_dir)
     mock_settings.base_dir = self.submin_env
     storage.open(mock_settings)
     storage.database_evolve()
     options.set_value('svn_authz_file',
                       conf_dir + 'authz')  # needed for export
     options.set_value('svn_dir',
                       self.submin_env + 'svn')  # needed for export
     options.set_value('git_dir', self.submin_env + 'git')
     options.set_value('vcs_plugins', 'svn, git')
예제 #11
0
    def write_options(self, config):
        from submin.models import options
        from ConfigParser import NoOptionError, NoSectionError

        cfg = {
            'base_url_submin': ('www', 'base_url'),
            'base_url_svn': ('www', 'svn_base_url'),
            'base_url_trac': ('www', 'trac_base_url'),
            'svn_dir': ('svn', 'repositories'),
            'trac_dir': ('trac', 'basedir'),
            'dir_bin': ('backend', 'bindir'),
            'session_salt': ('generated', 'session_salt'),
            'env_path': ('backend', 'path'),
        }
        for (key, section_option) in cfg.iteritems():
            try:
                value = config.get(section_option[0], section_option[1])
                options.set_value(key, value)
            except (NoOptionError, NoSectionError):
                pass  # fallback to the defaults set before

        options.set_value('svn_authz_file', 'conf/authz')
예제 #12
0
	def write_options(self, config):
		from submin.models import options
		from ConfigParser import NoOptionError, NoSectionError

		cfg = {
			'base_url_submin': ('www', 'base_url'),
			'base_url_svn': ('www', 'svn_base_url'),
			'base_url_trac': ('www', 'trac_base_url'),
			'svn_dir': ('svn', 'repositories'),
			'trac_dir': ('trac', 'basedir'),
			'dir_bin': ('backend', 'bindir'),
			'session_salt': ('generated', 'session_salt'),
			'env_path': ('backend', 'path'),
		}
		for (key, section_option) in cfg.iteritems():
			try:
				value = config.get(section_option[0], section_option[1])
				options.set_value(key, value)
			except (NoOptionError, NoSectionError):
				pass # fallback to the defaults set before

		options.set_value('svn_authz_file', 'conf/authz')
예제 #13
0
파일: users.py 프로젝트: andy-deng/submin
 def setUp(self):
     self.submin_env = Path(tempfile.mkdtemp(prefix="submin-unittest"))
     conf_dir = self.submin_env + "conf"
     svn_dir = self.submin_env + "svn"
     os.mkdir(conf_dir)
     os.mkdir(svn_dir)
     mock_settings.base_dir = self.submin_env
     storage.open(mock_settings)
     storage.database_evolve()
     options.set_value("svn_authz_file", conf_dir + "authz")  # needed for export
     options.set_value("svn_dir", svn_dir)  # needed for export
     options.set_value("git_dir", self.submin_env + "git")
     options.set_value("vcs_plugins", "svn, git")
     self.tmp_dirs = []
     user.add("test", email="[email protected]", password="******")
     self.u = user.User("test")
예제 #14
0
파일: options.py 프로젝트: andy-deng/submin
	def testPath(self):
		options.set_value("foo", "bar")
		self.assertEquals(unicode(options.env_path("foo")), "/submin/bar")
예제 #15
0
    def setUp(self):
        self.submin_env = tempfile.mkdtemp(prefix='submin-unittest')
        self.conf_dir = os.path.join(self.submin_env, 'conf')
        os.mkdir(self.conf_dir)
        self.authz_file = os.path.join(self.submin_env, 'conf', 'authz')

        mock_settings.base_dir = self.submin_env
        storage.open(mock_settings)
        storage.database_evolve()
        options.set_value('vcs_plugins', 'svn')
        options.set_value('svn_dir', 'svn')
        options.set_value('trac_dir', 'trac')
        options.set_value('svn_authz_file', 'conf/authz')
        options.set_value('enabled_trac', 'no')
        options.set_value('http_vhost', 'localhost')
        options.set_value('base_url_submin', '/submin')

        self.svn_dir = str(options.env_path('svn_dir'))
        self.trac_dir = str(options.env_path('trac_dir'))
        os.mkdir(self.svn_dir)
        os.mkdir(self.trac_dir)

        # now make some repositories
        self.repositories = [
            {
                'name': 'foo',
                'status': 'ok',
                'vcs': 'svn'
            },
            {
                'name': 'invalidperm',
                'status': 'permission denied',
                'vcs': 'svn'
            },
            {
                'name': 'invalidperm2',
                'status': 'permission denied',
                'vcs': 'svn'
            },
            {
                'name': 'example',
                'status': 'ok',
                'vcs': 'svn'
            },
            {
                'name': 'subdirs',
                'status': 'ok',
                'vcs': 'svn'
            },
        ]
        self.has_invalidperm = False
        self.has_invalidperm2 = False
예제 #16
0
파일: options.py 프로젝트: andy-deng/submin
	def testGetOption(self):
		options.set_value("foo", "bar")
		self.assertEquals(options.value("foo"), "bar")
예제 #17
0
파일: c_git.py 프로젝트: andy-deng/submin
	def subcmd_init(self, args):
		from submin.models import options

		if os.getuid() != 0:
			raise SubminAdminCmdException("Please execute `git init' as root.")

		try:
			sudo_bin = which("sudo")
			git_bin  = which("git")
		except ProgramNotFoundError as e:
			raise SubminAdminCmdException('Could not find %s, which is required for git init.' % e.prog)

		from submin.subminadmin import c_unixperms
		apache = www_user()
		self.create_ssh_key(owner=apache)

		# Ask the name of the git user, if it exists ask to use it or bail
		git_user = self.prompt_user("What user should the git-users connect as?",
				"git")

		from pwd import getpwnam
		# Create git user if it doesn't exist yet.
		try:
			pwd = getpwnam(git_user)
		except KeyError as e:
			self.create_user(git_user, options.env_path("git_dir"))
		else:
			use_it = self.prompt_user("User %s already exists. Use it?" % \
					git_user, "Yn")
			if use_it.lower() not in ("y", "yes", "yn"):
				raise SubminAdminCmdException('Aborting')

		# Now add the www-user to the git-group and chgrp of essential files
		# (settings file, database and paths.)
		git_pw = getpwnam(git_user)
		# XXX this is problably not necessary anymore
		self.add_user_to_group(apache.pw_name, git_pw.pw_gid)
		self.chgrp_relevant_files(git_uid=git_pw.pw_uid, git_gid=git_pw.pw_gid)

		# Set the git_user option to the git-user
		options.set_value("git_user", git_user)

		# Ask public ssh-host
		ssh_host = self.prompt_user(
				"What is the public host-name of the ssh-server?",
				socket.getfqdn())
		options.set_value("git_ssh_host", ssh_host)

		# Ask internal ssh-host
		internal_ssh_host = self.prompt_user(
				"What is the internal host-name of the ssh-server\n" +
				"(used to, e.g., create repositories over fast local network)?",
				"localhost")
		options.set_value("git_ssh_host_internal", internal_ssh_host)

		# Ask ssh-port (default 22)
		ssh_port = self.prompt_user("On what port is the ssh-server available?",
				"22")
		options.set_value("git_ssh_port", ssh_port)

		# Enable git as a vcs plugin
		vcs_plugins = options.value("vcs_plugins")
		if 'git' not in vcs_plugins.split(','):
			options.set_value("vcs_plugins", "%s,git" % vcs_plugins)

		# Install .ssh/authorized_keys
		# This is kind-of elaborate, since the update-auth command is re-used
		# here, which is intended to be called via ssh. Since that is obviously
		# not possible yet, fake setting the SSH_ORIGINAL_COMMAND by passing it
		# as an environment variable.
		cmd = "sudo -H -u %s SSH_ORIGINAL_COMMAND='update-auth' submin2-admin '%s' git admin" % (git_user,
				options.env_path())
		executeCmd(cmd, "Could not install authorized_keys-file. Please check whether the git-user has read-access to the submin-environment directory")
예제 #18
0
 def testNotExists(self):
     options.set_value('env_path', '')
     exists = trac.has_trac_admin()
     self.assertEquals(exists, False)
예제 #19
0
 def testSetOption(self):
     options.set_value("foo", "bar")
     self.assertEquals(options.options(), [(u'git_dir', u'git'),
                                           (u'database_version', u'11'),
                                           (u'foo', u'bar')])
예제 #20
0
 def testPath(self):
     options.set_value("foo", "bar")
     self.assertEquals(unicode(options.env_path("foo")), "/submin/bar")
예제 #21
0
 def testCompleteVhostWithPort(self):
     options.set_value('http_vhost', 'http://example.net:80/')
     self.assertGreater(len(generate_acl_list()), 2)
예제 #22
0
    def create_env(self):
        """This is called when all info is gathered"""
        for key, value in self.defaults.items():
            if key not in self.init_vars:
                self.init_vars[key] = value

        try:
            self.create_dir(self.env)
            self.create_dir(self.init_vars['svn_dir'])
            self.create_dir(self.init_vars['git_dir'])
            self.create_dir(self.init_vars['conf_dir'])
            self.create_dir(self.init_vars['trac_dir'])
            self.create_dir(self.init_vars['hooks_dir'])
            self.create_dir(Path('auth'))
        except OSError:
            return  # already printed error message

        self.sa.execute(['config', 'defaults'])

        # check http_base
        p = self.init_vars['http_base']
        if str(p) == "":
            self.init_vars['http_base'] = Path("/")

        # write changes to config
        from submin.models import options

        default_options = {
            'base_url_submin': self._get_url('submin_url'),
            'base_url_svn': self._get_url('svn_url'),
            'base_url_trac': self._get_url('trac_url'),
            'http_vhost': self.init_vars['http_vhost'],
            'auth_type': 'sql',
            'svn_dir': str(self.init_vars['svn_dir']),
            'git_dir': str(self.init_vars['git_dir']),
            'trac_dir': str(self.init_vars['trac_dir']),
            'svn_authz_file': str(self.init_vars['authz']),
            'smtp_from': self.init_vars['smtp_from'],
            'commit_email_from': self.init_vars['commit_email_from'],
        }
        for (key, value) in default_options.items():
            options.set_value(key, value)

        # add a user
        from submin.models import user

        if self.init_vars['create_user'] == "yes":
            # add an admin user
            u = user.add('admin', self.email, send_mail=False)
            u.is_admin = True
            try:
                u.prepare_password_reset('submin2-admin')
            except SendEmailError as e:
                print(
                    'WARNING: Could not send an e-mail, please install a mail server'
                )
                print(
                    'WARNING: You can request a password reset for "admin" on the login page'
                )

        self.sa.execute(['upgrade', 'hooks', 'no-fix-unixperms'])
        self.sa.execute(['unixperms', 'fix'])
        if 'apache' in self.init_vars['enable_features']:
            self.sa.execute(['apacheconf', 'create', 'all'])
        if 'nginx' in self.init_vars['enable_features']:
            self.sa.execute(['nginxconf', 'create', 'all'])
        if 'trac' in self.init_vars['enable_features']:
            self.sa.execute(['trac', 'init'])
예제 #23
0
 def testCompleteVhostIPv6WithPort(self):
     options.set_value('http_vhost', 'http://[2001:db8::1]:80/')
     self.assertGreater(len(generate_acl_list()), 2)
예제 #24
0
 def testVhostWithoutSchemeWithPort(self):
     options.set_value('http_vhost', 'example.net:80')
     self.assertGreater(len(generate_acl_list()), 2)
예제 #25
0
	def testGetOption(self):
		options.set_value('answer', '42')
		c = c_config.c_config(self.sa, ['get', 'answer'])
		c.run()
		self.assertTrue('42' in sys.stdout.getvalue())
예제 #26
0
	def testUnsetOption(self):
		options.set_value('answer', '42')
		c = c_config.c_config(self.sa, ['unset', 'answer'])
		c.run()
		self.assertRaises(UnknownKeyError, options.value, 'answer')
예제 #27
0
 def testVhostWithoutSchemeIPv6WithPort(self):
     options.set_value('http_vhost', '[2001:db8::1]:80')
     self.assertGreater(len(generate_acl_list()), 2)
예제 #28
0
파일: options.py 프로젝트: andy-deng/submin
	def testAbsolutePath(self):
		options.set_value("foo", "/bar")
		self.assertEquals(unicode(options.env_path("foo")), "/bar")
예제 #29
0
	def testVhostWithoutSchemeWithPort(self):
		options.set_value('http_vhost', 'example.net:80')
		self.assertGreater(len(generate_acl_list()), 2)
예제 #30
0
	def create_env(self):
		"""This is called when all info is gathered"""
		for key, value in self.defaults.iteritems():
			if key not in self.init_vars:
				self.init_vars[key] = value

		try:
			self.create_dir(self.env)
			self.create_dir(self.init_vars['svn_dir'])
			self.create_dir(self.init_vars['git_dir'])
			self.create_dir(self.init_vars['conf_dir'])
			self.create_dir(self.init_vars['trac_dir'])
			self.create_dir(self.init_vars['hooks_dir'])
			self.create_dir(Path('auth'))
		except OSError:
			return # already printed error message

		self.sa.execute(['config', 'defaults'])

		# check http_base
		p = self.init_vars['http_base']
		if str(p) == "":
			self.init_vars['http_base'] = Path("/")

		# write changes to config
		from submin.models import options

		default_options = {
			'base_url_submin': self._get_url('submin_url'),
			'base_url_svn': self._get_url('svn_url'),
			'base_url_trac': self._get_url('trac_url'),
			'http_vhost': self.init_vars['http_vhost'],
			'auth_type': 'sql',
			'svn_dir': str(self.init_vars['svn_dir']),
			'git_dir': str(self.init_vars['git_dir']),
			'trac_dir': str(self.init_vars['trac_dir']),
			'svn_authz_file': str(self.init_vars['authz']),
			'smtp_from': self.init_vars['smtp_from'],
			'commit_email_from': self.init_vars['commit_email_from'],
		}
		for (key, value) in default_options.iteritems():
			options.set_value(key, value)

		# add a user
		from submin.models import user
		
		if self.init_vars['create_user'] == "yes":
			# add an admin user
			u = user.add('admin', self.email, send_mail=False)
			u.is_admin = True
			try:
				u.prepare_password_reset('submin2-admin')
			except SendEmailError as e:
				print 'WARNING: Could not send an e-mail, please install a mail server'
				print 'WARNING: You can request a password reset for "admin" on the login page'

		self.sa.execute(['upgrade', 'hooks', 'no-fix-unixperms'])
		self.sa.execute(['unixperms', 'fix'])
		if 'apache' in self.init_vars['enable_features']:
			self.sa.execute(['apacheconf', 'create', 'all'])
		if 'nginx' in self.init_vars['enable_features']:
			self.sa.execute(['nginxconf', 'create', 'all'])
		if 'trac' in self.init_vars['enable_features']:
			self.sa.execute(['trac', 'init'])
예제 #31
0
	def testCompleteVhostIPv6WithPort(self):
		options.set_value('http_vhost', 'http://[2001:db8::1]:80/')
		self.assertGreater(len(generate_acl_list()), 2)
예제 #32
0
 def testGetOption(self):
     options.set_value("foo", "bar")
     self.assertEquals(options.value("foo"), "bar")
예제 #33
0
	def testVhostWithoutSchemeIPv6WithPort(self):
		options.set_value('http_vhost', '[2001:db8::1]:80')
		self.assertGreater(len(generate_acl_list()), 2)
예제 #34
0
 def testAbsolutePath(self):
     options.set_value("foo", "/bar")
     self.assertEquals(unicode(options.env_path("foo")), "/bar")
예제 #35
0
	def testNonsense(self):
		options.set_value('http_vhost', ':80')
		self.assertEquals(len(generate_acl_list()), 2)
예제 #36
0
	def setUp(self):
		self.submin_env = tempfile.mkdtemp(prefix='submin-unittest')
		self.conf_dir = os.path.join(self.submin_env, 'conf')
		os.mkdir(self.conf_dir)
		self.authz_file = os.path.join(self.submin_env, 'conf', 'authz')

		mock_settings.base_dir = self.submin_env
		storage.open(mock_settings)
		storage.database_evolve()
		options.set_value('vcs_plugins', 'svn')
		options.set_value('svn_dir', 'svn')
		options.set_value('trac_dir', 'trac')
		options.set_value('svn_authz_file', 'conf/authz')
		options.set_value('enabled_trac', 'no')
		options.set_value('http_vhost', 'localhost')
		options.set_value('base_url_submin', '/submin')

		self.svn_dir = str(options.env_path('svn_dir'))
		self.trac_dir = str(options.env_path('trac_dir'))
		os.mkdir(self.svn_dir)
		os.mkdir(self.trac_dir)

		# now make some repositories
		self.repositories = [
			{'name': 'foo', 'status': 'ok', 'vcs': 'svn'},
			{'name': 'invalidperm', 'status': 'permission denied', 'vcs': 'svn'},
			{'name': 'invalidperm2', 'status': 'permission denied', 'vcs': 'svn'},
			{'name': 'example', 'status': 'ok', 'vcs': 'svn'},
			{'name': 'subdirs', 'status': 'ok', 'vcs': 'svn'},
		]
		self.has_invalidperm = False
		self.has_invalidperm2 = False
예제 #37
0
파일: options.py 프로젝트: andy-deng/submin
	def testSetOption(self):
		options.set_value("foo", "bar")
		self.assertEquals(options.options(), [(u'git_dir', u'git'), (u'database_version', u'11'), (u'foo', u'bar')])
예제 #38
0
파일: trac.py 프로젝트: andy-deng/submin
	def testNotExists(self):
		options.set_value('env_path', '')
		exists = trac.has_trac_admin()
		self.assertEquals(exists, False)
예제 #39
0
 def testNonsense(self):
     options.set_value('http_vhost', ':80')
     self.assertEquals(len(generate_acl_list()), 2)
예제 #40
0
 def testGetOption(self):
     options.set_value('answer', '42')
     c = c_config.c_config(self.sa, ['get', 'answer'])
     c.run()
     self.assertTrue('42' in sys.stdout.getvalue())
예제 #41
0
파일: c_git.py 프로젝트: andreash/submin
    def subcmd_init(self, args):
        from submin.models import options

        if os.getuid() != 0:
            raise SubminAdminCmdException("Please execute `git init' as root.")

        try:
            sudo_bin = which("sudo")
            git_bin = which("git")
        except ProgramNotFoundError as e:
            raise SubminAdminCmdException(
                'Could not find %s, which is required for git init.' % e.prog)

        from submin.subminadmin import c_unixperms
        apache = www_user()
        self.create_ssh_key(owner=apache)

        # Ask the name of the git user, if it exists ask to use it or bail
        git_user = self.prompt_user(
            "What user should the git-users connect as?", "git")

        from pwd import getpwnam
        # Create git user if it doesn't exist yet.
        try:
            pwd = getpwnam(git_user)
        except KeyError as e:
            self.create_user(git_user, "/home/git")
        #else:
        #    use_it = self.prompt_user("User %s already exists. Use it?" % \
        #            git_user, "Yn")
        #    if use_it.lower() not in ("y", "yes", "yn"):
        #        self.delete_user(git_user)
        #        self.create_user(git_user, "/home/git")

        # Now add the www-user to the git-group and chgrp of essential files
        # (settings file, database and paths.)
        git_pw = getpwnam(git_user)
        # XXX this is problably not necessary anymore
        self.add_user_to_group(apache.pw_name, git_pw.pw_gid)
        self.chgrp_relevant_files(git_uid=git_pw.pw_uid, git_gid=git_pw.pw_gid)

        # Set the git_user option to the git-user
        options.set_value("git_user", git_user)

        # Ask public ssh-host
        ssh_host = self.prompt_user(
            "What is the public host-name of the ssh-server?",
            socket.getfqdn())
        options.set_value("git_ssh_host", ssh_host)

        # Ask internal ssh-host
        internal_ssh_host = self.prompt_user(
            "What is the internal host-name of the ssh-server\n" +
            "(used to, e.g., create repositories over fast local network)?",
            "localhost")
        options.set_value("git_ssh_host_internal", internal_ssh_host)

        # Ask ssh-port (default 22)
        ssh_port = self.prompt_user(
            "On what port is the ssh-server available internally?", "22")
        options.set_value("git_ssh_port", ssh_port)

        # Enable git as a vcs plugin
        vcs_plugins = options.value("vcs_plugins")
        if 'git' not in vcs_plugins.split(','):
            options.set_value("vcs_plugins", "%s,git" % vcs_plugins)

        # Install .ssh/authorized_keys
        # This is kind-of elaborate, since the update-auth command is re-used
        # here, which is intended to be called via ssh. Since that is obviously
        # not possible yet, fake setting the SSH_ORIGINAL_COMMAND by passing it
        # as an environment variable.
        cmd = "sudo -H -u %s SSH_ORIGINAL_COMMAND='update-auth' submin2-admin '%s' git admin" % (
            git_user, options.env_path())
        executeCmd(
            cmd,
            "Could not install authorized_keys-file. Please check whether the git-user has read-access to the submin-environment directory"
        )
예제 #42
0
 def testUnsetOption(self):
     options.set_value('answer', '42')
     c = c_config.c_config(self.sa, ['unset', 'answer'])
     c.run()
     self.assertRaises(UnknownKeyError, options.value, 'answer')
예제 #43
0
	def testCompleteVhostWithPort(self):
		options.set_value('http_vhost', 'http://example.net:80/')
		self.assertGreater(len(generate_acl_list()), 2)