Skip to content

Commit

Permalink
chore: lowercase config
Browse files Browse the repository at this point in the history
  • Loading branch information
dantetemplar committed Nov 29, 2023
1 parent 3b7c638 commit 91438d4
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 94 deletions.
16 changes: 8 additions & 8 deletions settings.example.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
$schema: "./settings.schema.yaml"
# ---------- Application settings ----- #
DATABASE:
URI: postgresql+asyncpg://postgres:postgres@localhost:5432/postgres
database:
uri: postgresql+asyncpg://postgres:postgres@localhost:5432/postgres
# Predefined
PREDEFINED:
FIRST_SUPERUSER_LOGIN: admin
FIRST_SUPERUSER_PASSWORD: admin
predefined:
first_superuser_login: admin
first_superuser_password: admin
# Run 'openssl rand -hex 32' to generate key
SESSION_SECRET_KEY: session_secret_key
session_secret_key: session_secret_key
# Run 'openssl genrsa -out private.pem 2048' to generate keys
JWT_PRIVATE_KEY: |
jwt_private_key: |
-----BEGIN RSA PRIVATE KEY-----
ssssssssssssssssssssssssssssss
ssssssssssssssssssssssssssssss
ssssssssssssssssssssssssssssss
ssssssssssssssssssssssssssssss
-----END RSA PRIVATE KEY-----
# For existing key run 'openssl rsa -in private.pem -pubout -out public.pem'
JWT_PUBLIC_KEY: |
jwt_public_key: |
-----BEGIN PUBLIC KEY-----
ssssssssssssssssssssssssssssss
ssssssssssssssssssssssssssssss
Expand Down
59 changes: 29 additions & 30 deletions settings.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ $defs:
type: object
Cookies:
properties:
NAME:
name:
default: token
title: Name
type: string
DOMAIN:
domain:
default: innohassle.ru
title: Domain
type: string
ALLOWED_DOMAINS:
allowed_domains:
default:
- innohassle.ru
- api.innohassle.ru
Expand All @@ -28,49 +28,48 @@ $defs:
Database:
description: PostgreSQL database settings.
properties:
URI:
uri:
anyOf:
- type: string
- type: 'null'
default: null
description: Database URI. If not set, will be generated from other settings
title: Uri
USERNAME:
username:
anyOf:
- type: string
- type: 'null'
default: null
description: Database username
title: Username
PASSWORD:
password:
anyOf:
- type: string
- type: 'null'
default: null
description: Database password
title: Password
HOST:
host:
anyOf:
- type: string
- type: 'null'
default: null
description: Database host
title: Host
PORT:
port:
anyOf:
- type: integer
- type: 'null'
default: null
description: Database port
title: Port
DATABASE_NAME:
database_name:
anyOf:
- type: string
- type: 'null'
default: null
description: Database name
title: Database Name
required:
- URI
title: Database
type: object
Environment:
Expand All @@ -83,12 +82,12 @@ $defs:
Predefined:
description: Predefined settings. Will be used in setup stage.
properties:
FIRST_SUPERUSER_LOGIN:
first_superuser_login:
default: admin
description: Login for the first superuser
title: First Superuser Login
type: string
FIRST_SUPERUSER_PASSWORD:
first_superuser_password:
default: admin
description: Password for the first superuser
title: First Superuser Password
Expand All @@ -97,15 +96,15 @@ $defs:
type: object
StaticFiles:
properties:
MOUNT_PATH:
mount_path:
default: /static
title: Mount Path
type: string
MOUNT_NAME:
mount_name:
default: static
title: Mount Name
type: string
DIRECTORY:
directory:
default: static
format: path
title: Directory
Expand All @@ -114,67 +113,67 @@ $defs:
type: object
description: Settings for the application.
properties:
ENVIRONMENT:
environment:
allOf:
- $ref: '#/$defs/Environment'
default: development
description: App environment flag
APP_ROOT_PATH:
app_root_path:
default: ''
description: Prefix for the API path (e.g. "/api/v0")
title: App Root Path
type: string
DATABASE:
database:
allOf:
- $ref: '#/$defs/Database'
description: PostgreSQL database settings
PREDEFINED:
predefined:
allOf:
- $ref: '#/$defs/Predefined'
description: Predefined settings
SESSION_SECRET_KEY:
session_secret_key:
description: Secret key for sessions middleware. Use 'openssl rand -hex 32' to
generate keys
format: password
title: Session Secret Key
type: string
writeOnly: true
JWT_PRIVATE_KEY:
jwt_private_key:
description: Private key for JWT. Use 'openssl genrsa -out private.pem 2048' to
generate keys
format: password
title: Jwt Private Key
type: string
writeOnly: true
JWT_PUBLIC_KEY:
jwt_public_key:
description: Public key for JWT. Use 'openssl rsa -in private.pem -pubout -out
public.pem' to generate keys
title: Jwt Public Key
type: string
STATIC_FILES:
static_files:
allOf:
- $ref: '#/$defs/StaticFiles'
description: Static files settings
CORS_ALLOW_ORIGINS:
cors_allow_origins:
description: CORS origins, used by FastAPI CORSMiddleware
items:
type: string
title: Cors Allow Origins
type: array
ADMIN_PANEL:
admin_panel:
anyOf:
- $ref: '#/$defs/AdminPanel'
- type: 'null'
default: null
description: Admin panel settings. If not set, will be disabled
COOKIE:
cookie:
anyOf:
- $ref: '#/$defs/Cookies'
- type: 'null'
description: Cookies settings
required:
- SESSION_SECRET_KEY
- JWT_PRIVATE_KEY
- JWT_PUBLIC_KEY
- session_secret_key
- jwt_private_key
- jwt_public_key
title: Settings
type: object
20 changes: 10 additions & 10 deletions src/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@
license_info=docs.LICENSE_INFO,
openapi_tags=docs.TAGS_INFO,
servers=[
{"url": settings.APP_ROOT_PATH, "description": "Current"},
{"url": settings.app_root_path, "description": "Current"},
],
root_path=settings.APP_ROOT_PATH,
root_path=settings.app_root_path,
root_path_in_servers=False,
swagger_ui_oauth2_redirect_url=None,
generate_unique_id_function=generate_unique_operation_id,
)

# Static files
if settings.STATIC_FILES is not None:
if settings.static_files is not None:
from starlette.staticfiles import StaticFiles

app.mount(
settings.STATIC_FILES.MOUNT_PATH,
StaticFiles(directory=settings.STATIC_FILES.DIRECTORY),
name=settings.STATIC_FILES.MOUNT_NAME,
settings.static_files.mount_path,
StaticFiles(directory=settings.static_files.directory),
name=settings.static_files.mount_name,
)

# CORS settings
if settings.CORS_ALLOW_ORIGINS:
if settings.cors_allow_origins:
app.add_middleware(
middleware_class=CORSMiddleware,
allow_origins=settings.CORS_ALLOW_ORIGINS,
allow_origins=settings.cors_allow_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

# Mock utilities
if settings.ENVIRONMENT == Environment.DEVELOPMENT:
if settings.environment == Environment.DEVELOPMENT:
from fastapi_mock import MockUtilities

MockUtilities(app, return_example_instead_of_500=True)
Expand All @@ -61,7 +61,7 @@ async def startup_event():
await setup_repositories()

# Admin panel
if settings.ADMIN_PANEL is not None:
if settings.admin_panel is not None:
from src.api.startup import setup_admin_panel

setup_admin_panel(app)
Expand Down
12 changes: 6 additions & 6 deletions src/api/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ async def setup_repositories():
from src.storages.sqlalchemy.storage import SQLAlchemyStorage

# ------------------- Repositories Dependencies -------------------
storage = SQLAlchemyStorage(settings.DATABASE.get_async_engine())
storage = SQLAlchemyStorage(settings.database.get_async_engine())
user_repository = UserRepository(storage)
auth_repository = AuthRepository(storage)

Dependencies.set_auth_repository(auth_repository)
Dependencies.set_storage(storage)
Dependencies.set_user_repository(user_repository)

if settings.ENVIRONMENT == Environment.DEVELOPMENT:
if settings.environment == Environment.DEVELOPMENT:
import logging

logging.getLogger("sqlalchemy.engine").setLevel(logging.WARNING)
Expand All @@ -35,13 +35,13 @@ async def setup_repositories():
def setup_admin_panel(app: FastAPI):
from src.modules.admin.app import init_app

init_app(app, settings.DATABASE.get_async_engine())
init_app(app, settings.database.get_async_engine())


async def setup_predefined():
user_repository = Dependencies.get_user_repository()
if not await user_repository.read_by_login(settings.PREDEFINED.FIRST_SUPERUSER_LOGIN):
if not await user_repository.read_by_login(settings.predefined.first_superuser_login):
await user_repository.create_superuser(
login=settings.PREDEFINED.FIRST_SUPERUSER_LOGIN,
password=settings.PREDEFINED.FIRST_SUPERUSER_PASSWORD,
login=settings.predefined.first_superuser_login,
password=settings.predefined.first_superuser_password,
)
Loading

0 comments on commit 91438d4

Please sign in to comment.