Skip to content

Commit 6dc0100

Browse files
committed
Merge dev into main
2 parents ec9ad1f + c7cc4d1 commit 6dc0100

19 files changed

Lines changed: 360 additions & 50 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OSBot-Fast-API
22

3-
![Current Release](https://img.shields.io/badge/release-v0.19.0-blue)
3+
![Current Release](https://img.shields.io/badge/release-v0.19.1-blue)
44
![Python](https://img.shields.io/badge/python-3.8+-green)
55
![FastAPI](https://img.shields.io/badge/FastAPI-0.100+-red)
66
![Type-Safe](https://img.shields.io/badge/Type--Safe-✓-brightgreen)

osbot_fast_api/admin_ui/api/routes/Routes__Admin__Cookies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
2-
from typing import Dict, Any, List, Optional
32
import osbot_fast_api
3+
from typing import Dict, Any, List, Optional
44
from fastapi import Request, Response
55
from osbot_utils.utils.Files import path_combine, file_exists
66
from osbot_fast_api.api.routes.Fast_API__Routes import Fast_API__Routes

osbot_fast_api/api/routes/Fast_API__Routes.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,23 @@ class Fast_API__Routes(Type_Safe): # refactor to Fast_API__Routes
2222

2323
def __init__(self, **kwargs):
2424
super().__init__(**kwargs)
25-
if not self.prefix: # if not set explicitly
26-
self.prefix = Safe_Str__Fast_API__Route__Prefix(self.tag) # create the prefix from the lower case tag and with a starting /
25+
if not self.prefix: # if not set explicitly
26+
self.prefix = Safe_Str__Fast_API__Route__Prefix(self.tag) # create the prefix from the lower case tag and with a starting /
2727

2828
def add_route(self,function, methods):
2929
path = self.parse_function_name(function)
3030
self.router.add_api_route(path=path, endpoint=function, methods=methods)
3131
return self
3232

33+
def add_route_any(self, function, path=None): # Add route that accepts ANY HTTP method
34+
methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']
35+
36+
if path:
37+
self.router.add_api_route(path=path, endpoint=function, methods=methods)
38+
else:
39+
self.add_route(function, methods)
40+
41+
return self
3342
def add_route_with_body(self, function, methods):
3443
sig = inspect.signature(function) # Get function signature
3544
type_hints = get_type_hints(function) # Get type annotations

osbot_fast_api/schemas/Safe_Str__Fast_API__Route__Tag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
from osbot_utils.type_safe.primitives.safe_str.Safe_Str import Safe_Str
33

4-
TYPE_SAFE_STR__FASTAPI__ROUTE__REGEX = re.compile(r'[^a-zA-Z0-9\-_/{}.]')
4+
TYPE_SAFE_STR__FASTAPI__ROUTE__REGEX = re.compile(r'[^a-zA-Z0-9\-_/{}.:]')
55
TYPE_SAFE_STR__FASTAPI__ROUTE__MAX_LENGTH = 512
66

77
class Safe_Str__Fast_API__Route__Tag(Safe_Str):

osbot_fast_api/schemas/consts__Fast_API.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import re
2-
32
from osbot_fast_api.schemas.Safe_Str__Fast_API__Route__Prefix import Safe_Str__Fast_API__Route__Prefix
43

54
# todo: the names of these variables need a bit of refactoring and normalising
@@ -34,15 +33,19 @@
3433
'set_cookie_form' ,
3534
'status' ,
3635
'version' ]
37-
EXPECTED_ROUTES_PATHS = ['/' ,
38-
'/auth/set-auth-cookie' ,
39-
'/auth/set-cookie-form',
40-
'/config/info' ,
36+
EXPECTED_ROUTES__CONFIG = ['/config/info' ,
4137
'/config/openapi.py' ,
4238
'/config/routes/html' ,
4339
'/config/routes/json' ,
4440
'/config/status' ,
4541
'/config/version' ]
42+
EXPECTED_ROUTES__SET_COOKIE = ['/auth/set-auth-cookie' ,
43+
'/auth/set-cookie-form']
44+
45+
EXPECTED_ROUTES_PATHS = (['/'] +
46+
EXPECTED_ROUTES__CONFIG +
47+
EXPECTED_ROUTES__SET_COOKIE)
48+
4649
EXPECTED_DEFAULT_ROUTES = ['/docs', '/openapi.json', '/redoc', '/static-docs' ]
4750

4851

osbot_fast_api/utils/Fast_API_Server.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import requests
22
import threading
3-
from urllib.parse import urljoin
4-
from threading import Thread
5-
from fastapi import FastAPI
3+
from urllib.parse import urljoin
4+
from threading import Thread
5+
from fastapi import FastAPI
66
from osbot_utils.type_safe.Type_Safe import Type_Safe
7-
from osbot_utils.testing.Stderr import Stderr
8-
from osbot_utils.testing.Stdout import Stdout
9-
from osbot_utils.utils.Http import wait_for_port, wait_for_port_closed, is_port_open, url_join_safe
10-
from osbot_utils.utils.Objects import base_types
11-
from uvicorn import Config, Server
12-
from osbot_utils.utils.Misc import random_port
7+
from osbot_utils.testing.Stderr import Stderr
8+
from osbot_utils.testing.Stdout import Stdout
9+
from osbot_utils.utils.Http import wait_for_port, wait_for_port_closed, is_port_open, url_join_safe
10+
from osbot_utils.utils.Objects import base_types
11+
from uvicorn import Config, Server
12+
from osbot_utils.utils.Misc import random_port
1313

1414
FAST_API__HOST = "127.0.0.1"
1515
FAST_API__LOG_LEVEL = "error"

osbot_fast_api/utils/Fast_API__Server_Info.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from osbot_utils.type_safe.Type_Safe import Type_Safe
1+
from osbot_utils.type_safe.Type_Safe import Type_Safe
22
from osbot_utils.type_safe.primitives.safe_str.identifiers.Random_Guid import Random_Guid
33
from osbot_utils.type_safe.primitives.safe_str.identifiers.Safe_Id import Safe_Id
4-
from osbot_utils.type_safe.primitives.safe_int.Timestamp_Now import Timestamp_Now
5-
from osbot_utils.utils.Env import get_env
4+
from osbot_utils.type_safe.primitives.safe_int.Timestamp_Now import Timestamp_Now
5+
from osbot_utils.utils.Env import get_env
66

77
ENV_NAME__FAST_API__SERVER_ID = 'FAST_API__SERVER_ID'
88
ENV_NAME__FAST_API__SERVER_NAME = 'FAST_API__SERVER_NAME'

osbot_fast_api/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.19.0
1+
v0.19.1

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "osbot_fast_api"
3-
version = "v0.19.0"
3+
version = "v0.19.1"
44
description = "OWASP Security Bot - Fast API"
55
authors = ["Dinis Cruz <dinis.cruz@owasp.org>"]
66
license = "MIT"

tests/unit/admin_ui/api/test_Admin_UI__Fast_API__multiple_workflows.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
import concurrent.futures
13
from unittest import TestCase
24
from osbot_utils.utils.Env import in_github_action
35
from osbot_utils.utils.Misc import list_set
@@ -7,12 +9,7 @@
79
from osbot_fast_api.admin_ui.api.testing.Admin_UI__Test_Context import Admin_UI__Test_Context
810
from osbot_fast_api.api.Fast_API import Fast_API
911
from osbot_fast_api.utils.Fast_API_Server import Fast_API_Server
10-
11-
import concurrent.futures
12-
import time
13-
import json
14-
15-
from osbot_fast_api.utils.Version import version__osbot_fast_api
12+
from osbot_fast_api.utils.Version import version__osbot_fast_api
1613

1714

1815
class test_Admin_UI__Fast_API__multiple_workflows(TestCase): # Full integration tests for Admin UI
@@ -240,7 +237,7 @@ def set_cookie(name):
240237
assert throughput > 100 # At least 100 req/s
241238
else:
242239
assert duration < 0.3 # 100 requests in under 0.3 seconds (locally)
243-
assert throughput > 500 # At least 500 req/s (locally)
240+
assert throughput > 400 # At least 500 req/s (locally)
244241

245242
def test_05_error_handling(self):
246243
"""Test error handling in Admin UI"""

0 commit comments

Comments
 (0)