Skip to content

Commit

Permalink
Merge pull request #92 from alice-biometrics/bugfix/config-environmen…
Browse files Browse the repository at this point in the history
…t-without-envar

fix(config): solving error configuring environment using Config inste…
  • Loading branch information
miguel-lorenzo committed Nov 8, 2023
2 parents 950d127 + bac98eb commit 3f871c9
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 241 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,8 @@ jobs:
run: python examples/onboarding.py
- name: Example [Onboarding Get Users]
run: python examples/onboarding_get_users.py
- name: Example [Onboarding Report V0]
run: python examples/onboarding_report_v0.py
- name: Example [Onboarding with Identification]
run: python examples/onboarding_with_identification.py
- name: Example [Onboarding with user matching]
run: python examples/onboarding_with_user_matching.py
- name: Example [Onboarding with Certificate]
run: python examples/onboarding_with_certificate.py
- name: Example [Onboarding with Screening]
Expand Down
1 change: 0 additions & 1 deletion alice/auth/auth_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def _create_backend_token(self, verbose: Optional[bool] = False) -> Response:
if result.is_failure:
return result.value # type: ignore
login_token = result.unwrap()

url = f"{self.url}/backend_token"
headers = {"Authorization": f"Bearer {login_token}"}
if self.use_cache:
Expand Down
2 changes: 1 addition & 1 deletion alice/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class Config(BaseSettings):
model_config = SettingsConfigDict(arbitrary_types_allowed=True)
model_config = SettingsConfigDict(arbitrary_types_allowed=True, extra="allow")

api_key: Union[str, None] = Field(default=None)
environment: Union[Environment, None] = Field(
Expand Down
2 changes: 1 addition & 1 deletion alice/onboarding/enums/environment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum


class Environment(Enum):
class Environment(str, Enum):
SANDBOX = "sandbox"
PRODUCTION = "production"
STAGING = "staging"
40 changes: 0 additions & 40 deletions alice/onboarding/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from alice.onboarding.enums.document_source import DocumentSource
from alice.onboarding.enums.document_type import DocumentType
from alice.onboarding.enums.duplicates_resource_type import DuplicatesResourceType
from alice.onboarding.enums.match_case import MatchCase
from alice.onboarding.enums.onboarding_steps import OnboardingSteps
from alice.onboarding.enums.user_state import UserState
from alice.onboarding.enums.version import Version
Expand Down Expand Up @@ -1215,45 +1214,6 @@ def identify_user(
)
)

@early_return
def user_matching(
self,
user_id: str,
match_case: MatchCase,
verbose: bool = False,
) -> Result[bool, Union[OnboardingError, AuthError]]:
"""
It performs face matching between all the user selfies or documents. This call requires a BACKEND_TOKEN_WITH_USER_ID..
Parameters
----------
user_id
User identifier
match_case
Evidence (selfies or docs) on which to perform the matching
verbose
Used for print service response as well as the time elapsed
Returns
-------
A Result where if the operation is successful it returns a list of face matchings.
Otherwise, it returns an OnboardingError or AuthError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.user_matching(
user_id=user_id,
match_case=match_case,
verbose=verbose,
).unwrap_or_return()

if response.status_code == 200:
return Success(response.json())
else:
return Failure(
OnboardingError.from_response(
operation="user_matching", response=response
)
)

def enable_authentication(
self, user_id: str, verbose: bool = False
) -> Result[bool, Union[OnboardingError, AuthError]]:
Expand Down
46 changes: 0 additions & 46 deletions alice/onboarding/onboarding_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from alice.onboarding.enums.document_source import DocumentSource
from alice.onboarding.enums.document_type import DocumentType
from alice.onboarding.enums.duplicates_resource_type import DuplicatesResourceType
from alice.onboarding.enums.match_case import MatchCase
from alice.onboarding.enums.onboarding_steps import OnboardingSteps
from alice.onboarding.enums.user_state import UserState
from alice.onboarding.enums.version import Version
Expand Down Expand Up @@ -1381,51 +1380,6 @@ def identify_user(

return Success(response)

@early_return
def user_matching(
self,
user_id: str,
match_case: MatchCase,
verbose: bool = False,
) -> Result[Response, Error]:
"""
It performs face matching between all the user selfies or documents. This call requires a BACKEND_TOKEN_WITH_USER_ID..
Parameters
----------
user_id
User identifier
match_case
Evidence (selfies or docs) on which to perform the matching
verbose
Used for print service response as well as the time elapsed
Returns
-------
A Result object with Response object [requests library] if Success
"""
print_intro("user_matching", verbose=verbose)

backend_user_token = self.auth.create_backend_token(
user_id=user_id
).unwrap_or_return()
print_token("backend_token_with_user", backend_user_token, verbose=verbose)

headers = self._auth_headers(backend_user_token)

try:
response = self.session.get(
f"{self.url}/user/match?match_case={match_case.value}",
headers=headers,
timeout=self.timeout,
)
except requests.exceptions.Timeout:
return Failure(OnboardingError.timeout(operation="user_matching"))
print_response(response=response, verbose=verbose)

return Success(response)

@early_return
@timeit
def enable_authentication(
Expand Down
98 changes: 0 additions & 98 deletions examples/onboarding_report_v0.py

This file was deleted.

48 changes: 0 additions & 48 deletions examples/onboarding_with_user_matching.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_integration_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_should_return_an_error_when_the_api_key_is_not_configured():

@pytest.mark.unit
def test_should_timeout_when_time_exceeded(given_valid_api_key):
config = Config(api_key=given_valid_api_key, timeout=0.1)
config = Config(api_key=given_valid_api_key, timeout=0.01)
onboarding = Onboarding.from_config(config)

result = onboarding.create_flow(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_integration_onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_should_return_an_error_when_the_api_key_is_not_configured():
def test_should_timeout_when_time_exceeded(
given_valid_api_key, given_any_selfie_image_media_data
):
config = Config(api_key=given_valid_api_key, timeout=0.1)
config = Config(api_key=given_valid_api_key, timeout=0.01)
onboarding = Onboarding.from_config(config)

result = onboarding.create_user(
Expand Down

0 comments on commit 3f871c9

Please sign in to comment.