feat: configurable API rate limit
This commit is contained in:
@@ -17,6 +17,7 @@ class Parameters:
|
|||||||
timeout: int = 120
|
timeout: int = 120
|
||||||
db_uri: str = "sqlite://db.sqlite"
|
db_uri: str = "sqlite://db.sqlite"
|
||||||
cache_uri: str = "memory://"
|
cache_uri: str = "memory://"
|
||||||
|
api_rate_limit: str = "100/minute"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_namespace(cls, args: argparse.Namespace) -> Parameters:
|
def from_namespace(cls, args: argparse.Namespace) -> Parameters:
|
||||||
@@ -128,5 +129,12 @@ def parse_parameters(args: typing.Sequence[str]) -> Parameters:
|
|||||||
default=default_values.cache_uri,
|
default=default_values.cache_uri,
|
||||||
help_txt="cache connection URI",
|
help_txt="cache connection URI",
|
||||||
)
|
)
|
||||||
|
__add_arg_str(
|
||||||
|
parser,
|
||||||
|
"--api-rate-limit",
|
||||||
|
env_var="API_RATE_LIMIT",
|
||||||
|
default=default_values.api_rate_limit,
|
||||||
|
help_txt="API rate limit (flask-limiter syntax)",
|
||||||
|
)
|
||||||
parsed_args = parser.parse_args(args)
|
parsed_args = parser.parse_args(args)
|
||||||
return Parameters.from_namespace(parsed_args)
|
return Parameters.from_namespace(parsed_args)
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ class Server(gunicorn.app.base.BaseApplication):
|
|||||||
self.limiter = flask_limiter.Limiter(
|
self.limiter = flask_limiter.Limiter(
|
||||||
flask_limiter.util.get_remote_address,
|
flask_limiter.util.get_remote_address,
|
||||||
app=self.app,
|
app=self.app,
|
||||||
default_limits=["100 per minute"],
|
default_limits=[params.api_rate_limit],
|
||||||
storage_uri=params.cache_uri,
|
storage_uri=params.cache_uri,
|
||||||
)
|
)
|
||||||
self._index_content: str | None = None
|
self._index_content: str | None = None
|
||||||
|
|||||||
Reference in New Issue
Block a user