def test_skitai(app): skitai.set_worker_critical_point() skitai.deflu("a", "b") assert (skitai.dconf["models-keys"] == ["a", "b"]) if os.name != "posix": return assert skitai.joinpath('a', 'b').endswith("/bin/a/b") skitai.mount("/k", app) assert skitai.dconf['mount']["default"][0][1][0].endswith('/bin/pytest') assert skitai.dconf['mount']["default"][0][1][1] == 'app' skitai.dconf['mount']["default"] = [] skitai.mount("/k2", '/path/app.py', 'app') assert skitai.dconf['mount']["default"][0][1] == ('/path/app.py', 'app') skitai.dconf['mount']["default"] = [] skitai.mount("/k2", 'path/app.py', 'app') assert skitai.dconf['mount']["default"][0][1][0].endswith( '/bin/path/app.py') assert skitai.dconf['mount']["default"][0][1][1] == 'app' if tfserver: pref = skitai.pref() pref.config.tf_models = None skitai.dconf['mount']["default"] = [] skitai.mount("/k2", tfserver, pref=pref) assert skitai.dconf['mount']["default"][0][1][0].endswith( 'tfserver/export/skitai/__export__.py') skitai.dconf['mount']["default"] = [] skitai.mount("/k2", (tfserver, "dapp"), "dapp", pref=pref) assert skitai.dconf['mount']["default"][0][1][0].endswith( 'tfserver/export/skitai/dapp') assert skitai.dconf['mount']["default"][0][1][1] == "dapp" skitai.dconf['mount']["default"] = [] skitai.mount("/k2", "X11") assert skitai.dconf['mount']["default"][0][1][0].endswith('/bin/X11') skitai.dconf['mount']["default"] = [] skitai.mount("/k2", "@X11") assert skitai.dconf['mount']["default"][0][1] == "@X11" if django: skitai.dconf['mount']["default"] = [] t = os.path.join(os.path.dirname(__file__), "django_") skitai.mount("/k2", t) assert skitai.dconf['mount']["default"][0][1] == t skitai.dconf['mount']["default"] = [] t = os.path.join(os.path.dirname(__file__), "django_", "wsgi.py") skitai.mount("/k2", t, "application") t = os.path.join(os.path.dirname(__file__), "django_", "settings.py") skitai.alias("@django", skitai.DJANGO, t) assert skitai.dconf["clusters"]["django"]
def setup_was (wasc): def add_cluster (wasc, name, args): ctype, members, policy, ssl, max_conns = args wasc.add_cluster (ctype, name, members, ssl, policy, max_conns) # was and testutil was share objects try: wasc.register ("logger", logger ()) except AttributeError: # class has been already setup return wasc wasc.register ("httpserver", server.Server (wasc.logger)) wasc.register ("debug", False) wasc.register ("clusters", {}) wasc.register ("clusters_for_distcall", {"__socketpool__": None, "__dbpool__": None}) wasc.register ("workers", 1) wasc.register ("cachefs", cachefs.CacheFileSystem (None, 0, 0)) wasc.register ("executors", executors.Executors ()) websocekts.start_websocket (wasc) wasc.register ("websockets", websocekts.websocket_servers) add_cluster (wasc, *skitai.alias ("@example", PROTO_HTTP, "www.example.com")) add_cluster (wasc, *skitai.alias ("@examples", PROTO_HTTPS, "www.example.com")) add_cluster (wasc, *skitai.alias ("@sqlite3", DB_SQLITE3, SAMPLE_DBPATH)) add_cluster (wasc, *skitai.alias ("@postgresql", DB_PGSQL, "user:[email protected]/mydb")) add_cluster (wasc, *skitai.alias ("@mongodb", DB_MONGODB, "127.0.0.1:27017/mydb")) add_cluster (wasc, *skitai.alias ("@redis", DB_REDIS, "127.0.0.1:6379")) return wasc
from atila import Atila import time, math import json from package import route_guide_pb2 app = Atila(__name__) app.debug = True app.use_reloader = True @app.route("/") def RouteChat(was): return "<h1>Reverse Proxing</h1><a href='/lb/pypi'>Click Here</a>" if __name__ == "__main__": import skitai skitai.alias("@pypi", skitai.PROTO_HTTPS, "pypi.org") skitai.mount("/", app) skitai.mount("/lb", "@pypi") skitai.run(port=30371)
time.sleep (int (wait)) return was.response.api (data = "JSON") @app.route ("/shutdown") def shutdown (was, stream_id = 1): was.request.protocol.close (last_stream_id = int (stream_id)) return 'CLOSED' if __name__ == "__main__": import skitai if os.name == "nt": skitai.set_service (ServiceConfig) skitai.alias ("@pypi", skitai.PROTO_HTTPS, "pypi.org") skitai.alias ("@sqlite3", skitai.DB_SQLITE3, "resources/sqlite3.db") skitai.alias ("@sqlite3m", skitai.DB_SQLITE3, ["resources/sqlite3-1.db", "resources/sqlite3-2.db"]) skitai.mount ("/", 'statics') skitai.mount ("/", app) skitai.mount ("/websocket", 'websocket.py') skitai.mount ("/rpc2", 'rpc2.py') skitai.mount ("/routeguide.RouteGuide", 'grpc_route_guide.py') skitai.mount ("/members", 'auth.py') skitai.mount ("/lb", "@pypi") skitai.enable_proxy () skitai.run ( port = 30371, workers = 1,
# For JWT Claim def handle_claim(self, handler, request): claim = request.claim expires = claim.get("expires", 0) if expires and expires < time.time(): return handler.continue_request(request) handler.continue_request(request, claim.get("user"), claim.get("roles")) @app.startup def startup(wasc): wasc.handler.set_auth_handler(Authorizer()) @app.route("/") def index(was): return "<h1>Skitai App Engine: API Gateway</h1>" if __name__ == "__main__": import skitai skitai.alias("@pypi", skitai.PROTO_HTTP, "gall.dcinside.com") skitai.alias("@postgres", skitai.DB_PGSQL, "127.0.0.1:5432/mydb/postgres/1111") skitai.mount('/', app) skitai.mount('/lb', '@pypi') skitai.enable_gateway(True, "8fa06210-e109-11e6-934f-001b216d6e71", "Skitai API Gateway") skitai.run(address="0.0.0.0", port=30371)