Example #1
0
def create():
    out = StringIO.StringIO()
    write_file = True

    try:
        custom = open(os.path.expanduser('~/authorized_keys.custom')).read()
    except IOError:
        print '~/authorized_keys.custom not found - not updating SSH keys'
        write_file = False
        custom = ''

    out.write('# ~/authorized_keys.custom\n')
    out.write(custom)
    out.write('\n# autogenerated\n')

    auth_cmd = 'python -m gitjoin.git_auth'

    for key in models.SSHKey.objects.all():
        keydata = tools.reformat_ssh_key(key.data)
        fingerprint = key.fingerprint
        correct_fingerprint = tools.get_ssh_key_fingerprint(key.data)

        if fingerprint != correct_fingerprint:
            # fill in missing/incorrect data
            fingerprint = key.fingerprint = correct_fingerprint
            key.save()

        out.write(('command="cd %s && source activate_base.inc && %s %s",'
                   'no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s\n')
                  % (pipes.quote(settings.APP_ROOT), auth_cmd, fingerprint, keydata))

    if write_file:
        tools.overwrite_file(os.path.expanduser('~/.ssh/authorized_keys'), out.getvalue())
Example #2
0
    def set_hook(self, name, value):
        if not os.path.exists(self.path + '/hooks'):
            os.mkdir(self.path + '/hooks')

        assert '/' not in name
        path = self.path + '/hooks/' + name
        tools.overwrite_file(path, value)
        os.chmod(path, 0o755)