2013-03-05 13:14:43 +00:00
|
|
|
import sys
|
2013-07-26 18:42:32 +00:00
|
|
|
import argparse
|
2013-03-05 13:14:43 +00:00
|
|
|
|
|
|
|
from flask import Flask
|
|
|
|
from werkzeug.routing import BaseConverter
|
|
|
|
|
2013-07-26 19:14:34 +00:00
|
|
|
from moto.backends import BACKENDS
|
2013-03-05 13:14:43 +00:00
|
|
|
from moto.core.utils import convert_flask_to_httpretty_response
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
HTTP_METHODS = ["GET", "POST", "PUT", "DELETE", "HEAD"]
|
|
|
|
|
|
|
|
|
|
|
|
class RegexConverter(BaseConverter):
|
|
|
|
# http://werkzeug.pocoo.org/docs/routing/#custom-converters
|
|
|
|
def __init__(self, url_map, *items):
|
|
|
|
super(RegexConverter, self).__init__(url_map)
|
|
|
|
self.regex = items[0]
|
|
|
|
|
|
|
|
|
|
|
|
def configure_urls(service):
|
2013-07-26 19:14:34 +00:00
|
|
|
backend = BACKENDS[service]
|
2013-03-05 13:14:43 +00:00
|
|
|
from werkzeug.routing import Map
|
2013-06-25 16:36:21 +00:00
|
|
|
# Reset view functions to reset the app
|
|
|
|
app.view_functions = {}
|
2013-03-05 13:14:43 +00:00
|
|
|
app.url_map = Map()
|
|
|
|
app.url_map.converters['regex'] = RegexConverter
|
|
|
|
for url_path, handler in backend.flask_paths.iteritems():
|
|
|
|
app.route(url_path, methods=HTTP_METHODS)(convert_flask_to_httpretty_response(handler))
|
|
|
|
|
|
|
|
|
2013-07-26 19:03:16 +00:00
|
|
|
def main(argv=sys.argv[1:]):
|
2013-07-26 19:14:34 +00:00
|
|
|
available_services = BACKENDS.keys()
|
2013-07-26 18:42:32 +00:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
'service', type=str,
|
|
|
|
choices=available_services,
|
|
|
|
help='Choose which mechanism you want to run')
|
|
|
|
parser.add_argument(
|
|
|
|
'-H', '--host', type=str,
|
|
|
|
help='Which host to bind',
|
|
|
|
default='0.0.0.0')
|
|
|
|
parser.add_argument(
|
|
|
|
'-p', '--port', type=int,
|
|
|
|
help='Port number to use for connection',
|
|
|
|
default=5000)
|
|
|
|
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
|
|
|
|
configure_urls(args.service)
|
2013-03-05 13:14:43 +00:00
|
|
|
|
|
|
|
app.testing = True
|
2013-07-26 18:42:32 +00:00
|
|
|
app.run(host=args.host, port=args.port)
|
2013-03-05 13:14:43 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|