-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): set environment by parameter and envar (#87)
* feat(config): set environment by parameter and envar * fix(static-analysis): solve mypy warnings
- Loading branch information
1 parent
216e976
commit 3a53674
Showing
20 changed files
with
113 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[mypy] | ||
disable_error_code = type-abstract | ||
plugins = pydantic.mypy | ||
|
||
# --strict | ||
disallow_any_generics = true | ||
disallow_subclassing_any = true | ||
disallow_untyped_calls = true | ||
disallow_untyped_defs = true | ||
disallow_incomplete_defs = true | ||
check_untyped_defs = true | ||
disallow_untyped_decorators = true | ||
no_implicit_optional = true | ||
warn_redundant_casts = true | ||
warn_unused_ignores = true | ||
warn_return_any = true | ||
implicit_reexport = false | ||
strict_equality = true | ||
|
||
# --strict end | ||
|
||
[pydantic-mypy] | ||
init_forbid_extra = True | ||
init_typed = True | ||
warn_required_dynamic_aliases = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,60 @@ | ||
from typing import Union | ||
|
||
from pydantic import BaseModel, Field | ||
from pydantic import Field, model_validator | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
from requests import Session | ||
|
||
from alice.onboarding.enums.environment import Environment | ||
|
||
class Config(BaseModel): | ||
class Config: | ||
arbitrary_types_allowed = True | ||
|
||
onboarding_url: str = Field(default="https://apis.alicebiometrics.com/onboarding") | ||
sandbox_url: str = Field( | ||
default="https://apis.alicebiometrics.com/onboarding/sandbox" | ||
) | ||
class Config(BaseSettings): | ||
model_config = SettingsConfigDict(arbitrary_types_allowed=True) | ||
|
||
api_key: Union[str, None] = Field(default=None) | ||
sandbox_token: Union[str, None] = Field(default=None) | ||
environment: Union[Environment, None] = Field( | ||
default=Environment.PRODUCTION, alias="ALICE_ENVIRONMENT" | ||
) | ||
verbose: bool = Field(default=False) | ||
session: Union[Session, None] = Field(default=None) | ||
timeout: Union[float, None] = Field( | ||
default=None, description="Timeout for every request in seconds", ge=0, le=100 | ||
) | ||
send_agent: bool = Field(default=True) | ||
verbose: bool = Field(default=False) | ||
session: Union[Session, None] = Field(default=None) | ||
onboarding_url: Union[str, None] = Field( | ||
default="https://apis.alicebiometrics.com/onboarding" | ||
) | ||
sandbox_url: Union[str, None] = Field( | ||
default="https://apis.alicebiometrics.com/onboarding/sandbox", | ||
description="This path is only used for trials", | ||
) | ||
sandbox_token: Union[str, None] = Field( | ||
default=None, description="This token is only used for trials" | ||
) | ||
|
||
@model_validator(mode="after") | ||
def validate_urls(self) -> "Config": | ||
if self.environment is None: | ||
if isinstance(self.onboarding_url, str): | ||
if "sandbox" in self.onboarding_url: | ||
self.environment = Environment.SANDBOX | ||
elif "staging" in self.onboarding_url: | ||
self.environment = Environment.STAGING | ||
else: | ||
if self.environment == Environment.PRODUCTION: | ||
self.onboarding_url = "https://apis.alicebiometrics.com/onboarding" | ||
self.sandbox_url = "https://apis.alicebiometrics.com/onboarding/sandbox" | ||
elif self.environment == Environment.SANDBOX: | ||
self.onboarding_url = ( | ||
"https://apis.sandbox.alicebiometrics.com/onboarding" | ||
) | ||
self.sandbox_url = ( | ||
"https://apis.sandbox.alicebiometrics.com/onboarding/sandbox" | ||
) | ||
elif self.environment == Environment.STAGING: | ||
self.onboarding_url = ( | ||
"https://apis.staging.alicebiometrics.com/onboarding" | ||
) | ||
self.sandbox_url = ( | ||
"https://apis.staging.alicebiometrics.com/onboarding/sandbox" | ||
) | ||
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from enum import Enum | ||
|
||
|
||
class Environment(Enum): | ||
SANDBOX = "sandbox" | ||
PRODUCTION = "production" | ||
STAGING = "staging" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pyjwt>=2.3.0,<3 | ||
pydantic>=1.8.2,<3 | ||
pydantic-settings<3 | ||
requests>=2.26.0,<3 | ||
meiga>=1.9.1,<2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters