Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
michalslomczynski committed Dec 11, 2023
1 parent 081b1dc commit fd1b916
Show file tree
Hide file tree
Showing 8 changed files with 773 additions and 415 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v2
# with:
# python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip codecov flake8
Expand All @@ -37,4 +37,9 @@ jobs:
- name: Run tests
run: |
docker-compose -f docker-compose.test.yml up --build --exit-code-from test
finally:
runs-on: ubuntu-latest
steps:
- name: Cleanup containers
run: |
docker-compose -f docker-compose.test.yml down
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ app-common-python = ">=0.2.5"
boto3 = ">=1.16.13"
botocore = ">=1.19.13"
click = ">=0.7"
connexion = {extras = ["swagger-ui"],version = "==2.14.1"}
connexion = {extras = ["swagger-ui", "uvicorn"], version = "*"}
flask = "==2.2.5"
gitpython = ">=3.1.30"
iso8601 = ">=0.1.12"
Expand All @@ -37,6 +37,7 @@ tornado = ">=6.0.3"
watchtower = ">=1.0.0"
werkzeug = ">=1.0.1"
yarl = ">=1.6.2"
a2wsgi = "*"

[requires]
python_version = "3.9"
1,109 changes: 728 additions & 381 deletions Pipfile.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions vmaas/reposcan/dump.output
2 changes: 2 additions & 0 deletions vmaas/reposcan/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from tornado.ioloop import IOLoop
from tornado.wsgi import WSGIContainer
from prometheus_client import start_http_server
from a2wsgi import ASGIMiddleware

from vmaas.common.config import Config
from vmaas.reposcan.reposcan import create_app, DEFAULT_PATH, DEFAULT_PATH_API
Expand All @@ -11,6 +12,7 @@
application = create_app({DEFAULT_PATH + "/v1": "reposcan.spec.yaml",
DEFAULT_PATH_API + "/v1": "reposcan.spec.yaml",
"": "reposcan.healthz.spec.yaml"})
application = ASGIMiddleware(application) # As of connexion >3.0 ASGI server should be used as default, otherwise wrapped by such middleware.

if __name__ == '__main__':
cfg = Config()
Expand Down
7 changes: 3 additions & 4 deletions vmaas/reposcan/reposcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import connexion
import git
from connexion.options import SwaggerUIOptions
from flask import request
from prometheus_client import generate_latest
from tornado.ioloop import IOLoop, PeriodicCallback
Expand Down Expand Up @@ -926,10 +927,8 @@ def terminate(*_):
for sig in KILL_SIGNALS:
signal.signal(sig, terminate)

app = connexion.App(__name__, options={
'swagger_ui': True,
'openapi_spec_path': '/openapi.json'
})
app = connexion.App(__name__,
swagger_ui_options=SwaggerUIOptions(swagger_ui=True))

# Response validation is disabled due to returing streamed response in GET /pkgtree
# https://github.com/zalando/connexion/pull/467 should fix it
Expand Down
34 changes: 19 additions & 15 deletions vmaas/webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from aiohttp import hdrs
from aiohttp import web
from aiohttp.client_exceptions import ClientConnectionError
from connexion.options import SwaggerUIOptions
from prometheus_client import generate_latest
from jsonschema.exceptions import ValidationError
from vmaas.webapp.cache import Cache
Expand Down Expand Up @@ -564,11 +565,12 @@ def format_error(detail, status):
middlewares.append(gzip_middleware)
middlewares.extend([error_handler, timing_middleware])

app = connexion.AioHttpApp(__name__, options={
'swagger_ui': True,
'openapi_spec_path': '/openapi.json',
'middlewares': middlewares
})
# app = connexion.AsyncApp(__name__, options={
# 'swagger_ui': True,
# 'openapi_spec_path': '/openapi.json',
# 'middlewares': middlewares
# })
app = connexion.AsyncApp(__name__, swagger_ui_options=SwaggerUIOptions(swagger_ui=True))

def metrics(request, **kwargs): # pylint: disable=unused-argument
"""Provide current prometheus metrics"""
Expand All @@ -580,16 +582,18 @@ def dummy_200(request, **kwargs): # pylint: disable=unused-argument
"""Dummy endpoint returning 200"""
return web.Response()

async def on_prepare(request, response): # pylint: disable=unused-argument
"""Hook for preparing new responses"""
response.headers["Access-Control-Allow-Origin"] = "*"
response.headers["Access-Control-Allow-Headers"] = "Content-Type"
response.headers['Access-Control-Allow-Methods'] = 'GET, OPTIONS, POST'

app.app.on_response_prepare.append(on_prepare)
app.app.router.add_get("/metrics", metrics)
app.app.router.add_get("/healthz", HealthHandler.get)
app.app.router.add_route("OPTIONS", "/api/v3/cves", dummy_200)
# async def on_prepare(request, response): # pylint: disable=unused-argument
# """Hook for preparing new responses"""
# response.headers["Access-Control-Allow-Origin"] = "*"
# response.headers["Access-Control-Allow-Headers"] = "Content-Type"
# response.headers['Access-Control-Allow-Methods'] = 'GET, OPTIONS, POST'

# app.app.on_response_prepare.append(on_prepare)
app.add_url_rule("/", 'metrics', metrics)
app.add_url_rule("/", 'healthz', HealthHandler.get)
# app.app.router.add_get("/metrics", metrics)
# app.app.router.add_get("/healthz", HealthHandler.get)
# app.app.router.add_route("OPTIONS", "/api/v3/cves", dummy_200)

for route, spec in specs.items():
app.add_api(spec, resolver=connexion.RestyResolver('app'),
Expand Down
17 changes: 8 additions & 9 deletions vmaas/webapp/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Entry point for the application"""
import asyncio

from aiohttp import web
from prometheus_client import start_http_server
from vmaas.webapp.app import create_app, DEFAULT_PATH, DEFAULT_PATH_API
from vmaas.webapp.app import init_refresh_timer
Expand All @@ -12,17 +10,18 @@

LOGGER = get_logger(__name__)

application = create_app({DEFAULT_PATH + "/v1": "webapp.v1.spec.yaml",
DEFAULT_PATH + "/v2": "webapp.v2.spec.yaml",
DEFAULT_PATH + "/v3": "webapp.v3.spec.yaml",
DEFAULT_PATH_API + "/v1": "webapp.v1.spec.yaml",
DEFAULT_PATH_API + "/v2": "webapp.v2.spec.yaml",
DEFAULT_PATH_API + "/v3": "webapp.v3.spec.yaml"})

if __name__ == '__main__':
init_logging()
# pylint: disable=invalid-name
application = create_app({DEFAULT_PATH + "/v1": "webapp.v1.spec.yaml",
DEFAULT_PATH + "/v2": "webapp.v2.spec.yaml",
DEFAULT_PATH + "/v3": "webapp.v3.spec.yaml",
DEFAULT_PATH_API + "/v1": "webapp.v1.spec.yaml",
DEFAULT_PATH_API + "/v2": "webapp.v2.spec.yaml",
DEFAULT_PATH_API + "/v3": "webapp.v3.spec.yaml"})
init_refresh_timer()
cfg = Config()

start_http_server(int(cfg.metrics_port))
web.run_app(application.app, port=cfg.public_port, access_log_format="%s %r (%a) %Tfs", loop=asyncio.get_event_loop())
application.run("main:application", port=cfg.public_port)

0 comments on commit fd1b916

Please sign in to comment.