Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: set up FOCA #13

Merged
merged 44 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f56882a
basic structure using foca
psankhe28 Aug 6, 2024
d04f70c
Update tus_storagehandler/config.yaml
psankhe28 Aug 6, 2024
fb391ea
Update tus_storagehandler/storage_handler.yaml
psankhe28 Aug 6, 2024
fdf2431
updated license
psankhe28 Aug 6, 2024
e59a83d
added foca
psankhe28 Aug 9, 2024
cf06b09
fixing lint
psankhe28 Aug 9, 2024
ab0c2c7
formatted file
psankhe28 Aug 9, 2024
4fdab89
added init file
psankhe28 Aug 9, 2024
4c886ed
fixed lint
psankhe28 Aug 9, 2024
588295d
formatting
psankhe28 Aug 9, 2024
c6f8b03
made changes
psankhe28 Aug 10, 2024
b51b695
fixed ruff checks
psankhe28 Aug 10, 2024
439bfff
fixing failed workflows
psankhe28 Aug 10, 2024
ae19407
formatted
psankhe28 Aug 10, 2024
d8ff3a4
changed test
psankhe28 Aug 10, 2024
c9a50d7
formatted test
psankhe28 Aug 10, 2024
e592571
added env desc to readme
psankhe28 Aug 10, 2024
1b7a1d4
removed dotenv
psankhe28 Aug 12, 2024
653cc32
made changes
psankhe28 Aug 13, 2024
e0a3f45
added override for mypy
psankhe28 Aug 13, 2024
e3e04dc
setting up dev and prod env
psankhe28 Aug 13, 2024
f6a1a40
fixed type check
psankhe28 Aug 13, 2024
f6fc7a5
made some changes
psankhe28 Aug 15, 2024
1fca403
fixed lint
psankhe28 Aug 15, 2024
6fe1d25
changed slug
psankhe28 Aug 15, 2024
1f4609c
changed repo url
psankhe28 Aug 15, 2024
3302ff9
changed repo url for license
psankhe28 Aug 15, 2024
94d8b86
changed link
psankhe28 Aug 15, 2024
c8a44d0
changed slug
psankhe28 Aug 16, 2024
02139bf
reverting all changes in project name, slug and repository
psankhe28 Aug 16, 2024
115157f
change
psankhe28 Aug 16, 2024
920cdd3
fixed format
psankhe28 Aug 16, 2024
069a6b5
test changes
psankhe28 Aug 17, 2024
3e080b7
change in workflow
psankhe28 Aug 17, 2024
afaf56c
updated test_operations.py
psankhe28 Aug 18, 2024
faabcaa
fixed the pre commit checks
psankhe28 Aug 19, 2024
6a87cfb
made some readme changes
psankhe28 Aug 19, 2024
225425b
Updated README.md
psankhe28 Aug 19, 2024
a2f7740
Update __init__.py
uniqueg Aug 19, 2024
9068a22
Update README.md
uniqueg Aug 19, 2024
a66c33f
remove environment env
psankhe28 Aug 19, 2024
704ebce
removed enum
psankhe28 Aug 19, 2024
0467881
change in readme
psankhe28 Aug 19, 2024
83cddfc
fixed the table
psankhe28 Aug 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions deployment/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
##### BASE IMAGE #####
FROM elixircloud/foca:20240711-py3.12

##### METADATA #####
LABEL software="Cloud Storage Handler"
LABEL software.description="API for handling files on a cloud storage service"
LABEL software.website="https://github.com/elixir-cloud-aai/tus-storagehandler"
LABEL maintainer.organisation="ELIXIR Cloud & AAI"
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved

## Copy app files
COPY ./tus_storage_handler /app
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved

## Install app
RUN cd /app \
&& poetry install \
&& poetry shell \
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
&& python app.py
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved

WORKDIR /app
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved

CMD ["python", "tus_storage_handler/app.py"]
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions deployment/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.6'
services:

cloud-registry:
image: elixircloud/csh:0.1.0
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
ports:
- "8080:8080"
4,537 changes: 2,648 additions & 1,889 deletions poetry.lock

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ repository = "https://github.com/elixir-cloud-aai/tus-storagehandler"
version = "0.1.0"

[tool.poetry.dependencies]
python = ">=3.11"
python = ">=3.11,<4.0"
foca = "^0.13.0"
connexion = "2.14.2"
multipart = "^0.2.5"
python-multipart = "^0.0.9"
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
python-dotenv = "^1.0.1"
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
pytest = "^8.3.2"
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
requests = "^2.32.3"

[tool.poetry.group.code_quality]
optional = true
Expand Down
21 changes: 21 additions & 0 deletions tests/test_integration/test_operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Integration tests for operations in the service."""

import pytest
import requests

SUCCESS_STATUS_CODE = 200
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved


@pytest.fixture
def base_url():
"""Return the base URL for the service."""
return "http://localhost:8080"


def test_get_root(base_url):
"""Test the root endpoint of the service."""
response = requests.get(f"{base_url}/elixircoud/csh/v1")

assert (
response.status_code == SUCCESS_STATUS_CODE
), f"Expected status code 200, got {response.status_code}"
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion tus_storagehandler/__init__.py
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""This package contains module for the tus_storagehandler."""
"""Cloud Storage Handler."""
1 change: 1 addition & 0 deletions tus_storagehandler/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""API package."""
1 change: 1 addition & 0 deletions tus_storagehandler/api/elixircloud/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Elixircloud API package."""
uniqueg marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions tus_storagehandler/api/elixircloud/csh/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Cloud Storage Handler API package."""
uniqueg marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 12 additions & 0 deletions tus_storagehandler/api/elixircloud/csh/controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Cloud Storage Handler controllers."""

import logging

from flask import jsonify

logger = logging.getLogger(__name__)


def home():
"""Endpoint to return a welcome message."""
return jsonify({"message": "Welcome to the Cloud Storage Handler server!"}), 200
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
57 changes: 57 additions & 0 deletions tus_storagehandler/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""API server entry point."""

import logging
import os
from pathlib import Path

from connexion import FlaskApp # type: ignore
from dotenv import load_dotenv # type: ignore
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
from foca import Foca

load_dotenv()
logger = logging.getLogger(__name__)


def init_app() -> FlaskApp:
"""Initialize and return the FOCA app.

This function initializes the FOCA app by loading the configuration
from the environment variable `TUS_FOCA_CONFIG_PATH` if set, or from
the default path if not. It raises a `FileNotFoundError` if the
configuration file is not found.
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved

Returns:
A Connexion application instance.

Raises:
FileNotFoundError: If the configuration file is not found.
"""
# Determine the configuration path
config_path_env1 = os.getenv("TUS_FOCA_CONFIG_PATH")
print(config_path_env1)
if config_path_env := os.getenv("TUS_FOCA_CONFIG_PATH"):
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
print(config_path_env)
config_path = Path(config_path_env).resolve()
else:
config_path = (
Path(__file__).parents[1] / "deployment" / "config.yaml"
).resolve()
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved

# Check if the configuration file exists
if not config_path.exists():
raise FileNotFoundError(f"Config file not found at: {config_path}")

foca = Foca(
config_file=config_path,
)
return foca.create_app()


def main() -> None:
"""Run FOCA application."""
app = init_app()
app.run(port=app.port)


if __name__ == "__main__":
main()
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
40 changes: 40 additions & 0 deletions tus_storagehandler/config.yaml
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
server:
host: '0.0.0.0'
port: 8080
debug: False
environment: development
testing: False
use_reloader: True

security:
auth:
required: True
add_key_to_claims: True
allow_expired: False
audience: null
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
claim_identity: sub
claim_issuer: iss
algorithms:
- RS256
validation_methods:
- userinfo
- public_key
validation_checks: all

api:
specs:
- path: storage_handler.yaml
append: null
add_operation_fields:
x-openapi-router-controller: tus_storagehandler.api.elixircloud.csh.controllers
connexion:
strict_validation: True
validate_responses: False
options:
swagger_ui: True
serve_spec: True

exceptions:
required_members: [['message'], ['code']]
status_member: ['code']
exceptions: exceptions.exceptions
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 22 additions & 0 deletions tus_storagehandler/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Tus Storage Handler exceptions."""

from werkzeug.exceptions import BadRequest, InternalServerError, NotFound

exceptions = {
Exception: {
"message": "An unexpected error occurred. Please try again.",
"code": 500,
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
},
BadRequest: {
"message": "Invalid request. Please check your input and try again.",
"code": 400,
},
NotFound: {
"message": "The requested resource could not be found.",
"code": 404,
},
InternalServerError: {
"message": "An internal server error occurred in the tus storage handler",
"code": 500,
},
}
10 changes: 0 additions & 10 deletions tus_storagehandler/main.py

This file was deleted.

34 changes: 34 additions & 0 deletions tus_storagehandler/storage_handler.yaml
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
openapi: 3.0.2
info:
version: 1.0.0
title: Cloud Storage Handler
description: API for handling files on a cloud storage service
contact:
name: ELIXIR Cloud & AAI
email: [email protected]
license:
name: Apache 2.0
url: 'https://github.com/elixir-cloud-aai/tus-storagehandler/blob/main/LICENSE'
servers:
- url: /elixircoud/csh/v1
paths:
/:
get:
description: |
Returns a welcome message
operationId: home
responses:
'200':
description: basic response
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: "Welcome to Tus Storage Handler API"
'400':
description: The request is malformed.
'500':
description: An unexpected error occurred.
Loading