Coverage for fio_wrapper/decorator.py: 100%
12 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-16 11:50 +0100
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-16 11:50 +0100
1from functools import wraps
3from fio_wrapper.exceptions import NoAPIKeyProvided
4from fio_wrapper.fio_adapter import FIOAdapter
7def apikey_required(func) -> any:
8 """Wraps endpoint and check for FIO API Key
10 Args:
11 func (method): Wrapped endpoint method
13 Raises:
14 SystemExit: Decorator can only be used on endpoints
15 NoAPIKeyProvided: FIO API Key not provided, but endpoint requires it.
17 Returns:
18 method: Executed endpoint method
19 """
21 @wraps(func)
22 def wrapper_apikey_required(self, *args, **kwargs):
23 # can only decorate endpoint functions
24 if self.adapter is None or not isinstance(self.adapter, FIOAdapter):
25 raise SystemExit("apikey_required decorator can only be used on endpoints")
27 # requires API Key set in adapter
28 if self.adapter.header is None or self.adapter.header["Authorization"] is None:
29 raise NoAPIKeyProvided(
30 "FIO API Key not provided. This endpoint requires an API key."
31 )
33 return func(self, *args, **kwargs)
35 return wrapper_apikey_required