Skip to content

Commit

Permalink
πŸ”„ merge: Merge remote-tracking branch 'github/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xitowzys committed May 11, 2023
2 parents 0746570 + 20fae60 commit ab4042e
Show file tree
Hide file tree
Showing 85 changed files with 2,888 additions and 1,597 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = fastapi_gateway_auto_generate/tmp/*, fastapi_gateway_auto_generate/migration/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,5 @@ test.py
*.ipynb

allureress/
allure-report/
main.py
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ allure:

coverage:
coverage erase
coverage run --include=dadata/* -m pytest -ra
coverage report -m
coverage run --source=./fastapi_gateway_auto_generate -m pytest -s
coverage html
coverage-badge -f -o ./raw/coverage.svg
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
<p align="center">
<a href="https://fastapi.tiangolo.com"><img src="./raw/FastAPI-API-Gateway-Magic-logo.png" alt="FastAPI"></a>
</p>

<p align="center">
<em>A library that allows you to automate the process of creating an API Gateway</em>
<a href="https://www.python.org/"> <img src="https://img.shields.io/badge/made%20with-python%20%F0%9F%90%8D-brightgreen" alt="madewithpython" border="0"></a>
</p>

<p align="center">

<a href="https://github.com/xitowzys-ISZF/FastAPI-auto-generate-gateway/blob/dev/LICENSE)" target="_blank">
<img src="https://scrutinizer-ci.com/g/xitowzys-ISZF/FastAPI-auto-generate-gateway/badges/quality-score.png?b=dev" alt="Supported Python versions">
<img src="https://scrutinizer-ci.com/g/xitowzys-ISZF/FastAPI-auto-generate-gateway/badges/code-intelligence.svg?b=dev" alt="Supported Python versions">
<img src="https://scrutinizer-ci.com/g/xitowzys-ISZF/FastAPI-auto-generate-gateway/badges/build.png?b=dev" alt="Supported Python versions">
</a>

</p>
<p align="center">

<a href="https://github.com/xitowzys-ISZF/FastAPI-auto-generate-gateway/blob/dev/LICENSE)" target="_blank">
<img src="https://img.shields.io/github/license/xitowzys-ISZF/FastAPI-auto-generate-gateway" alt="Supported Python versions">
<img src="./raw/coverage.svg" alt="Supported Python versions">
<img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/xitowzys-ISZF/FastAPI-auto-generate-gateway">
<img alt="GitHub all releases" src="https://img.shields.io/github/downloads/xitowzys-ISZF/FastAPI-auto-generate-gateway/total">

</a>

</p>
Expand All @@ -21,7 +36,22 @@
</a>
</p>

---
# πŸ”₯ FastAPI Auto Generate Gateway

A library that allows you to automate the process of creating an API Gateway

# πŸ“š About

This is a library that enables the automation of the process of creating an API Gateway.
With its help, you can quickly and easily configure and deploy an API Gateway for your microservices architecture.
The library provides a simple and intuitive interface for configuration,
which reduces the time and effort required to manually set up the API Gateway.









Empty file added docs/CodeReference/database.md
Empty file.
3 changes: 3 additions & 0 deletions docs/CodeReference/domain/models/RouteModel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::: fastapi_gateway_auto_generate.domain.models.RouteModel.RouteModel
options:
show_root_heading: true
3 changes: 3 additions & 0 deletions docs/CodeReference/domain/usecases/BuildRouteModelsUsecase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::: fastapi_gateway_auto_generate.domain.usecases.BuildRouteModelsUsecase.BuildRouteModelsUsecase
options:
show_root_heading: true
3 changes: 3 additions & 0 deletions docs/CodeReference/domain/usecases/BuildRoutesUsecase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::: fastapi_gateway_auto_generate.domain.usecases.BuildRoutesUsecase.BuildRoutesUsecase
options:
show_root_heading: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::: fastapi_gateway_auto_generate.domain.usecases.DeleteTmpModelsFilesUsecase.DeleteTmpModelsFilesUsecase
options:
show_root_heading: true
3 changes: 3 additions & 0 deletions docs/CodeReference/domain/usecases/InitDatabaseUsecase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::: fastapi_gateway_auto_generate.domain.usecases.InitDatabaseUsecase.InitDatabaseUsecase
options:
show_root_heading: true
3 changes: 3 additions & 0 deletions docs/CodeReference/domain/usecases/RefreshServicesUsecase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::: fastapi_gateway_auto_generate.domain.usecases.RefreshServicesUsecase.RefreshServicesUsecase
options:
show_root_heading: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::: fastapi_gateway_auto_generate.domain.usecases.UpdateOpenApiSchemaUsecase.UpdateOpenApiSchemaUsecase
options:
show_root_heading: true
Empty file.
Empty file.
10 changes: 10 additions & 0 deletions docs/CodeReference/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
::: fastapi_gateway_auto_generate.Generator
options:
show_root_heading: true

::: fastapi_gateway_auto_generate.Config
options:
show_root_heading: true

!!! warning
The **`service_management`** parameter is temporarily not functioning and will always be set to `True`.
3 changes: 3 additions & 0 deletions docs/CodeReference/management/Management.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::: fastapi_gateway_auto_generate.management.Management
options:
show_root_heading: true
Empty file.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions docs/CodeReference/management/routes/AddServiceRoute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::: fastapi_gateway_auto_generate.management.routes.AddServiceRoute
options:
show_root_heading: true
3 changes: 3 additions & 0 deletions docs/CodeReference/management/routes/DeleteServiceRoute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::: fastapi_gateway_auto_generate.management.routes.DeleteServiceRoute
options:
show_root_heading: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::: fastapi_gateway_auto_generate.management.routes.GetAllInfoServicesRoute
options:
show_root_heading: true
3 changes: 3 additions & 0 deletions docs/CodeReference/management/routes/RefreshServicesRoute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::: fastapi_gateway_auto_generate.management.routes.RefreshServicesRoute
options:
show_root_heading: true
Empty file added docs/CodeReference/migration.md
Empty file.
3 changes: 2 additions & 1 deletion docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

## Where is the service data stored?

Data and service status are stored in a local SQLite database. If you want to store the database side by side, you can specify an additional parameter `database_path`
Data and service status are stored in a local SQLite database. If you want to store the database side by side, you can specify an additional parameter `database_path`

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# File retrieval from the services

## Service

In this example, a service implemented through FastAPI will be used.
If you have a service implemented in another programming language,
the main requirement is to transfer the file in binary format with the header (application/octet-stream).
To pass a file through FastAPI, you can use FileResponse
(more details can be found in the official documentation: https://fastapi.tiangolo.com/advanced/custom-response/#fileresponse)."

## API-Gateway

!!! bug
It is not possible to download a file through Swagger, as when sending a request,
the API-Gateway starts streaming byte streams, which can cause the page or the entire browser to crash.

To solve the file download issue, you can either directly paste the URL in the browser,
use some third-party tools, or use a programming language.

An example of downloading and saving a file using Python:

```python
import requests

cookies = {'rinex_to_csv_processing_id': '0000000000000000001'}

url = 'http://127.0.0.1:8080/rinex/rinex_to_csv/get_result'
r = requests.get(url, allow_redirects=True, cookies=cookies)

if r.status_code == 200:
open('save.zip', 'wb').write(r.content)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# File transfer to the service
75 changes: 75 additions & 0 deletions docs/Usage/FileManipulation/http-https.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
This method is suitable for transferring small files between the service and API-Gateway.
If you plan to transfer files larger than 500 MB,
it is recommended to consider using the method through a [broker](/Usage/FileManipulation/http-https/).

## File transfer to the service

## File retrieval from the services

### 1. Service

In this example, a service implemented through FastAPI will be used.
If you have a service implemented in another programming language,
the main requirement is to transfer the file in binary format with the header `application/octet-stream`.

To pass a file through FastAPI, you can use FileResponse
(more details can be found in the official documentation: https://fastapi.tiangolo.com/advanced/custom-response/#fileresponse)."

Example of sending a file to an API Gateway:

```python
import os
from fastapi.responses import FileResponse
from fastapi import FastAPI, HTTPException, Cookie
from pathlib import Path
from collections import defaultdict

processings = defaultdict(dict)

temdir = Path('/tmp/files')

app = FastAPI()


@app.get("/get_result", tags=["default"])
async def get_result(processing_id: str | None = Cookie(default=None)):

if not processing_id:
HTTPException(status_code=400, detail="Upload files first")
if not processing_id in processings:
raise HTTPException(status_code=404, detail="No such proc_id")
if not os.path.exists(temdir / processing_id / 'out'):
raise HTTPException(status_code=425,
detail = "Run processing first")

files = os.listdir(temdir / processing_id / "out")
files = [f for f in files if f.endswith('zip')]
out_file = temdir / processing_id / 'out' / files[0]

return FileResponse(out_file,
filename = files[0],
media_type="application/octet-stream")
```

### 2. API-Gateway

!!! bug
It is not possible to download a file through Swagger, as when sending a request,
the API-Gateway starts streaming byte streams, which can cause the page or the entire browser to crash.

To solve the file download issue, you can either directly paste the URL in the browser,
use some third-party tools, or use a programming language.

An example of downloading and saving a file using Python:

```python
import requests

cookies = {'processing_id': '0000000000000000001'}

url = 'http://127.0.0.1:8080/service/get_result'
r = requests.get(url, allow_redirects=True, cookies=cookies)

if r.status_code == 200:
open('save.zip', 'wb').write(r.content)
```
60 changes: 30 additions & 30 deletions docs/Usage/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Getting started

## Additional metadata for tags
## 1. Additional metadata for tags

In order for the url from the microservice to be transferred to the API Gateway,
you need to add additional metadata for your tags. In our case, this is `x-auto-generate-in-api-gateway`.
Expand Down Expand Up @@ -97,10 +97,11 @@ Adds an additional tag `x-auto-generate-in-api-gateway` in order for it to be tr

Now who has the tag `users` and `items` will be automatically transferred to the API Gateway.

!!! question
If you suddenly change the tag for some reason, then you can do this when creating an object in the API Gateway
[//]: # (!!! question)

## Initializing an object in the API Gateway
[//]: # ( If you suddenly change the tag for some reason, then you can do this when creating an object in the API Gateway)

## 2. Initializing an object in the API Gateway

### Create Config object

Expand All @@ -117,33 +118,32 @@ config = Config(
)
```

- `fast_api_app` β†’ The object of your app.
- `service_management_api` β†’ Enable service management using the API interface. **Enabled by default.**

!!! warning
This parameter temporarily does not work and will always be enabled.

- `db_path` β†’ The path to the database. **By default, creates a database in the root directory of the project.**

> Documentation in development
### Example creating a simple generator
!!! info
You can find more information about the
Config class in the [Code Reference.](/CodeReference/#fastapi_gateway_auto_generate.Config)

```python
from fastapi_gateway_auto_generate import Generator, Config
from fastapi import FastAPI
import uvicorn

app = FastAPI()
#### Example creating a simple generator

config = Config(
fast_api_app=app,
)
=== "app.py"

Generator(
config=config
)
```python
from fastapi_gateway_auto_generate import Generator, Config
from fastapi import FastAPI
import uvicorn

app = FastAPI()

config = Config(
fast_api_app=app,
)

Generator(
config=config
)

if __name__ == "__main__":
uvicorn.run(app=app, port=5000, log_level="info")
```

if __name__ == "__main__":
uvicorn.run(app=app, port=5000, log_level="info")
```
After all the manipulations, you will have urls in Swagger for managing services.
You can read more details about Service management [here](/Usage/service-management/).
4 changes: 4 additions & 0 deletions docs/Usage/security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Security

!!! info
This functionality has not yet been implemented
Loading

0 comments on commit ab4042e

Please sign in to comment.