NERSC / sfapi_client

Python client for SF API
https://nersc.github.io/sfapi_client/
Other
10 stars 3 forks source link

[Async]Client.update_credentials(client_id=None, secret=None, key=None) method #91

Open MrCreosote opened 1 week ago

MrCreosote commented 1 week ago

It would be very helpful to have a method to update the credentials for a client without having to create a new client. The use case here is a service that contacts the API in a few places in the code base. When the credentials expire, all those clients need to be replaced. If there was an update method, a separate coroutine could monitor a creds file for changes and call the update method and the various parts of the service could wouldn't have to be concerned with replacing the client and closing the old client.

cjh1 commented 4 days ago

@MrCreosote what is the complication with just creating a new client? Is it that you have a processing loop with the client context? Something like this?:

async with AsyncClient(client_id, client_secret) as client:
   # processing loop
MrCreosote commented 4 days ago

The context is a service that consists of multiple modules that have references to the AsyncClient. That means whenever the credentials are updated, all those references need to be updated to the new client and the old client has to be closed - but it can't be closed immediately as there may be client calls in flight. I have an implementation that does this but it wound up being pretty complex.

If creds can be updated on the fly, we don't have to worry about closing the old client with a delay or replacing references - we just need a cred checking loop with a reference to the client that updates the creds via the method in the issue title.