-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
235 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Tiler Tests | ||
|
||
on: | ||
|
||
push: | ||
paths: | ||
- 'tiler/**' | ||
|
||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.10] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- 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 | ||
pip install flake8 | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
- name: Tiler tests | ||
env: | ||
# add environment variables for tests | ||
run: | | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# TILER | ||
REQUIRE_AUTH= | ||
API_HOST= | ||
S3_BUCKET_URL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
FROM python:3.11 | ||
LABEL maintainer="[email protected]" | ||
|
||
ENV NAME landgriffon-tiler | ||
ENV USER $NAME | ||
ENV APP_HOME /opt/$NAME | ||
|
||
ARG TILE_LANDGRIFFON_COG_FILENAME | ||
# @todo: The data should be retrieved from a S3 bucket in LG World | ||
#ARG DATA_CORE_COG_SOURCE_URL | ||
|
||
#ARG DATA_CORE_COG_CHECKSUM | ||
|
||
RUN addgroup $USER && adduser --shell /bin/bash --disabled-password --ingroup $USER $USER | ||
|
||
WORKDIR $APP_HOME | ||
RUN chown $USER:$USER $APP_HOME | ||
|
||
COPY requirements.txt requirements.txt | ||
|
||
RUN pip install --no-cache-dir --upgrade -r ./requirements.txt | ||
|
||
|
||
COPY --chown=$USER:$USER app ./app | ||
|
||
#ADD --chown=$USER:$USER --checksum=${DATA_CORE_COG_CHECKSUM} ${DATA_CORE_COG_SOURCE_URL} ./data/${TILE_LANDGRIFFON_COG_FILENAME} | ||
#RUN find ./data -type f -exec chmod ugo-w '{}' \; | ||
|
||
EXPOSE 4000 | ||
USER $USER | ||
|
||
# @todo Consider whether to use a shell script as entrypoint to allow for | ||
# different run modes (e.g. debug, dev, prod, etc.) via Docker commands | ||
|
||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "4000"] |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from pydantic import BaseSettings | ||
from os import getenv | ||
from functools import lru_cache | ||
|
||
|
||
class Settings(BaseSettings): | ||
api_url: str = getenv('API_HOST') | ||
api_port: str = getenv('API_PORT') | ||
s3_bucket_url: str = getenv('S3_BUCKET_URL') | ||
require_auth: str = getenv('REQUIRE_AUTH') | ||
|
||
|
||
@lru_cache() | ||
def get_settings(): | ||
return Settings() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from fastapi import FastAPI, Query | ||
from fastapi.middleware.cors import CORSMiddleware | ||
from titiler.core import TilerFactory | ||
from titiler.core.errors import DEFAULT_STATUS_CODES, add_exception_handlers | ||
from titiler.core.middleware import TotalTimeMiddleware, LoggerMiddleware | ||
from .middlewares.auth_middleware import AuthMiddleware | ||
from .middlewares.url_injector import inject_s3_url | ||
|
||
app = FastAPI(title="LandGriffon Tiler! Because why keep life simple?") | ||
app.add_middleware(TotalTimeMiddleware) | ||
app.add_middleware(LoggerMiddleware) | ||
app.add_middleware(AuthMiddleware) | ||
app.add_middleware(CORSMiddleware, allow_origins=["*"], | ||
allow_methods=["GET"], | ||
allow_headers=["*"], ) | ||
|
||
# single COG tiler. One file can have multiple bands | ||
cog = TilerFactory(router_prefix="/cog", path_dependency=inject_s3_url) | ||
app.include_router(cog.router, tags=["Cloud Optimized GeoTIFF"], prefix="/cog", ) | ||
add_exception_handlers(app, DEFAULT_STATUS_CODES) | ||
|
||
|
||
@app.get("/health", description="Health Check", tags=["Health Check"]) | ||
def ping(): | ||
"""Health check.""" | ||
return {"ping": "pong"} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import requests | ||
from fastapi import Request, Response, HTTPException | ||
from starlette.middleware.base import BaseHTTPMiddleware | ||
import os | ||
from app.config.config import get_settings | ||
|
||
api_url = get_settings().api_url | ||
api_port = get_settings().api_port | ||
|
||
|
||
class AuthMiddleware(BaseHTTPMiddleware): | ||
async def dispatch(self, request: Request, call_next): | ||
env = os.environ.get('PYTHON_ENV') | ||
if env == 'dev': | ||
return await call_next(request) | ||
else: | ||
try: | ||
token = request.headers.get("Authorization") | ||
if not token: | ||
return Response(status_code=400, content="No token found") | ||
headers = { | ||
"Authorization": token | ||
} | ||
response = requests.get(f"{api_url}:{api_port}/auth/validate-token", headers=headers) | ||
if response.status_code != 200: | ||
return Response(status_code=401, content="Unauthorized") | ||
return await call_next(request) | ||
|
||
|
||
except Exception as e: | ||
print(e) | ||
raise HTTPException(status_code=500, detail=str(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from fastapi.params import Query | ||
|
||
from ..config.config import get_settings | ||
|
||
|
||
def inject_s3_url(url: str | None = Query(default=None, description="Optional dataset URL")) -> str: | ||
s3_url = get_settings().s3_bucket_url | ||
return s3_url + url |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from fastapi.testclient import TestClient | ||
from ..main import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_auth_middleware(): | ||
"""Should throw a Unauthorized Exception if no token has been provided""" | ||
response = client.get("/cog/info") | ||
assert response.status_code == 400 | ||
assert response.text == 'No token found' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
titiler.application==0.11.0 | ||
uvicorn | ||
requests~=2.28.2 | ||
pytest~=7.2.1 |