Skip to content

Commit

Permalink
Merge pull request #4 from alice-biometrics/feature/add_send_agent_bool
Browse files Browse the repository at this point in the history
Added option to send or not user agent
  • Loading branch information
miguel-lorenzo authored Apr 6, 2020
2 parents 3e721d1 + 6a89480 commit a94eea6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
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:
auth_url: str = "https://apis.alicebiometrics.com/auth"
api_key: str = None
sandbox_token: str = None
send_agent: bool = True
12 changes: 9 additions & 3 deletions alice/onboarding/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@
class Onboarding:
@staticmethod
def from_config(config: Config):
return Onboarding(auth=Auth.from_config(config), url=config.onboarding_url)
return Onboarding(
auth=Auth.from_config(config),
url=config.onboarding_url,
send_agent=config.send_agent,
)

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

def healthcheck(self, verbose: bool = False) -> Result[bool, OnboardingError]:
Expand Down
24 changes: 14 additions & 10 deletions alice/onboarding/onboarding_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@


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

def _auth_headers(self, token: str):
auth_headers = {
"Authorization": "Bearer {}".format(token),
"Alice-User-Agent": "onboarding-python/{} ({}; {}) python {}".format(
alice.__version__,
platform.system(),
platform.release(),
platform.python_version(),
),
}
auth_headers = {"Authorization": "Bearer {}".format(token)}
if self.send_agent:
auth_headers.update(
{
"Alice-User-Agent": "onboarding-python/{} ({}; {}) python {}".format(
alice.__version__,
platform.system(),
platform.release(),
platform.python_version(),
)
}
)
return auth_headers

@timeit
Expand Down

0 comments on commit a94eea6

Please sign in to comment.