@@ -34,14 +34,15 @@ from your_application.settings import settings
3434application: litestar.Litestar = LitestarBootstrapper(settings).bootstrap()
3535```
3636
37- With <b >microbootstrap</b >, you get an application with built-in support for:
37+ Only ` litestar ` is supported yet.
38+ With <b >microbootstrap</b >, you get an application with lightweight built-in support for:
3839
3940- ` sentry `
4041- ` prometheus `
4142- ` opentelemetry `
4243- ` logging `
43-
44- < b >microbootstrap</ b > supports only ` litestar ` framework for now.
44+ - ` cors `
45+ - ` swagger ` - additional offline version support
4546
4647Interested? Let's jump right into it ⚡
4748
@@ -58,7 +59,7 @@ $ poetry add microbootstrap -E litestar
5859pip:
5960
6061``` bash
61- $ poetry add microbootstrap[litestar]
62+ $ pip install microbootstrap[litestar]
6263```
6364
6465## Quickstart
@@ -163,6 +164,8 @@ Currently, these instruments are already supported for bootstrapping:
163164- ` prometheus `
164165- ` opentelemetry `
165166- ` logging `
167+ - ` cors `
168+ - ` swagger `
166169
167170Let's make it clear, what it takes to bootstrap them.
168171
@@ -247,7 +250,7 @@ class YourSettings(BaseBootstrapSettings):
247250
248251All these settings are then passed to [ opentelemetry] ( https://opentelemetry.io/ ) , completing your Opentelemetry integration.
249252
250- ## Logging
253+ ### Logging
251254
252255<b >microbootstrap</b > provides in-memory json logging using [ structlog] ( https://pypi.org/project/structlog/ ) .
253256To learn more about in-memory logging, check out [ MemoryHandler] ( https://docs.python.org/3/library/logging.handlers.html#memoryhandler )
@@ -280,6 +283,59 @@ Parameters description:
280283- ` logging_extra_processors ` - set additional structlog processors if you have some.
281284- ` logging_exclude_endpoints ` - remove logging on certain endpoints.
282285
286+ ### Swagger
287+
288+ ``` python
289+ from microbootstrap.bootstrappers.litestar import BaseBootstrapSettings
290+
291+
292+ class YourSettings (BaseBootstrapSettings ):
293+ service_name: str = " micro-service"
294+ service_description: str = " Micro service description"
295+ service_version: str = " 1.0.0"
296+ service_static_path: str = " /static"
297+
298+ swagger_path: str = " /docs"
299+ swagger_offline_docs: bool = False
300+ swagger_extra_params: dict[str , Any] = {}
301+ ```
302+
303+ Parameters description:
304+
305+ - ` service_environment ` - will be displayed in docs.
306+ - ` service_name ` - will be displayed in docs.
307+ - ` service_description ` - will be displayed in docs.
308+ - ` service_static_path ` - set additional structlog processors if you have some.
309+ - ` swagger_path ` - path of the docs.
310+ - ` swagger_offline_docs ` - makes swagger js bundles access offline, because service starts to host via static.
311+ - ` swagger_extra_params ` - additional params to pass into openapi config.
312+
313+ ### Cors
314+
315+ ``` python
316+ from microbootstrap.bootstrappers.litestar import BaseBootstrapSettings
317+
318+
319+ class YourSettings (BaseBootstrapSettings ):
320+ cors_allowed_origins: list[str ] = pydantic.Field(default_factory = list )
321+ cors_allowed_methods: list[str ] = pydantic.Field(default_factory = list )
322+ cors_allowed_headers: list[str ] = pydantic.Field(default_factory = list )
323+ cors_exposed_headers: list[str ] = pydantic.Field(default_factory = list )
324+ cors_allowed_credentials: bool = False
325+ cors_allowed_origin_regex: str | None = None
326+ cors_max_age: int = 600
327+ ```
328+
329+ Parameters description:
330+
331+ - ` cors_allowed_origins ` - list of origins that are allowed.
332+ - ` cors_allowed_methods ` - list of allowed HTTP methods.
333+ - ` cors_allowed_headers ` - list of allowed headers.
334+ - ` cors_exposed_headers ` - list of headers that are exposed via the 'Access-Control-Expose-Headers' header.
335+ - ` cors_allowed_credentials ` - boolean dictating whether or not to set the 'Access-Control-Allow-Credentials' header.
336+ - ` cors_allowed_origin_regex ` - regex to match origins against.
337+ - ` cors_max_age ` - response caching TTL in seconds, defaults to 600.
338+
283339## Configuration
284340
285341Despite settings being pretty convenient mechanism, it's not always possible to store everything in settings.
@@ -294,6 +350,8 @@ To configure instruemt manually, you have to import one of available configs fro
294350- ` OpentelemetryConfig `
295351- ` PrometheusConfig `
296352- ` LoggingConfig `
353+ - ` SwaggerConfig `
354+ - ` CorsConfig `
297355
298356And pass them into ` .configure_instrument ` or ` .configure_instruments ` bootstrapper method.
299357
@@ -428,8 +486,8 @@ from microbootstrap.instruments.base import Instrument
428486
429487
430488class MyInstrument(Instrument[MyInstrumentConfig]):
431- def write_status( self , console_writer: ConsoleWriter) -> None :
432- pass
489+ instrument_name: str
490+ ready_condition: str
433491
434492 def is_ready(self ) -> bool :
435493 pass
@@ -447,10 +505,16 @@ class MyInstrument(Instrument[MyInstrumentConfig]):
447505
448506And now you can define behaviour of your instrument
449507
450- - `write_status` - writes status to console, indicating, is instrument bootstrapped.
451- - `is_ready` - defines ready for bootstrapping state of instrument, based on it' s config values.
452- - `teardown` - graceful shutdown for instrument during application shutdown.
453- - `bootstrap` - main instrument' s logic.
508+ Attributes:
509+
510+ - `instrument_name` - Will be displayed in your console during bootstrap.
511+ - `ready_condition` - Will be displayed in your console during bootstrap if instument is not ready.
512+
513+ Methods:
514+
515+ - `is_ready` - defines ready for bootstrapping state of instrument, based on it' s config values. Required.
516+ - `teardown` - graceful shutdown for instrument during application shutdown. Not required.
517+ - `bootstrap` - main instrument' s logic. Not required.
454518
455519When you have a carcass of instrument, you can adapt it for every framework existing.
456520Let' s adapt it for litestar for example
0 commit comments