-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from CMCC-Foundation/update_release_0.1
Update release 0.1
- Loading branch information
Showing
110 changed files
with
2,991 additions
and
5,221 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: Build Docker images for geolake components and push to the repository | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize] | ||
workflow_dispatch: | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.x" | ||
- name: Install build | ||
run: >- | ||
python3 -m | ||
pip install | ||
build | ||
--user | ||
- name: Build a binary wheel and a source for drivers | ||
run: python3 -m build ./drivers | ||
- name: Set Docker image tag name | ||
run: echo "TAG=$(date +'%Y.%m.%d.%H.%M')" >> $GITHUB_ENV | ||
- name: Login to Scaleway Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
username: nologin | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
registry: ${{ vars.DOCKER_REGISTRY }} | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Build and push drivers | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ./drivers | ||
file: ./drivers/Dockerfile | ||
push: true | ||
build-args: | | ||
REGISTRY=${{ vars.GEOKUBE_REGISTRY }} | ||
tags: | | ||
${{ vars.DOCKER_REGISTRY }}/geolake-drivers:${{ env.TAG }} | ||
${{ vars.DOCKER_REGISTRY }}/geolake-drivers:latest | ||
- name: Build and push datastore component | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ./datastore | ||
file: ./datastore/Dockerfile | ||
push: true | ||
build-args: | | ||
REGISTRY=${{ vars.DOCKER_REGISTRY }} | ||
tags: | | ||
${{ vars.DOCKER_REGISTRY }}/geolake-datastore:${{ env.TAG }} | ||
${{ vars.DOCKER_REGISTRY }}/geolake-datastore:latest | ||
- name: Build and push api component | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ./api | ||
file: ./api/Dockerfile | ||
push: true | ||
build-args: | | ||
REGISTRY=${{ vars.DOCKER_REGISTRY }} | ||
tags: | | ||
${{ vars.DOCKER_REGISTRY }}/geolake-api:${{ env.TAG }} | ||
${{ vars.DOCKER_REGISTRY }}/geolake-api:latest | ||
- name: Build and push executor component | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ./executor | ||
file: ./executor/Dockerfile | ||
push: true | ||
build-args: | | ||
REGISTRY=${{ vars.DOCKER_REGISTRY }} | ||
tags: | | ||
${{ vars.DOCKER_REGISTRY }}/geolake-executor:${{ env.TAG }} | ||
${{ vars.DOCKER_REGISTRY }}/geolake-executor:latest |
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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
FROM rg.nl-ams.scw.cloud/dds-production/geokube:v0.2a5 | ||
WORKDIR /code | ||
COPY ./api/requirements.txt /code/requirements.txt | ||
ARG REGISTRY=rg.fr-par.scw.cloud/geolake | ||
ARG TAG=latest | ||
FROM $REGISTRY/geolake-datastore:$TAG | ||
WORKDIR /app | ||
COPY requirements.txt /code/requirements.txt | ||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt | ||
COPY ./utils/wait-for-it.sh /code/wait-for-it.sh | ||
COPY ./datastore /code/app/datastore | ||
COPY ./db/dbmanager /code/db/dbmanager | ||
COPY ./geoquery/ /code/geoquery | ||
COPY ./resources /code/app/resources | ||
COPY ./api/app /code/app | ||
COPY app /app | ||
EXPOSE 80 | ||
CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"] | ||
CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"] |
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 |
---|---|---|
@@ -1,2 +0,0 @@ | ||
from .context import Context | ||
from .manager import assert_not_anonymous | ||
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,66 @@ | ||
"""The module contains authentication backend""" | ||
from uuid import UUID | ||
|
||
from starlette.authentication import ( | ||
AuthCredentials, | ||
AuthenticationBackend, | ||
UnauthenticatedUser, | ||
) | ||
from dbmanager.dbmanager import DBManager | ||
|
||
import exceptions as exc | ||
from auth.models import DDSUser | ||
from auth import scopes | ||
|
||
|
||
class DDSAuthenticationBackend(AuthenticationBackend): | ||
"""Class managing authentication and authorization""" | ||
|
||
async def authenticate(self, conn): | ||
"""Authenticate user based on `User-Token` header""" | ||
if "User-Token" in conn.headers: | ||
return self._manage_user_token_auth(conn.headers["User-Token"]) | ||
return AuthCredentials([scopes.ANONYMOUS]), UnauthenticatedUser() | ||
|
||
def _manage_user_token_auth(self, user_token: str): | ||
try: | ||
user_id, api_key = self.get_authorization_scheme_param(user_token) | ||
except exc.BaseDDSException as err: | ||
raise err.wrap_around_http_exception() | ||
user_dto = DBManager().get_user_details(user_id) | ||
eligible_scopes = [scopes.AUTHENTICATED] + self._get_scopes_for_user( | ||
user_dto=user_dto | ||
) | ||
if user_dto.api_key != api_key: | ||
raise exc.AuthenticationFailed( | ||
user_dto | ||
).wrap_around_http_exception() | ||
return AuthCredentials(eligible_scopes), DDSUser(username=user_id) | ||
|
||
def _get_scopes_for_user(self, user_dto) -> list[str]: | ||
if user_dto is None: | ||
return [] | ||
eligible_scopes = [] | ||
for role in user_dto.roles: | ||
if "admin" == role.role_name: | ||
eligible_scopes.append(scopes.ADMIN) | ||
continue | ||
# NOTE: Role-specific scopes | ||
# Maybe need some more logic | ||
eligible_scopes.append(role.role_name) | ||
return eligible_scopes | ||
|
||
def get_authorization_scheme_param(self, user_token: str): | ||
"""Get `user_id` and `api_key` if authorization scheme is correct.""" | ||
if user_token is None or user_token.strip() == "": | ||
raise exc.EmptyUserTokenError | ||
if ":" not in user_token: | ||
raise exc.ImproperUserTokenError | ||
user_id, api_key, *rest = user_token.split(":") | ||
if len(rest) > 0: | ||
raise exc.ImproperUserTokenError | ||
try: | ||
_ = UUID(user_id, version=4) | ||
except ValueError as err: | ||
raise exc.ImproperUserTokenError from err | ||
return (user_id, api_key) |
Oops, something went wrong.