Datatamer / tamr-client

Programmatically interact with Tamr
https://tamr-client.readthedocs.io
Apache License 2.0
11 stars 25 forks source link

Use session auth token cookie to minimize re-auth events #490

Closed skalish closed 3 years ago

skalish commented 3 years ago

↪️ Pull Request

This PR adds the capability to fetch and store Tamr auth cookies to reuse sessions and limit the necessary number of calls to the Tamr auth service.

For TC, auth cookie fetching is done automatically whenever a request is made to the Tamr server and a valid cookie is not already stored.

For TUC, an auth cookie is fetched when a Client is created with the store_auth_cookie parameter set to True. It is False by default. An existing Client without an auth cookie can be manually directed to fetch one with the method .set_auth_cookie().

Closes #305

💻 Examples

from tamr_unify_client.auth import UsernamePasswordAuth
from tamr_unify_client.client import Client

auth = UsernamePasswordAuth("my_username", "my_password")
client = Client(auth, store_auth_cookie=True)

# OR

client = Client(auth)
client.set_auth_cookie()

✔️ PR Todo

pcattori commented 3 years ago

What about something like:

session: tc.Session = tc.session.make(instance=i, auth=a)

where tc.Session is a dataclass:

@dataclass(frozen=true)
class Session:
  _session: requests.Session
  auth: requests.AuthThingy
  instance: tc.Instance
pcattori commented 3 years ago

Or with monkey-patching:

  def __init__(self):
    self._session.request = our request function?
github-actions[bot] commented 3 years ago

:tada: This PR is included in version 1.4.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: