[Checkins] SVN: zc.zopeorgkeyupload/branches/dev/ Initial working
hack.
Jim Fulton
jim at zope.com
Thu May 1 13:28:23 EDT 2008
Log message for revision 86015:
Initial working hack.
Changed:
A zc.zopeorgkeyupload/branches/dev/bootstrap.py
U zc.zopeorgkeyupload/branches/dev/buildout.cfg
U zc.zopeorgkeyupload/branches/dev/setup.py
A zc.zopeorgkeyupload/branches/dev/src/zc/zopeorgkeyupload/
A zc.zopeorgkeyupload/branches/dev/src/zc/zopeorgkeyupload/__init__.py
-=-
Added: zc.zopeorgkeyupload/branches/dev/bootstrap.py
===================================================================
--- zc.zopeorgkeyupload/branches/dev/bootstrap.py (rev 0)
+++ zc.zopeorgkeyupload/branches/dev/bootstrap.py 2008-05-01 17:28:22 UTC (rev 86015)
@@ -0,0 +1,55 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+try:
+ import pkg_resources
+except ImportError:
+ ez = {}
+ exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+ import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+ cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+ os.P_WAIT, sys.executable, sys.executable,
+ '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
Property changes on: zc.zopeorgkeyupload/branches/dev/bootstrap.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: zc.zopeorgkeyupload/branches/dev/buildout.cfg
===================================================================
--- zc.zopeorgkeyupload/branches/dev/buildout.cfg 2008-05-01 17:21:38 UTC (rev 86014)
+++ zc.zopeorgkeyupload/branches/dev/buildout.cfg 2008-05-01 17:28:22 UTC (rev 86015)
@@ -1,12 +1,39 @@
[buildout]
develop = .
-parts = test py
+parts = py config
+extends = ldap.cfg
+find-links = http://downloads.sourceforge.net/python-ldap/python-ldap-2.3.4.tar.gz?modtime=1206796934&big_mirror=0
+index = http://download.zope.org/simple
+versions = versions
-[test]
-recipe = zc.recipe.testrunner
-eggs =
-
[py]
recipe = zc.recipe.egg
-eggs = ${test:eggs}
interpreter = py
+eggs =
+ zc.zopeorgkeyupload
+ zope.publisher
+ zope.server
+ PasteDeploy
+ PasteScript
+ python-ldap
+
+[config]
+recipe = zc.recipe.deployment:configuration
+text =
+ [app:main]
+ use = egg:zope.publisher
+ publication = egg:zc.zopeorgkeyupload
+ host = ${ldap:host}
+ port = ${ldap:port}
+ base = ${ldap:base}
+ keydir = ${buildout:directory}/keys
+
+ [server:main]
+ use = egg:zope.server
+ host = 127.0.0.1
+ port = 8080
+
+
+
+[versions]
+python-ldap = 2.3.4
Modified: zc.zopeorgkeyupload/branches/dev/setup.py
===================================================================
--- zc.zopeorgkeyupload/branches/dev/setup.py 2008-05-01 17:21:38 UTC (rev 86014)
+++ zc.zopeorgkeyupload/branches/dev/setup.py 2008-05-01 17:28:22 UTC (rev 86015)
@@ -11,36 +11,31 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-import os
+name = 'zc.zopeorgkeyupload'
+version = '0.1'
+
from setuptools import setup, find_packages
entry_points = """
+[zope.publisher.publication_factory]
+default = zc.zopeorgkeyupload:Publication
"""
-def read(rname):
- return open(os.path.join(os.path.dirname(__file__), *rname.split('/')
- )).read()
-
-long_description = (
- read('src/zc/?/README.txt')
- + '\n' +
- 'Download\n'
- '--------\n'
- )
-
setup(
- name = '',
- version = '0.1',
+ name = name,
+ version = version,
author = 'Jim Fulton',
author_email = 'jim at zope.com',
description = '',
- long_description=long_description,
license = 'ZPL 2.1',
packages = find_packages('src'),
namespace_packages = ['zc'],
package_dir = {'': 'src'},
- install_requires = ['setuptools'],
+ install_requires = ['setuptools',
+ 'zope.security',
+ 'zope.app.security',
+ ],
zip_safe = False,
entry_points=entry_points,
include_package_data = True,
Added: zc.zopeorgkeyupload/branches/dev/src/zc/zopeorgkeyupload/__init__.py
===================================================================
--- zc.zopeorgkeyupload/branches/dev/src/zc/zopeorgkeyupload/__init__.py (rev 0)
+++ zc.zopeorgkeyupload/branches/dev/src/zc/zopeorgkeyupload/__init__.py 2008-05-01 17:28:22 UTC (rev 86015)
@@ -0,0 +1,120 @@
+import ldap
+import os
+import pwd
+import re
+import zope.app.security.basicauthadapter
+import zope.component
+import zope.publisher.http
+import zope.security.interfaces
+
+zope.component.provideAdapter(zope.publisher.http.HTTPCharsets)
+
+v1re = re.compile(r'\d+ \d+ \d+').match
+command = r'command="/usr/local/bin/scm $SSH_ORIGINAL_COMMAND\" '
+
+class Publication:
+
+ def __init__(self, global_config, host, port, base, keydir):
+ self.host, self.port = host, int(port)
+ self.base, self.keydir = base, keydir
+ self.tmp = os.path.join(keydir, '.tmp')
+
+ def beforeTraversal(self, request):
+ pass
+
+ def getApplication(self, request):
+ return self
+
+ def callTraversalHooks(self, request, ob):
+ pass
+
+ def traverseName(self, request, ob, name):
+ return self
+
+ def afterTraversal(self, request, ob):
+ pass
+
+ def callObject(self, request, ob):
+ cred = zope.app.security.basicauthadapter.BasicAuthAdapter(request)
+ login = cred.getLogin()
+ authorized = False
+ if login is not None:
+ c = ldap.open(self.host, self.port)
+ dn = "cn=%s,%s" % (login, self.base)
+ try:
+ c.bind_s(dn, cred.getPassword())
+ authorized = True
+ c.unbind()
+ except ldap.INVALID_CREDENTIALS:
+ pass
+
+ if not authorized:
+ cred.needLogin('ZopeCVSAdmin')
+ return "You need to register with zope.org."
+
+ try:
+ pwd.getpwnam(login)
+ except KeyError:
+ return "You are not yet a contributor"
+
+ if 'key' not in request.form:
+ return key_form % ''
+
+ key = request.form['key'].read(10000)
+ if len(key) >= 10000:
+ return key_form % 'The key you uploaded is too long!<br />'
+
+ v1keys = []
+ v2keys = []
+ for line in key.split('\n'):
+ if not line.strip():
+ continue
+ if line.strip().startswith('#'):
+ continue
+ if line.strip().split()[0] in ('ssh-dss', 'ssh-rsa'):
+ v2keys.append(command+line)
+ elif v1re(line):
+ v1keys.append(command+line)
+ else:
+ return key_form % (
+ 'The key you uploaded is not properly formatted!<br />')
+
+ if v1keys:
+ open(self.tmp, 'w').write(''.join(v1keys))
+ os.path.rename(self.tmp, os.path.join(self.keydir, login+'-1'))
+
+ if v2keys:
+ open(self.tmp, 'w').write(''.join(v2keys))
+ os.rename(self.tmp, os.path.join(self.keydir, login+'-1'))
+
+ return ("Your keys have been uploaded.\n"
+ "It may take a few minutes for them to become effective.")
+
+ def afterCall(self, request, ob):
+ pass
+
+ def handleException(self, object, request, exc_info, retry_allowed=1):
+ raise exc_info[0], exc_info[1], exc_info[2]
+
+ def endRequest(self, request, ob):
+ pass
+
+ def getDefaultTraversal(self, request, ob):
+ return self, ()
+
+
+key_form = """
+<html>
+ <head>
+ <title>Upload your public SSH key</title>
+ </head>
+ <body>
+ %s
+ <form method="POST" enctype="multipart/form-data">
+ Upload your public SSH key(s):
+ <input type="file" name="key" size="40" /><br />
+ <input type="submit" value="submit" />
+ </form>
+</html>
+"""
+
More information about the Checkins
mailing list