First step AuthorizedPrincipalCommand added
This commit is contained in:
parent
7b97347875
commit
bd57935d6e
3 changed files with 95 additions and 1 deletions
|
@ -38,7 +38,7 @@ class App(object):
|
|||
self.handle_args(parser, cfg, options, args)
|
||||
|
||||
def setup_basic_logging(self):
|
||||
logging.basicConfig(filename='gitosis.log', level=10)
|
||||
logging.basicConfig()
|
||||
|
||||
def create_parser(self):
|
||||
parser = optparse.OptionParser()
|
||||
|
|
93
gitosis/principals.py
Normal file
93
gitosis/principals.py
Normal file
|
@ -0,0 +1,93 @@
|
|||
"""
|
||||
Perform gitosis actions for a git hook.
|
||||
"""
|
||||
|
||||
import errno
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
|
||||
from gitosis import repository
|
||||
from gitosis import ssh
|
||||
from gitosis import ssh_principals
|
||||
from gitosis import gitweb
|
||||
from gitosis import gitdaemon
|
||||
from gitosis import app
|
||||
from gitosis import util
|
||||
|
||||
def serve_principal(sshUser, principal):
|
||||
print "Do nothing"
|
||||
|
||||
def post_update(cfg, git_dir):
|
||||
export = os.path.join(git_dir, 'gitosis-export')
|
||||
try:
|
||||
shutil.rmtree(export)
|
||||
except OSError, e:
|
||||
if e.errno == errno.ENOENT:
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
repository.export(git_dir=git_dir, path=export)
|
||||
os.rename(
|
||||
os.path.join(export, 'gitosis.conf'),
|
||||
os.path.join(export, '..', 'gitosis.conf'),
|
||||
)
|
||||
# re-read config to get up-to-date settings
|
||||
cfg.read(os.path.join(export, '..', 'gitosis.conf'))
|
||||
gitweb.set_descriptions(
|
||||
config=cfg,
|
||||
)
|
||||
generated = util.getGeneratedFilesDir(config=cfg)
|
||||
gitweb.generate_project_list(
|
||||
config=cfg,
|
||||
path=os.path.join(generated, 'projects.list'),
|
||||
)
|
||||
gitdaemon.set_export_ok(
|
||||
config=cfg,
|
||||
)
|
||||
authorized_keys = util.getSSHAuthorizedKeysPath(config=cfg)
|
||||
ssh.writeAuthorizedKeys(
|
||||
path=authorized_keys,
|
||||
keydir=os.path.join(export, 'keydir'),
|
||||
)
|
||||
principals = util.getSSHPrincipalsPath(config=cfg)
|
||||
ssh_principals.writePrincipals(
|
||||
path=principals,
|
||||
principals=os.path.join(export, 'keydir/principals'),
|
||||
)
|
||||
|
||||
class Main(app.App):
|
||||
def create_parser(self):
|
||||
parser = super(Main, self).create_parser()
|
||||
parser.set_usage('%prog [OPTS] sshUser principal principal ...')
|
||||
parser.set_description(
|
||||
'Serves principals as AuthorizedPrincipalsCommand ')
|
||||
return parser
|
||||
|
||||
def handle_args(self, parser, cfg, options, args):
|
||||
try:
|
||||
(sshUser, principals) = args
|
||||
except ValueError:
|
||||
parser.error('Missing argument sshUsers and/or principals.')
|
||||
|
||||
log = logging.getLogger('gitosis.principals')
|
||||
os.umask(0022)
|
||||
|
||||
git_dir = os.environ.get('GIT_DIR')
|
||||
|
||||
if sshUser != "":
|
||||
log.info('Running serve_principal for user %s', sshUser)
|
||||
serve_printipal(sshUser, principal)
|
||||
log.info('Done.')
|
||||
|
||||
# if git_dir is None:
|
||||
# log.error('Must have GIT_DIR set in enviroment')
|
||||
# sys.exit(1)
|
||||
#
|
||||
# if hook == 'post-update':
|
||||
# log.info('Running hook %s', hook)
|
||||
# post_update(cfg, git_dir)
|
||||
# log.info('Done.')
|
||||
# else:
|
||||
# log.warning('Ignoring unknown hook: %r', hook)
|
1
setup.py
1
setup.py
|
@ -45,6 +45,7 @@ arbitrary commands.
|
|||
'gitosis-serve = gitosis.serve:Main.run',
|
||||
'gitosis-run-hook = gitosis.run_hook:Main.run',
|
||||
'gitosis-init = gitosis.init:Main.run',
|
||||
'gitosis-authorized-principals = gitosis.principals:Main.run',
|
||||
],
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue