Skip to content

Commit

Permalink
Feature/set global config for verbose (#21)
Browse files Browse the repository at this point in the history
* Set global verbosity with Config object
  • Loading branch information
acostapazo authored Mar 11, 2021
1 parent 54ae96c commit 8d9517c
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 83 deletions.
9 changes: 7 additions & 2 deletions alice/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
class Auth:
@staticmethod
def from_config(config: Config):
return Auth(api_key=config.api_key, url=config.onboarding_url)
return Auth(
api_key=config.api_key, url=config.onboarding_url, verbose=config.verbose
)

def __init__(self, api_key, url: str = DEFAULT_URL):
def __init__(self, api_key, url: str = DEFAULT_URL, verbose: bool = False):
self._auth_client = AuthClient(url, api_key)
self.url = url
self.verbose = verbose

def create_backend_token(
self, user_id: str = None, verbose: bool = False
Expand All @@ -37,6 +40,7 @@ def create_backend_token(
A Result where if the operation is successful it returns BACKEND_TOKEN or BACKEND_TOKEN_WITH_USER.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self._auth_client.create_backend_token(user_id, verbose=verbose)

if response.status_code == 200:
Expand Down Expand Up @@ -70,6 +74,7 @@ def create_user_token(
A Result where if the operation is successful it returns USER_TOKEN.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self._auth_client.create_user_token(user_id, verbose=verbose)

if response.status_code == 200:
Expand Down
1 change: 1 addition & 0 deletions alice/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ class Config:
api_key: str = None
sandbox_token: str = None
send_agent: bool = True
verbose: bool = False
46 changes: 43 additions & 3 deletions alice/onboarding/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ def from_config(config: Config):
auth=Auth.from_config(config),
url=config.onboarding_url,
send_agent=config.send_agent,
verbose=config.verbose,
)

def __init__(self, auth: Auth, url: str = DEFAULT_URL, send_agent: bool = True):
def __init__(
self,
auth: Auth,
url: str = DEFAULT_URL,
send_agent: bool = True,
verbose: bool = False,
):
self.onboarding_client = OnboardingClient(
auth=auth, url=url, send_agent=send_agent
)
self.url = url
self.verbose = verbose

def healthcheck(self, verbose: bool = False) -> Result[bool, OnboardingError]:
"""
Expand All @@ -45,6 +53,7 @@ def healthcheck(self, verbose: bool = False) -> Result[bool, OnboardingError]:
A Result where if the operation is successful it returns True.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.healthcheck(verbose=verbose)

if response.status_code == 200:
Expand Down Expand Up @@ -83,6 +92,7 @@ def create_user(
A Result where if the operation is successful it returns a user_id.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.create_user(
user_info=user_info, device_info=device_info, verbose=verbose
)
Expand Down Expand Up @@ -116,6 +126,7 @@ def delete_user(
A Result where if the operation is successful it returns True.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.delete_user(user_id=user_id, verbose=verbose)

if response.status_code == 200:
Expand Down Expand Up @@ -147,6 +158,7 @@ def get_user_status(
A Result where if the operation is successful it returns a Dict with the status info.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.get_user_status(
user_id=user_id, verbose=verbose
)
Expand Down Expand Up @@ -176,7 +188,8 @@ def get_users(self, verbose: bool = False) -> Result[List[str], OnboardingError]
A Result where if the operation is successful it returns list of string with already created user_ids.
Otherwise, it returns an OnboardingError.
"""
response = self.onboarding_client.get_users()
verbose = self.verbose or verbose
response = self.onboarding_client.get_users(verbose=verbose)

if response.status_code == 200:
return Success(response.json()["users"])
Expand All @@ -201,6 +214,7 @@ def get_users_stats(self, verbose: bool = False) -> Result[Dict, OnboardingError
A Result where if the operation is successful it returns a dict with users information
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.get_users_stats(verbose=verbose)

if response.status_code == 200:
Expand Down Expand Up @@ -252,6 +266,7 @@ def get_users_status(
A Result where if the operation is successful it returns list of dict which represent the status of each user.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.get_users_status(
verbose=verbose,
page=page,
Expand Down Expand Up @@ -306,7 +321,7 @@ def add_user_feedback(
A Result where if the operation is successful it returns True.
Otherwise, it returns an OnboardingError.
"""

verbose = self.verbose or verbose
response = self.onboarding_client.add_user_feedback(
user_id=user_id,
document_id=document_id,
Expand Down Expand Up @@ -348,6 +363,7 @@ def add_selfie(
A Result where if the operation is successful it returns True.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.add_selfie(
user_id=user_id, media_data=media_data, verbose=verbose
)
Expand Down Expand Up @@ -380,6 +396,7 @@ def delete_selfie(
A Result where if the operation is successful it returns True.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.delete_selfie(
user_id=user_id, verbose=verbose
)
Expand Down Expand Up @@ -414,6 +431,7 @@ def void_selfie(
A Result where if the operation is successful it returns True.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.void_selfie(user_id=user_id, verbose=verbose)

if response.status_code == 200:
Expand Down Expand Up @@ -447,6 +465,7 @@ def supported_documents(
A Result where if the operation is successful it returns dict with supported document.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.supported_documents(
user_id=user_id, verbose=verbose
)
Expand Down Expand Up @@ -485,6 +504,7 @@ def create_document(
A Result where if the operation is successful it returns a str with a document_id.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.create_document(
user_id=user_id, type=type, issuing_country=issuing_country, verbose=verbose
)
Expand Down Expand Up @@ -521,6 +541,7 @@ def delete_document(
A Result where if the operation is successful it returns True.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.delete_document(
user_id=user_id, document_id=document_id, verbose=verbose
)
Expand Down Expand Up @@ -557,6 +578,7 @@ def void_document(
A Result where if the operation is successful it returns True.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.void_document(
user_id=user_id, document_id=document_id, verbose=verbose
)
Expand Down Expand Up @@ -610,6 +632,7 @@ def add_document(
A Result where if the operation is successful it returns True.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.add_document(
user_id=user_id,
document_id=document_id,
Expand Down Expand Up @@ -654,6 +677,7 @@ def document_properties(
A Result where if the operation is successful it returns dict with document properties.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.document_properties(
user_id=user_id, document_id=document_id, verbose=verbose
)
Expand Down Expand Up @@ -694,6 +718,7 @@ def create_report(
A Result where if the operation is successful it returns a Dict with the generated report.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.create_report(
user_id=user_id, verbose=verbose, report_version=report_version
)
Expand Down Expand Up @@ -731,6 +756,7 @@ def create_certificate(
A Result where if the operation is successful it returns a str with a pdf_report_id.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.create_certificate(
user_id=user_id, template_name=template_name, verbose=verbose
)
Expand Down Expand Up @@ -766,6 +792,7 @@ def retrieve_certificate(
A Result where if the operation is successful it returns a binary pdf (bytes).
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.retrieve_certificate(
user_id=user_id, certificate_id=certificate_id, verbose=verbose
)
Expand Down Expand Up @@ -799,6 +826,7 @@ def retrieve_certificates(
A Result where if the operation is successful it returns a list of dictionaries.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.retrieve_certificates(
user_id=user_id, verbose=verbose
)
Expand Down Expand Up @@ -834,6 +862,7 @@ def screening(
A Result where if the operation is successful it returns a dictionary.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.screening(
user_id=user_id, detail=detail, verbose=verbose
)
Expand Down Expand Up @@ -864,6 +893,7 @@ def screening_monitor_add(
A Result where if the operation is successful it returns True.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.screening_monitor_add(
user_id=user_id, verbose=verbose
)
Expand Down Expand Up @@ -896,6 +926,7 @@ def screening_monitor_delete(
A Result where if the operation is successful it returns True.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.screening_monitor_delete(
user_id=user_id, verbose=verbose
)
Expand Down Expand Up @@ -929,6 +960,7 @@ def screening_monitor_open_alerts(
A Result where if the operation is successful it returns a dictionary.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.screening_monitor_open_alerts(
start_index=start_index, size=size, verbose=verbose
)
Expand Down Expand Up @@ -961,6 +993,7 @@ def identify_user(
A Result where if the operation is successful it returns a dict with sorted users by face score.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.identify_user(
target_user_id=target_user_id,
probe_user_ids=probe_user_ids,
Expand Down Expand Up @@ -991,6 +1024,7 @@ def authorize_user(
A Result where if the operation is successful it returns True.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.authorize_user(
user_id=user_id, verbose=verbose
)
Expand Down Expand Up @@ -1023,6 +1057,7 @@ def deauthorize_user(
A Result where if the operation is successful it returns True.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.deauthorize_user(
user_id=user_id, verbose=verbose
)
Expand Down Expand Up @@ -1058,6 +1093,7 @@ def authenticate_user(
A Result where if the operation is successful it returns a authentication_id.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.authenticate_user(
user_id=user_id, media_data=media_data, verbose=verbose
)
Expand Down Expand Up @@ -1091,6 +1127,7 @@ def get_authentications_ids(
A Result where if the operation is successful it returns a List of string with all the authentication_ids.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.get_authentications_ids(
user_id=user_id, verbose=verbose
)
Expand Down Expand Up @@ -1136,6 +1173,7 @@ def get_authentications(
the total number of authentications.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.get_authentications(
user_id=user_id,
page_size=page_size,
Expand Down Expand Up @@ -1175,6 +1213,7 @@ def get_authentication(
A Result where if the operation is successful it returns a Dict with the information of one authentication.
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.get_authentication(
user_id=user_id, authentication_id=authentication_id, verbose=verbose
)
Expand Down Expand Up @@ -1210,6 +1249,7 @@ def retrieve_media(
A Result where if the operation is successful it returns a binary image (bytes).
Otherwise, it returns an OnboardingError.
"""
verbose = self.verbose or verbose
response = self.onboarding_client.retrieve_media(
user_id=user_id, media_id=media_id, verbose=verbose
)
Expand Down
16 changes: 14 additions & 2 deletions alice/sandbox/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@
class Sandbox:
@staticmethod
def from_config(config: Config):
return Sandbox(sandbox_token=config.sandbox_token, url=config.sandbox_url)
return Sandbox(
sandbox_token=config.sandbox_token,
url=config.sandbox_url,
verbose=config.verbose,
)

def __init__(self, sandbox_token: str, url: str = DEFAULT_URL):
def __init__(
self, sandbox_token: str, url: str = DEFAULT_URL, verbose: bool = False
):
self.sandbox_client = SandboxClient(sandbox_token=sandbox_token, url=url)
self.url = url
self.verbose = verbose

@staticmethod
def _is_token_valid(token, margin_seconds: int = 60):
Expand All @@ -45,6 +52,7 @@ def healthcheck(self, verbose: bool = False) -> Result[bool, SandboxError]:
A Result where if the operation is successful it returns True.
Otherwise, it returns an SandboxError.
"""
verbose = self.verbose or verbose
response = self.sandbox_client.healthcheck(verbose=verbose)

if response.status_code == 200:
Expand Down Expand Up @@ -82,6 +90,7 @@ def create_user(
A Result where if the operation is successful it returns a user_id.
Otherwise, it returns an SandboxError.
"""
verbose = self.verbose or verbose
response = self.sandbox_client.create_user(
user_info=user_info, device_info=device_info, verbose=verbose
)
Expand Down Expand Up @@ -114,6 +123,7 @@ def delete_user(
A Result where if the operation is successful it returns True.
Otherwise, it returns an SandboxError.
"""
verbose = self.verbose or verbose
response = self.sandbox_client.delete_user(email=email, verbose=verbose)

if response.status_code == 200:
Expand Down Expand Up @@ -141,6 +151,7 @@ def get_user(self, email: str, verbose: bool = False) -> Result[Dict, SandboxErr
A Result where if the operation is successful it returns a Dict with the status info.
Otherwise, it returns an SandboxError.
"""
verbose = self.verbose or verbose
response = self.sandbox_client.get_user(email=email, verbose=verbose)

if response.status_code == 200:
Expand Down Expand Up @@ -170,6 +181,7 @@ def get_user_token(
A Result where if the operation is successful it returns list of string with already created user_ids.
Otherwise, it returns an SandboxError.
"""
verbose = self.verbose or verbose
response = self.sandbox_client.get_user_token(email=email, verbose=verbose)

if response.status_code == 200:
Expand Down
Loading

0 comments on commit 8d9517c

Please sign in to comment.