beanie icon indicating copy to clipboard operation
beanie copied to clipboard

Using beanie in with rotating/dynamic credentials

Open juskaiser opened this issue 2 years ago • 6 comments

I'm interested in using beanie for a project with API that is backed by Atlas. One of the constraints I have is the use of rotating credentials that get updated hourly.

Are there any examples or recommendations for using beanie in this situation? How would one update the existing beanie initialization with new credentials and close the previously created motor client? I'm hoping the update would be seamless/transparent to end-users of the API: any in-process requests would be fulfilled and there would be no interruption in the Mongo connection as API requests continue to come in.

juskaiser avatar Mar 14 '22 21:03 juskaiser

Oh. This is interesting. Could you pls tell me, how do you handle this without Beanie? I can include this to the init function, if it will fit

roman-right avatar Mar 22 '22 10:03 roman-right

To add to this atlas requires pymongo[srv]. How are you getting past with a default install of beanie:

pymongo.errors.ConfigurationError: The "dnspython" module must be installed to use mongodb+srv:// URIs. To fix this error install pymongo with the srv extra:
 /workspaces/OS-CFDB/.venv/bin/python -m pip install "pymongo[srv]"

killswitch-GUI avatar Mar 31 '22 14:03 killswitch-GUI

We just installed dnspython as another requirement. For the original post thought: When using just Motor, we setup a wrapper when calling atlas and when we received an auth error, we just grabbed the new credentials from the secrets file and setup a a new connection. When using Beanie, we've explored a couple options, but it looks like where we are landing is watching a file that is populated with a vault side car and assigning a new client to beanie. We debated rerunning the full init, but I'm hesitant because of the overhead with validating the collections/indexes, so I was wondering if we could get a helper function to tell the Document classes to use a new connection/collection and skip all the initial startup processes. We can post some of our existing ideas, but I don't love them and think a beanie helper function would be super helpful.

kawidman3 avatar Apr 04 '22 13:04 kawidman3

Hey. I have to check, which steps of init could be skipped (using relative argument explicitly) to not break things. I'll come back here soon and tell, what are the plans about this.

roman-right avatar Apr 04 '22 14:04 roman-right

This issue is stale because it has been open 30 days with no activity.

github-actions[bot] avatar Feb 10 '23 02:02 github-actions[bot]

This issue was closed because it has been stalled for 14 days with no activity.

github-actions[bot] avatar Feb 25 '23 02:02 github-actions[bot]