Permalink
Browse files

first import

  • Loading branch information...
0 parents commit aa8469da46279d015a046814fea44a4bd4a6dd4e @leifj committed Jul 4, 2012
Showing with 5,834 additions and 0 deletions.
  1. +12 −0 .gitignore
  2. +11 −0 .hgignore
  3. +19 −0 HACKING.txt
  4. +2 −0 MANIFEST.in
  5. +23 −0 NEWS.txt
  6. +23 −0 README.rst
  7. +113 −0 bootstrap.py
  8. +13 −0 buildout.cfg
  9. +46 −0 setup.py
  10. +98 −0 src/pyff/__init__.py
  11. +47 −0 src/pyff/decorators.py
  12. +40 −0 src/pyff/feed.py
  13. +71 −0 src/pyff/mdrepo.py
  14. +12 −0 src/pyff/pipeline.py
  15. +112 −0 src/pyff/schema/MetadataExchange.xsd
  16. +205 −0 src/pyff/schema/cs-sstc-schema-assertion-1.1.xsd
  17. +195 −0 src/pyff/schema/oasis-200401-wss-wssecurity-secext-1.0.xsd
  18. +108 −0 src/pyff/schema/oasis-200401-wss-wssecurity-utility-1.0.xsd
  19. +75 −0 src/pyff/schema/privacy.xsd
  20. +281 −0 src/pyff/schema/saml-schema-assertion-2.0.xsd
  21. +333 −0 src/pyff/schema/saml-schema-metadata-2.0.xsd
  22. +42 −0 src/pyff/schema/shibboleth-metadata-1.0.xsd
  23. +60 −0 src/pyff/schema/shibboleth-trust-1.0.xsd
  24. +296 −0 src/pyff/schema/shibboleth.xsd
  25. +35 −0 src/pyff/schema/sstc-metadata-attr.xsd
  26. +25 −0 src/pyff/schema/sstc-saml-idp-discovery.xsd
  27. +41 −0 src/pyff/schema/sstc-saml-metadata-algsupport.xsd
  28. +87 −0 src/pyff/schema/sstc-saml-metadata-ui-v1.0.xsd
  29. +283 −0 src/pyff/schema/sstc-saml-schema-assertion-2.0.xsd
  30. +333 −0 src/pyff/schema/sstc-saml-schema-metadata-2.0.xsd
  31. +137 −0 src/pyff/schema/ws-addr.xsd
  32. +144 −0 src/pyff/schema/ws-authorization.xsd
  33. +464 −0 src/pyff/schema/ws-federation.xsd
  34. +1,204 −0 src/pyff/schema/ws-securitypolicy-1.2.xsd
  35. +136 −0 src/pyff/schema/xenc-schema.xsd
  36. +287 −0 src/pyff/schema/xml.xsd
  37. +317 −0 src/pyff/schema/xmldsig-core-schema.xsd
  38. +33 −0 src/pyff/utils.py
  39. +46 −0 src/pyff/xslt/pp.xsl
  40. +25 −0 src/pyff/xslt/tidy.xsl
@@ -0,0 +1,12 @@
+*.pyc
+
+.installed.cfg
+bin
+develop-eggs
+
+*.egg-info
+
+tmp
+build
+dist
+.idea
@@ -0,0 +1,11 @@
+syntax: glob
+
+.installed.cfg
+bin
+develop-eggs
+
+*.egg-info
+
+tmp
+build
+dist
@@ -0,0 +1,19 @@
+Development setup
+=================
+
+To create a buildout,
+
+ $ python bootstrap.py
+ $ bin/buildout
+
+Release HOWTO
+=============
+
+To make a release,
+
+ 1) Update release date/version in NEWS.txt and setup.py
+ 2) Run 'python setup.py sdist'
+ 3) Test the generated source distribution in dist/
+ 4) Upload to PyPI: 'python setup.py sdist register upload'
+ 5) Increase version in setup.py (for next release)
+
@@ -0,0 +1,2 @@
+include README.rst
+include NEWS.txt
@@ -0,0 +1,23 @@
+.. This is your project NEWS file which will contain the release notes.
+.. Example: http://www.python.org/download/releases/2.6/NEWS.txt
+.. The content of this file, along with README.rst, will appear in your
+.. project's PyPI page.
+
+News
+====
+
+0.2a1
+-----
+
+*Release date: UNRELEASED*
+
+* Example news entry for the in-development version
+
+
+0.1
+---
+
+*Release date: 15-Mar-2010*
+
+* Example news entry for a released version
+
@@ -0,0 +1,23 @@
+This file requires editing
+==========================
+
+Note to the author: Please add something informative to this README *before*
+releasing your software, as `a little documentation goes a long way`_. Both
+README.rst (this file) and NEWS.txt (release notes) will be included in your
+package metadata which gets displayed in the PyPI page for your project.
+
+You can take a look at the README.txt of other projects, such as repoze.bfg
+(http://bfg.repoze.org/trac/browser/trunk/README.txt) for some ideas.
+
+.. _`a little documentation goes a long way`: http://www.martinaspeli.net/articles/a-little-documentation-goes-a-long-way
+
+Credits
+-------
+
+- `Distribute`_
+- `Buildout`_
+- `modern-package-template`_
+
+.. _Buildout: http://www.buildout.org/
+.. _Distribute: http://pypi.python.org/pypi/distribute
+.. _`modern-package-template`: http://pypi.python.org/pypi/modern-package-template
@@ -0,0 +1,113 @@
+##############################################################################
+#
+# 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: bootstrap.py 102545 2009-08-06 14:49:47Z chrisw $
+"""
+
+import os, shutil, sys, tempfile, urllib2
+from optparse import OptionParser
+
+tmpeggs = tempfile.mkdtemp()
+
+is_jython = sys.platform.startswith('java')
+
+# parsing arguments
+parser = OptionParser()
+parser.add_option("-v", "--version", dest="version",
+ help="use a specific zc.buildout version")
+parser.add_option("-d", "--distribute",
+ action="store_true", dest="distribute", default=True,
+ help="Use Disribute rather than Setuptools.")
+
+options, args = parser.parse_args()
+
+if options.version is not None:
+ VERSION = '==%s' % options.version
+else:
+ VERSION = ''
+
+USE_DISTRIBUTE = options.distribute
+args = args + ['bootstrap']
+
+to_reload = False
+try:
+ import pkg_resources
+ if not hasattr(pkg_resources, '_distribute'):
+ to_reload = True
+ raise ImportError
+except ImportError:
+ ez = {}
+ if USE_DISTRIBUTE:
+ exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
+ ).read() in ez
+ ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True)
+ else:
+ exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+ if to_reload:
+ reload(pkg_resources)
+ else:
+ import pkg_resources
+
+if sys.platform == 'win32':
+ def quote(c):
+ if ' ' in c:
+ return '"%s"' % c # work around spawn lamosity on windows
+ else:
+ return c
+else:
+ def quote (c):
+ return c
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+ws = pkg_resources.working_set
+
+if USE_DISTRIBUTE:
+ requirement = 'distribute'
+else:
+ requirement = 'setuptools'
+
+if is_jython:
+ import subprocess
+
+ assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
+ quote(tmpeggs), 'zc.buildout' + VERSION],
+ env=dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse(requirement)).location
+ ),
+ ).wait() == 0
+
+else:
+ assert os.spawnle(
+ os.P_WAIT, sys.executable, quote (sys.executable),
+ '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION,
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse(requirement)).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout' + VERSION)
+import zc.buildout.buildout
+zc.buildout.buildout.main(args)
+shutil.rmtree(tmpeggs)
@@ -0,0 +1,13 @@
+[buildout]
+parts = python scripts
+develop = .
+eggs = pyFF
+
+[python]
+recipe = zc.recipe.egg
+interpreter = python
+eggs = ${buildout:eggs}
+
+[scripts]
+recipe = zc.recipe.egg:scripts
+eggs = ${buildout:eggs}
@@ -0,0 +1,46 @@
+from setuptools import setup, find_packages
+import sys, os
+
+here = os.path.abspath(os.path.dirname(__file__))
+README = open(os.path.join(here, 'README.rst')).read()
+NEWS = open(os.path.join(here, 'NEWS.txt')).read()
+
+
+version = '0.1'
+
+install_requires = [
+ 'lxml',
+ 'dm.xmlsec.binding',
+ 'yaml'
+ # List your project dependencies here.
+ # For more details, see:
+ # http://packages.python.org/distribute/setuptools.html#declaring-dependencies
+]
+
+
+setup(name='pyFF',
+ version=version,
+ description="Federation Feeder",
+ long_description=README + '\n\n' + NEWS,
+ classifiers=[
+ # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+ ],
+ keywords='identity federation saml metadata',
+ author='Leif Johansson',
+ author_email='leifj@sunet.se',
+ url='http://blogs.mnt.se',
+ license='BSD',
+ packages=find_packages('src'),
+ package_dir = {'': 'src'},
+ include_package_data=True,
+ package_data = {
+ 'pyff': ['xslt/*.xsl','schema/*.xsd']
+ },
+ zip_safe=False,
+ install_requires=install_requires,
+ entry_points={
+ 'console_scripts':
+ ['pyFF=pyff:main']
+ },
+ requires=install_requires
+)
@@ -0,0 +1,98 @@
+import sys
+import getopt
+import os
+import hashlib
+import lxml.etree as etree
+from pyff.feed import import_feed
+from pyff.utils import resource_string
+from pyff.mdrepo import NS,MDRepository
+
+def process(fn,md,stdout):
+ """
+ Load one feed specifier and process it
+ """
+ feed = import_feed(fn)
+ name = feed.get('Name',fn)
+
+ for u in feed.get('inputs',[]):
+ if type(u) is dict:
+ url = u.get('url',None)
+ if url is not None and (url.startswith("http://") or url.startswith("https:") or url.startswith("ftp://")):
+ md.load_url(url,md,verify=u.get('verify',None))
+ else:
+ raise Exception,"Unknown metadata input format: %s" % u
+ elif os.path.isdir(u):
+ md.load_dir(u,md)
+ else:
+ raise Exception,"Unknown metadata input: %s" % u
+
+ t = md.entity_set(md,feed.get('entities',md.keys()),name,feed.get('cacheDuration',None),feed.get('validUntil',None))
+ for ts in feed.get('pipeline',[]):
+ # apply an xslt stylesheet
+ stylesheet = ts.pop('stylesheet',None)
+ if stylesheet is not None:
+ xslt = etree.parse(resource_string(stylesheet,"xslt"))
+ transform = etree.XSLT(xslt)
+ # this is to make sure the parameters are passed as xslt strings
+ d = dict((k,"\'%s\'" % v) for (k,v) in ts.items())
+ ot = transform(t,**d)
+ t = ot
+ # split into EntityDescriptor-parts and save in target_dir/sha1(@entityID).xml
+ target_dir = ts.pop('store',None)
+ if target_dir is not None:
+ if not os.path.isdir(target_dir):
+ os.makedirs(target_dir)
+ for e in t.xpath("//md:EntityDescriptor",namespaces=NS):
+ eid = e.get('entityID')
+ if eid is None or len(eid) == 0:
+ raise Exception,"Missing entityID in %s" % e
+ m = hashlib.sha1()
+ m.update(eid)
+ d = m.hexdigest()
+ with open("%s.xml" % os.path.join(target_dir,d),"w") as fn:
+ fn.write(etree.tostring(e,encoding='UTF-8',xml_declaration=True,pretty_print=True))
+ # sign
+ key_name = ts.pop("sign",None)
+ if key_name is not None:
+ # TODO sign
+ #t = ot
+ pass
+ # write to file
+ output_file = ts.pop("publish",None)
+ if output_file is not None:
+ out = output_file
+ if os.path.isdir(output_file):
+ out = os.path.join(output_file,os.path.splitext(fn)[0])
+ with open(out,"w") as fo:
+ fo.write(etree.tostring(t,encoding='UTF-8',xml_declaration=True,pretty_print=True))
+ # print entityIDs on stdout
+ if ts.has_key('showeids'):
+ for e in t.xpath("//md:EntityDescriptor",namespaces=NS):
+ print e.get('entityID')
+
+
+ md[name] = t
+
+def main():
+ # parse command line options
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
+ except getopt.error, msg:
+ print msg
+ print "for help use --help"
+ sys.exit(2)
+ # process options
+
+ md=MDRepository()
+ for o, a in opts:
+ if o in ("-h", "--help"):
+ print __doc__
+ sys.exit(0)
+
+ # process arguments
+
+ for arg in args:
+ process(arg,md)
+
+if __name__ == "__main__":
+ main()
Oops, something went wrong.

0 comments on commit aa8469d

Please sign in to comment.