From 48c37987b271aa7ffe306e38459b4db38d0fc413 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Wed, 18 Jan 2023 14:23:25 +0100 Subject: [PATCH 01/15] fixed logging and added current timezone info --- app/main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 204a55a..76a42b2 100644 --- a/app/main.py +++ b/app/main.py @@ -22,9 +22,10 @@ from sqlalchemy.orm import sessionmaker from util import load_key, load_file from orm import Origin, Lease, init as db_init, migrate -logger = logging.getLogger() load_dotenv('../version.env') +TZ = datetime.now().astimezone().tzinfo + VERSION, COMMIT, DEBUG = env('VERSION', 'unknown'), env('COMMIT', 'unknown'), bool(env('DEBUG', False)) config = dict(openapi_url='/-/openapi.json', docs_url='/-/docs', redoc_url='/-/redoc') @@ -58,6 +59,8 @@ app.add_middleware( allow_headers=['*'], ) +logging.basicConfig() +logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG if DEBUG else logging.INFO) @@ -97,6 +100,7 @@ async def _config(): 'LEASE_EXPIRE_DELTA': str(LEASE_EXPIRE_DELTA), 'LEASE_RENEWAL_PERIOD': str(LEASE_RENEWAL_PERIOD), 'CORS_ORIGINS': str(CORS_ORIGINS), + 'TZ': str(TZ), }) @@ -529,6 +533,11 @@ async def leasing_v1_lessor_shutdown(request: Request): return JSONr(response) +@app.on_event('startup') +async def app_on_startup(): + logger.info(f'Using timezone: {str(TZ)}. Make sure this is correct and match your clients!') + + if __name__ == '__main__': import uvicorn From 9411759f6db5e4a13422be18c292b3f69fd35058 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Wed, 18 Jan 2023 14:23:34 +0100 Subject: [PATCH 02/15] added system requirements and preparements --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 28a7bdc..04b013e 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,15 @@ Only the clients need a connection to this service on configured port. # Setup (Service) +**System requirements**: + +- LXC with 256mb ram and 4gb hdd is enough (Ubuntu 22.10 from Proxmox templates) \ + (actually its consuming 100mb ram and 750mb hdd) + +**Prepare your system**: + +- Make sure your timezone is set correct on you fastapi-dls server and your client + ## Docker Docker-Images are available here: From 38177fa2594e273d748d2cf3c6aa45a27cc4e23e Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Wed, 18 Jan 2023 14:29:48 +0100 Subject: [PATCH 03/15] styling --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 04b013e..884cdd3 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,14 @@ Only the clients need a connection to this service on configured port. [[_TOC_]] - # Setup (Service) **System requirements**: -- LXC with 256mb ram and 4gb hdd is enough (Ubuntu 22.10 from Proxmox templates) \ - (actually its consuming 100mb ram and 750mb hdd) +- 256mb ram +- 4gb hdd + +Tested with Ubuntu 22.10 (from Proxmox templates), actually its consuming 100mb ram and 750mb hdd. **Prepare your system**: From 7045692958b4348e225891abf27553f977e021bd Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Thu, 19 Jan 2023 07:25:24 +0100 Subject: [PATCH 04/15] added official links --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 884cdd3..c0a9c0b 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,14 @@ Compatibility tested with official DLS 2.0.1. This service can be used without internet connection. Only the clients need a connection to this service on configured port. +**Official Links** + +- https://git.collinwebdesigns.de/oscar.krause/fastapi-dls +- https://gitea.publichub.eu/oscar.krause/fastapi-dls +- Docker Image `collinwebdesigns/fastapi-dls:latest` + +*All other repositories are forks!* + [[_TOC_]] # Setup (Service) From 91be7b226cc1966b03a2b9d67c088b3d4bc5e96e Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Thu, 19 Jan 2023 07:25:44 +0100 Subject: [PATCH 05/15] added some comments for default values --- app/orm.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/orm.py b/app/orm.py index bfd6557..387c828 100644 --- a/app/orm.py +++ b/app/orm.py @@ -170,6 +170,14 @@ class Lease(Base): renew = delta.total_seconds() * LEASE_RENEWAL_PERIOD renew = datetime.timedelta(seconds=renew) expires = delta - renew # 19.2 + + import datetime + LEASE_RENEWAL_PERIOD=0.15 # 15% + delta = datetime.timedelta(days=90) + renew = delta.total_seconds() * LEASE_RENEWAL_PERIOD + renew = datetime.timedelta(seconds=renew) + expires = delta - renew # 76 days, 12:00:00 hours + """ renew = delta.total_seconds() * renewal_period renew = timedelta(seconds=renew) From c3ea0aa48c7304e1adeb0d304b3951d39228e609 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Thu, 19 Jan 2023 07:26:07 +0100 Subject: [PATCH 06/15] added variable for client-token-expire-delta --- app/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 76a42b2..b4ee325 100644 --- a/app/main.py +++ b/app/main.py @@ -45,6 +45,7 @@ TOKEN_EXPIRE_DELTA = relativedelta(days=int(env('TOKEN_EXPIRE_DAYS', 1)), hours= LEASE_EXPIRE_DELTA = relativedelta(days=int(env('LEASE_EXPIRE_DAYS', 90)), hours=int(env('LEASE_EXPIRE_HOURS', 0))) LEASE_RENEWAL_PERIOD = float(env('LEASE_RENEWAL_PERIOD', 0.15)) LEASE_RENEWAL_DELTA = timedelta(days=int(env('LEASE_EXPIRE_DAYS', 90)), hours=int(env('LEASE_EXPIRE_HOURS', 0))) +CLIENT_TOKEN_EXPIRE_DELTA = relativedelta(years=12) CORS_ORIGINS = str(env('CORS_ORIGINS', '')).split(',') if (env('CORS_ORIGINS')) else [f'https://{DLS_URL}'] jwt_encode_key = jwk.construct(INSTANCE_KEY_RSA.export_key().decode('utf-8'), algorithm=ALGORITHMS.RS256) @@ -196,7 +197,7 @@ async def _lease_delete(request: Request, lease_ref: str): @app.get('/-/client-token', summary='* Client-Token', description='creates a new messenger token for this service instance') async def _client_token(): cur_time = datetime.utcnow() - exp_time = cur_time + relativedelta(years=12) + exp_time = cur_time + CLIENT_TOKEN_EXPIRE_DELTA payload = { "jti": str(uuid4()), From 95427d430ef7e911f34e56f3728f50436b17a448 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Thu, 19 Jan 2023 07:26:22 +0100 Subject: [PATCH 07/15] added startup script --- app/main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index b4ee325..e9ed1dd 100644 --- a/app/main.py +++ b/app/main.py @@ -536,7 +536,14 @@ async def leasing_v1_lessor_shutdown(request: Request): @app.on_event('startup') async def app_on_startup(): - logger.info(f'Using timezone: {str(TZ)}. Make sure this is correct and match your clients!') + logger.info(f''' + Using timezone: {str(TZ)}. Make sure this is correct and match your clients! + + Your clients renew their license every {str(Lease.calculate_renewal(LEASE_RENEWAL_PERIOD, LEASE_RENEWAL_DELTA))}. + If the renewal fails, the license is {str(LEASE_RENEWAL_DELTA)} valid. + + Your client-token file (.tok) is valid for {str(CLIENT_TOKEN_EXPIRE_DELTA)}. + ''') if __name__ == '__main__': From bed24b56ce9fda25c4cabe29605e122f06b4f1de Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Thu, 19 Jan 2023 08:26:35 +0100 Subject: [PATCH 08/15] styling --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c0a9c0b..bb590f0 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Only the clients need a connection to this service on configured port. *All other repositories are forks!* +--- + [[_TOC_]] # Setup (Service) From f7ef8d76b6d2f07b536761a046b6db78483a669c Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Mon, 23 Jan 2023 07:12:02 +0100 Subject: [PATCH 09/15] fixed Origin.delete() --- app/orm.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/orm.py b/app/orm.py index 387c828..6f4858f 100644 --- a/app/orm.py +++ b/app/orm.py @@ -57,12 +57,12 @@ class Origin(Base): session.close() @staticmethod - def delete(engine: Engine, origins: ["Origin"] = None) -> int: + def delete(engine: Engine, origin_refs: [str] = None) -> int: session = sessionmaker(bind=engine)() - if origins is None: + if origin_refs is None: deletions = session.query(Origin).delete() else: - deletions = session.query(Origin).filter(Origin.origin_ref in origins).delete() + deletions = session.query(Origin).filter(Origin.origin_ref in origin_refs).delete() session.commit() session.close() return deletions From 48eb6d6c64a86e6321eaafc8f6c738d1a40abe07 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Mon, 23 Jan 2023 07:23:42 +0100 Subject: [PATCH 10/15] typos --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bb590f0..5f3e4a8 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,14 @@ Only the clients need a connection to this service on configured port. # Setup (Service) -**System requirements**: +**System requirements** - 256mb ram - 4gb hdd Tested with Ubuntu 22.10 (from Proxmox templates), actually its consuming 100mb ram and 750mb hdd. -**Prepare your system**: +**Prepare your system** - Make sure your timezone is set correct on you fastapi-dls server and your client From 9ebff8d6ca2aeea1663592147343cedd3a8c914d Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Mon, 23 Jan 2023 07:29:13 +0100 Subject: [PATCH 11/15] typos --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f3e4a8..8220259 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Only the clients need a connection to this service on configured port. - https://gitea.publichub.eu/oscar.krause/fastapi-dls - Docker Image `collinwebdesigns/fastapi-dls:latest` -*All other repositories are forks!* +*All other repositories are forks! (which is no bad - just for information and bug reports)* --- From 02276d5440cf328164fef94bd2167f48b1af5b80 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Mon, 23 Jan 2023 07:33:54 +0100 Subject: [PATCH 12/15] disabled openapi endpoints --- README.md | 4 ---- app/main.py | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 8220259..649b158 100644 --- a/README.md +++ b/README.md @@ -368,10 +368,6 @@ Shows current runtime environment variables and their values. HTML rendered README.md. -### `GET /-/docs`, `GET /-/redoc` - -OpenAPI specifications rendered from `GET /-/openapi.json`. - ### `GET /-/manage` Shows a very basic UI to delete origins or leases. diff --git a/app/main.py b/app/main.py index e9ed1dd..4b78253 100644 --- a/app/main.py +++ b/app/main.py @@ -28,7 +28,7 @@ TZ = datetime.now().astimezone().tzinfo VERSION, COMMIT, DEBUG = env('VERSION', 'unknown'), env('COMMIT', 'unknown'), bool(env('DEBUG', False)) -config = dict(openapi_url='/-/openapi.json', docs_url='/-/docs', redoc_url='/-/redoc') +config = dict(openapi_url=None, docs_url=None, redoc_url=None) # dict(openapi_url='/-/openapi.json', docs_url='/-/docs', redoc_url='/-/redoc') app = FastAPI(title='FastAPI-DLS', description='Minimal Delegated License Service (DLS).', version=VERSION, **config) db = create_engine(str(env('DATABASE', 'sqlite:///db.sqlite'))) db_init(db), migrate(db) From f12dc28c426e6feeef9af1c1688d235fb612c44c Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Thu, 26 Jan 2023 07:17:16 +0100 Subject: [PATCH 13/15] fixed overriding config file on update / reinstall --- .PKGBUILD/PKGBUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/.PKGBUILD/PKGBUILD b/.PKGBUILD/PKGBUILD index 97d3995..82d038d 100644 --- a/.PKGBUILD/PKGBUILD +++ b/.PKGBUILD/PKGBUILD @@ -11,6 +11,7 @@ license=('MIT') depends=('python' 'python-jose' 'python-starlette' 'python-httpx' 'python-fastapi' 'python-dotenv' 'python-dateutil' 'python-sqlalchemy' 'python-pycryptodome' 'uvicorn' 'python-markdown' 'openssl') provider=("$pkgname") install="$pkgname.install" +backup=('etc/default/fastapi-dls') source=('git+file:///builds/oscar.krause/fastapi-dls' # https://gitea.publichub.eu/oscar.krause/fastapi-dls.git "$pkgname.default" "$pkgname.service" From f30e9237a507ff5b33fb25f124333589b73117b1 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Thu, 26 Jan 2023 07:18:01 +0100 Subject: [PATCH 14/15] requirements.txt updated --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4c25d3f..61d00cc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,4 @@ pycryptodome==3.16.0 python-dateutil==2.8.2 sqlalchemy==1.4.46 markdown==3.4.1 -python-dotenv==0.21.0 +python-dotenv==0.21.1 From 9edc93653e49aa669c93493d742507e9560250cc Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Thu, 26 Jan 2023 07:38:48 +0100 Subject: [PATCH 15/15] bump version to 1.3.4 --- version.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.env b/version.env index 93176fc..c7644ab 100644 --- a/version.env +++ b/version.env @@ -1 +1 @@ -VERSION=1.3.3 +VERSION=1.3.4