Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 0 additions & 9 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# Vault configuration
# is sensitive/secret
VAULT_TOKEN=

# contains defaults but can be overriden
VAULT_URL=
VAULT_CRT=

# Service configuration
# contains defaults but can be overriden
CONFIG_CENTER_ENABLED=false
APP_NAME=bff-cli
version=2.0.0
port=5080
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/hdc-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: HDC ci/cd pipeline

permissions:
contents: write
issues: write
pull-requests: write

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
run_tests_hdc:
uses: PilotDataPlatform/pilot-hdc-ci-tools/.github/workflows/run_tests.yml@main
with:
min_coverage_percent: 84
secrets: inherit

build_and_publish_hdc:
needs: [run_tests_hdc]
uses: PilotDataPlatform/pilot-hdc-ci-tools/.github/workflows/build_and_publish.yml@main
with:
matrix_config: '["bff-cli"]'
service_name: 'bff-cli'
secrets: inherit

deploy_hdc:
needs: [build_and_publish_hdc]
uses: PilotDataPlatform/pilot-hdc-ci-tools/.github/workflows/trigger_deployment.yml@main
with:
hdc_service_name: 'bff-cli'
secrets: inherit
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ repos:
]

- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
rev: v1.7.7
hooks:
- id: docformatter
args: [
Expand Down
128 changes: 0 additions & 128 deletions Jenkinsfile

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BFF-CLI

[![Python](https://img.shields.io/badge/python-3.8-brightgreen.svg)](https://www.python.org/)
[![Python](https://img.shields.io/badge/python-3.10-brightgreen.svg)](https://www.python.org/)

## Getting Started
The backend for the command line interface.
Expand Down Expand Up @@ -68,4 +68,3 @@ The development of the HealthDataCloud open source software was supported by the
This project has received funding from the European Union’s Horizon Europe research and innovation programme under grant agreement No 101058516. Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or other granting authorities. Neither the European Union nor other granting authorities can be held responsible for them.

![EU HDC Acknowledgement](https://hdc.humanbrainproject.eu/img/HDC-EU-acknowledgement.png)

5 changes: 5 additions & 0 deletions app/components/request/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (C) 2022-Present Indoc Systems
#
# Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE,
# Version 3.0 (the "License") available at https://www.gnu.org/licenses/agpl-3.0.en.html.
# You may not use this file except in compliance with the License.
41 changes: 41 additions & 0 deletions app/components/request/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (C) 2022-Present Indoc Systems
#
# Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE,
# Version 3.0 (the "License") available at https://www.gnu.org/licenses/agpl-3.0.en.html.
# You may not use this file except in compliance with the License.

from typing import Annotated

from fastapi import Depends
from fastapi import Request

from app.components.request.http_client import HTTPClient
from app.config import SettingsDependency


class RequestContext:
def __init__(self, *, request: Request, client_timeout: int, allowed_headers: set[str] | None = None) -> None:
self.request = request

self.allowed_headers = allowed_headers or {
'forwarded',
'x-forwarded-for',
'x-userinfo',
'authorization',
'session-id',
'vm-info',
}
self.headers = {}

for key, value in self.request.headers.items():
if key in self.allowed_headers:
self.headers[key] = value

self.client = HTTPClient(headers=self.headers, timeout=client_timeout)


def get_request_context(request: Request, settings: SettingsDependency) -> RequestContext:
return RequestContext(request=request, client_timeout=settings.SERVICE_CLIENT_TIMEOUT)


RequestContextDependency = Annotated[RequestContext, Depends(get_request_context)]
93 changes: 93 additions & 0 deletions app/components/request/http_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright (C) 2022-Present Indoc Systems
#
# Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE,
# Version 3.0 (the "License") available at https://www.gnu.org/licenses/agpl-3.0.en.html.
# You may not use this file except in compliance with the License.

from typing import Any

from httpx import URL
from httpx import AsyncClient
from httpx import Response
from httpx._types import HeaderTypes
from httpx._types import QueryParamTypes
from httpx._types import RequestContent
from httpx._types import RequestData
from httpx._types import TimeoutTypes


class HTTPClient:

def __init__(self, *, headers: HeaderTypes, timeout: TimeoutTypes) -> None:
self.headers = headers
self.timeout = timeout

@property
def client(self) -> AsyncClient:
return AsyncClient(headers=self.headers, timeout=self.timeout)

async def get(
self,
url: URL | str,
*,
params: QueryParamTypes | None = None,
headers: HeaderTypes | None = None,
) -> Response:
async with self.client as client:
return await client.request('GET', url, params=params, headers=headers)

async def post(
self,
url: URL | str,
*,
content: RequestContent | None = None,
data: RequestData | None = None,
json: Any | None = None,
params: QueryParamTypes | None = None,
headers: HeaderTypes | None = None,
) -> Response:
async with self.client as client:
return await client.request(
'POST', url, content=content, data=data, json=json, params=params, headers=headers
)

async def put(
self,
url: URL | str,
*,
content: RequestContent | None = None,
data: RequestData | None = None,
json: Any | None = None,
params: QueryParamTypes | None = None,
headers: HeaderTypes | None = None,
) -> Response:
async with self.client as client:
return await client.request(
'PUT', url, content=content, data=data, json=json, params=params, headers=headers
)

async def patch(
self,
url: URL | str,
*,
content: RequestContent | None = None,
data: RequestData | None = None,
json: Any | None = None,
params: QueryParamTypes | None = None,
headers: HeaderTypes | None = None,
) -> Response:
async with self.client as client:
return await client.request(
'PATCH', url, content=content, data=data, json=json, params=params, headers=headers
)

async def delete(
self,
url: URL | str,
*,
json: Any | None = None,
params: QueryParamTypes | None = None,
headers: HeaderTypes | None = None,
) -> Response:
async with self.client as client:
return await client.request('DELETE', url, json=json, params=params, headers=headers)
Loading
Loading