-
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.
Signed-off-by: Pratiksha Sankhe <[email protected]> Co-authored-by: Alex Kanitz <[email protected]> Co-authored-by: Alex Kanitz <[email protected]>
- Loading branch information
1 parent
4f7c103
commit 0b08ba9
Showing
12 changed files
with
944 additions
and
636 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 |
---|---|---|
|
@@ -10,7 +10,7 @@ jobs: | |
detect-unresolved-conflicts: | ||
name: Detect unresolved merge conflicts | ||
runs-on: ubuntu-latest | ||
needs: semantic_pr | ||
needs: semantic-pr | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: List files with merge conflict markers | ||
|
@@ -33,8 +33,13 @@ jobs: | |
poetry-install-options: "--only=misc --no-root" | ||
poetry-export-options: "--only=misc" | ||
|
||
- name: Check all the pre-commit hooks passed | ||
run: pre-commit run --all-files | ||
- name: Install pre-commit | ||
run: pip install pre-commit | ||
|
||
- name: Run pre-commit | ||
uses: pre-commit/[email protected] | ||
with: | ||
config: ../../.pre-commit-config.yaml | ||
|
||
semantic-pr: | ||
name: Semantic PR title | ||
|
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,60 @@ | ||
"""MinIO client class and convenience functions.""" | ||
|
||
import logging | ||
|
||
from connexion import FlaskApp | ||
from minio import Minio | ||
|
||
from cloud_storage_handler.api.elixircloud.csh.models import MinioConfig | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class MinioClient: | ||
"""Client for MinIO operations. | ||
Wraps ``minio.Minio`` and adds convenience methods. | ||
Attributes: | ||
config: MinIO configuration. | ||
client: MinIO client instance. | ||
""" | ||
|
||
def __init__(self, config: MinioConfig) -> None: | ||
"""Class constructor. | ||
Args: | ||
config: MinIO configuration. | ||
""" | ||
self.config: MinioConfig = config | ||
self.client: Minio = Minio( | ||
endpoint=f"{config.hostname}:{config.port}", | ||
access_key=config.access_key, | ||
secret_key=config.secret_key, | ||
secure=config.secure, | ||
) | ||
|
||
def create_bucket(self) -> None: | ||
"""Create bucket if it does not exist.""" | ||
if not self.client.bucket_exists(self.config.bucket_name): | ||
self.client.make_bucket(self.config.bucket_name) | ||
logger.info(f"Bucket '{self.config.bucket_name}' created.") | ||
else: | ||
logger.debug(f"Bucket '{self.config.bucket_name}' already exists.") | ||
|
||
|
||
def register_minio_client(app: FlaskApp) -> FlaskApp: | ||
"""Register MinIO client and create bucket. | ||
Args: | ||
app: Connexion Flask app instance. | ||
Returns: | ||
Connexion Flask app instance with a MinIO client instance added to | ||
its config. | ||
""" | ||
minio_client = MinioClient(config=app.app.config.foca.custom.minio) | ||
minio_client.create_bucket() | ||
app.app.config.foca.custom.minio.client = minio_client | ||
logger.info("MinIO client registered.") | ||
return app |
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,45 @@ | ||
"""Model for MinIO Configuration.""" | ||
|
||
from typing import Annotated, Optional | ||
|
||
from minio import Minio | ||
from pydantic import BaseModel, conint, constr | ||
|
||
|
||
class MinioConfig(BaseModel): | ||
"""Configuration for MinIO. | ||
Attributes: | ||
hostname: The name of the host where the MinIO server is running. | ||
port: The port on which the MinIO server is running. Must be between 1 | ||
and 65535. | ||
access_key: The access key used for authentication with MinIO. | ||
secret_key: The secret key used for authentication with MinIO. | ||
bucket_name: The name of the bucket where files are stored. Must be at | ||
least 1 character long. | ||
secure: Whether to use TLS connection to storage service or not. | ||
client: Client instance. | ||
Examples: | ||
MinioConfig( | ||
hostname="localhost", | ||
port=9000, | ||
access_key="minioadmin", | ||
secret_key="minioadmin", | ||
bucket_name="files", | ||
secure=False, | ||
) | ||
""" | ||
|
||
hostname: str = "localhost" | ||
port: Annotated[int, conint(ge=1, le=65535)] = 9000 | ||
access_key: str = "minioadmin" | ||
secret_key: str = "minioadmin" | ||
bucket_name: Annotated[str, constr(min_length=1)] = "files" | ||
secure: bool = False | ||
client: Optional[Minio] = None | ||
|
||
class Config: | ||
"""Model configuration.""" | ||
|
||
arbitrary_types_allowed = True |
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 @@ | ||
"""Custom configuration model for the FOCA app.""" | ||
|
||
from pydantic import BaseModel | ||
|
||
from cloud_storage_handler.api.elixircloud.csh.models import MinioConfig | ||
|
||
|
||
class CustomConfig(BaseModel): | ||
"""Custom configuration model for the FOCA app. | ||
Attributes: | ||
minio: MinIO configuration parameters. | ||
""" | ||
|
||
minio: MinioConfig |
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,42 +1,48 @@ | ||
--- | ||
server: | ||
host: '0.0.0.0' | ||
port: 8080 | ||
debug: false | ||
environment: development | ||
testing: false | ||
use_reloader: true | ||
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 | ||
claim_identity: sub | ||
claim_issuer: iss | ||
algorithms: | ||
- RS256 | ||
validation_methods: | ||
- userinfo | ||
- public_key | ||
validation_checks: all | ||
auth: | ||
required: true | ||
add_key_to_claims: true | ||
allow_expired: false | ||
audience: null | ||
claim_identity: sub | ||
claim_issuer: iss | ||
algorithms: | ||
- RS256 | ||
validation_methods: | ||
- userinfo | ||
- public_key | ||
validation_checks: all | ||
|
||
api: | ||
specs: | ||
- path: cloud_storage_handler/api/specs/specs.yaml | ||
append: null | ||
add_operation_fields: | ||
x-openapi-router-controller: cloud_storage_handler.api.elixircloud.csh.controllers | ||
connexion: | ||
strict_validation: true | ||
validate_responses: false | ||
options: | ||
swagger_ui: true | ||
serve_spec: true | ||
specs: | ||
- path: cloud_storage_handler/api/specs/specs.yaml | ||
append: null | ||
add_operation_fields: | ||
x-openapi-router-controller: cloud_storage_handler.api.elixircloud.csh.controllers | ||
connexion: | ||
strict_validation: true | ||
validate_responses: false | ||
|
||
custom: | ||
minio: | ||
hostname: localhost | ||
port: 9000 | ||
access_key: minioadmin | ||
secret_key: minioadmin | ||
bucket_name: 'files' | ||
secure: false | ||
|
||
exceptions: | ||
required_members: [['message'], ['code']] | ||
status_member: ['code'] | ||
exceptions: cloud_storage_handler.exceptions.exceptions | ||
required_members: [['message'], ['code']] | ||
status_member: ['code'] | ||
exceptions: cloud_storage_handler.exceptions.exceptions | ||
... |
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
Oops, something went wrong.