Skip checking creds (#5737)

* skip checking creds

* fix bug

* ok mypy

* add comment

* rename required_credentials

* fix

* fix top_retail bug

* don't require creds in some nasdaq fetchers

* black

* this was not here before

* fix tests

* update fetcher test

* update contributing guidelines
This commit is contained in:
montezdesousa
2023-11-17 16:15:34 +00:00
committed by GitHub
parent 86aa18b7d0
commit 565cafba53
34 changed files with 136 additions and 74 deletions

View File

@@ -243,7 +243,7 @@ Steps to create an `OBBject` extension:
```python
from openbb_core.app.model.extension import Extension
ext = Extension(name="example", required_credentials=["some_api_key"])
ext = Extension(name="example", credentials=["some_api_key"])
```
3. Optionally declare an `OBBject` accessor, it will use the extension name:

View File

@@ -36,11 +36,11 @@ class CredentialsLoader:
@staticmethod
def prepare(
required_credentials: Dict[str, Set[str]],
credentials: Dict[str, Set[str]],
) -> Dict[str, Tuple[object, None]]:
"""Prepare credentials map to be used in the Credentials model"""
formatted: Dict[str, Tuple[object, None]] = {}
for origin, creds in required_credentials.items():
for origin, creds in credentials.items():
for c in creds:
# Not sure we should do this, if you require the same credential it breaks
# if c in formatted:
@@ -61,7 +61,7 @@ class CredentialsLoader:
try:
entry = entry_point.load()
if isinstance(entry, Extension):
for c in entry.required_credentials:
for c in entry.credentials:
self.credentials["obbject"].add(c)
except Exception as e:
traceback.print_exception(type(e), e, e.__traceback__)
@@ -70,7 +70,7 @@ class CredentialsLoader:
def from_providers(self) -> None:
"""Load credentials from providers"""
self.credentials["providers"] = set()
for c in ProviderInterface().required_credentials:
for c in ProviderInterface().credentials:
self.credentials["providers"].add(c)
def load(self) -> BaseModel:

View File

@@ -11,7 +11,7 @@ class Extension:
def __init__(
self,
name: str,
required_credentials: Optional[List[str]] = None,
credentials: Optional[List[str]] = None,
) -> None:
"""Initialize the extension.
@@ -19,11 +19,11 @@ class Extension:
----------
name : str
Name of the extension.
required_credentials : Optional[List[str]], optional
credentials : Optional[List[str]], optional
List of required credentials, by default None
"""
self.name = name
self.required_credentials = required_credentials or []
self.credentials = credentials or []
@property
def obbject_accessor(self) -> Callable:

View File

@@ -64,8 +64,8 @@ class ProviderInterface(metaclass=SingletonMeta):
----------
map : MapType
Dictionary of provider information.
required_credentials: List[str]
List of required_credentials.
credentials: List[str]
List of credentials.
model_providers : Dict[str, ProviderChoices]
Dictionary of provider choices by model.
params : Dict[str, Dict[str, Union[StandardParams, ExtraParams]]]
@@ -110,9 +110,9 @@ class ProviderInterface(metaclass=SingletonMeta):
return self._map
@property
def required_credentials(self) -> List[str]:
def credentials(self) -> List[str]:
"""Dictionary of required credentials by provider."""
return self._registry_map.required_credentials
return self._registry_map.credentials
@property
def model_providers(self) -> Dict[str, ProviderChoices]:

View File

@@ -6,7 +6,7 @@ def test_credentials():
with patch(
target="openbb_core.app.model.credentials.ProviderInterface"
) as mock_provider_interface:
mock_provider_interface.required_credentials = {
mock_provider_interface.credentials = {
"benzinga_api_key": (typing.Optional[str], None),
"polygon_api_key": (typing.Optional[str], None),
}

View File

@@ -27,11 +27,11 @@ def test_map(provider_interface):
assert "EquityHistorical" in provider_interface_map
def test_required_credentials(provider_interface):
def test_credentials(provider_interface):
"""Test required credentials."""
required_credentials = provider_interface.required_credentials
assert isinstance(required_credentials, list)
assert len(required_credentials) > 0
credentials = provider_interface.credentials
assert isinstance(credentials, list)
assert len(credentials) > 0
def test_model_providers(provider_interface):