Skip to content

Instantly share code, notes, and snippets.

@dstanek
Created March 23, 2015 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstanek/b6a5ae8daff0e6f9263d to your computer and use it in GitHub Desktop.
Save dstanek/b6a5ae8daff0e6f9263d to your computer and use it in GitHub Desktop.
import collections
import re
import routes
from keystone import assignment
from keystone import auth
from keystone import catalog
from keystone.common import controller
from keystone import credential
from keystone import identity
from keystone import policy
from keystone import resource
from keystone import routers
from keystone import token
from keystone import trust
# NOTE(dstanek): The assignment routes add additional routes at runtime
# if CONF.os_inherit.enabled is True. I always want to gather those
# extra routes.
class CONF:
class os_inherit:
enabled = True
assignment.routers.CONF = CONF
class RouteCollectingMapper(object):
def __init__(self, version):
self._version = version
self.action_map = collections.defaultdict(list)
def connect(self, path, controller=None, action=None, conditions=None):
for method in conditions['method']:
self.action_map[action].append(
(method, '/' + self._version + path))
def wrap_controller(_class):
"""Some controllers used injected things in their __init__.
Since we are not injecting, that won't work.
"""
class UnDIController(_class):
def __init__(self):
pass
return UnDIController
router_modules = [
assignment, auth, catalog, credential, identity, policy, resource
]
mapper = routes.Mapper()
mapper = RouteCollectingMapper('v3')
sub_routers = []
for module in router_modules:
for name in dir(module.controllers):
obj = getattr(module.controllers, name)
if isinstance(obj, type) and issubclass(obj, controller.V3Controller):
setattr(module.controllers, name, wrap_controller(obj))
routers_instance = module.routers.Routers()
routers_instance.append_v3_routers(mapper, sub_routers)
action_re = re.compile(r'identity:([^"]+)"')
for line in open('etc/policy.json'):
if 'identity:' in line:
action = action_re.search(line).groups(0)[0]
for route in mapper.action_map.get(action, []):
print ' "#": "%s %s",' % route
print line,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment