Skip to content

Commit

Permalink
Add versioned endpoints (#92)
Browse files Browse the repository at this point in the history
* Split up ETOS API into v0 and v1alpha

This also has the added effect of separating the API docs to
/api/docs, /api/v0/docs and /api/v1alpha/docs.
The default ETOS API version shall be served on /api
Also removed some unecessary code and routers and moved the
selftest to /api/etos/ping and /api/version/etos/ping so that
we can start doing a few checks when the client pings ETOS.
The old /selftest/ping endpoint still exists, but redirects
to the default API version/ping
  • Loading branch information
t-persson authored Nov 27, 2024
1 parent 0b44651 commit 0dba3c3
Show file tree
Hide file tree
Showing 22 changed files with 348 additions and 674 deletions.
4 changes: 2 additions & 2 deletions manifests/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ spec:
protocol: TCP
livenessProbe:
httpGet:
path: /selftest/ping
path: /api/etos/ping
port: http
readinessProbe:
httpGet:
path: /selftest/ping
path: /api/etos/ping
port: http
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ classifiers = [
]
requires-python = ">=3.9"
dependencies = [
"etos_lib==4.4.1",
"etos_lib==4.4.2",
"etcd3gw~=2.3",
"uvicorn~=0.22",
"fastapi~=0.109.1",
Expand Down
2 changes: 1 addition & 1 deletion python/src/etos_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
trace.set_tracer_provider(PROVIDER)

FastAPIInstrumentor().instrument_app(
APP, tracer_provider=PROVIDER, excluded_urls="selftest/.*,logs/.*"
APP, tracer_provider=PROVIDER, excluded_urls=".*/etos/ping"
)

RegisterProviders()
45 changes: 7 additions & 38 deletions python/src/etos_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""ETOS API."""
import logging

from fastapi import FastAPI
from etos_api.routers.v0 import ETOSv0
from etos_api.routers.v1alpha import ETOSv1Alpha

from starlette.responses import RedirectResponse

from etos_api import routers

# This allows the path to start either at '/api' or '/'.
APP = FastAPI(root_path="/api")
LOGGER = logging.getLogger(__name__)


@APP.post("/")
async def redirect_post_to_root():
"""Redirect post requests to root to the start ETOS endpoint.
:return: Redirect to etos.
:rtype: :obj:`starlette.responses.RedirectResponse`
"""
LOGGER.debug("Redirecting post requests to the root endpoint to '/etos'")
# DEPRECATED. Exists only for backwards compatibility.
return RedirectResponse(url="/etos", status_code=308) # 308 = Permanent Redirect


@APP.head("/")
async def redirect_head_to_root():
"""Redirect head requests to root to the selftest/ping endpoint.
:return: Redirect to selftest/ping.
:rtype: :obj:`starlette.responses.RedirectResponse`
"""
LOGGER.debug("Redirecting head requests to the root endpoint to '/sefltest/ping'")
# DEPRECATED. Exists only for backwards compatibility.
return RedirectResponse(url="/selftest/ping", status_code=308) # 308 = Permanent Redirect

DEFAULT_VERSION = ETOSv0

APP.include_router(routers.etos.ROUTER)
APP.include_router(routers.testrun.ROUTER)
APP.include_router(routers.selftest.ROUTER)
APP.include_router(routers.logs.ROUTER)
APP = FastAPI()
APP.mount("/api/v1alpha", ETOSv1Alpha, "ETOS V1 Alpha")
APP.mount("/api/v0", ETOSv0, "ETOS V0")
APP.mount("/api", DEFAULT_VERSION, "ETOS V0")
1 change: 0 additions & 1 deletion python/src/etos_api/routers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"""ETOS API routers module."""
import os
from kubernetes import config
from . import etos, testrun, logs, selftest

if os.getenv("RUNNING_TESTS") is None:
try:
Expand Down
16 changes: 0 additions & 16 deletions python/src/etos_api/routers/lib/__init__.py

This file was deleted.

36 changes: 0 additions & 36 deletions python/src/etos_api/routers/lib/kubernetes.py

This file was deleted.

17 changes: 0 additions & 17 deletions python/src/etos_api/routers/logs/__init__.py

This file was deleted.

71 changes: 0 additions & 71 deletions python/src/etos_api/routers/logs/router.py

This file was deleted.

18 changes: 0 additions & 18 deletions python/src/etos_api/routers/selftest/__init__.py

This file was deleted.

39 changes: 0 additions & 39 deletions python/src/etos_api/routers/selftest/router.py

This file was deleted.

16 changes: 0 additions & 16 deletions python/src/etos_api/routers/selftest/schemas.py

This file was deleted.

69 changes: 0 additions & 69 deletions python/src/etos_api/routers/testrun/utilities.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""ETOS API etos module."""
from .router import ROUTER
from .router import ETOSv0
from . import schemas
Loading

0 comments on commit 0dba3c3

Please sign in to comment.