Original post

Attempting to access a website with Scraping like behavior that requires an authentication flow, I’d like to persist authentication sessions for a given TTL. I used example documentation I found with the standard libraries CookieJar and have been able to authenticate correctly, but any suggestions on how to persist the cookies to disk and reuse them?

— Use caseI’m looking to build a CLI to interact with a website I use frequently that does not offer a public API. It’s essentially a cloud service provider that gives environments with a TTL that the resources will be destroyed. Currently the only method to create them is tedious and manual. My concerns are the following:

– Site has short 20m authenticated sessions- Logging in for each subsequent command would be slow, and likely be flagged as strange- Only 1 domain, each CLI command would be align to a basic sequential CRUD operation

My design idea would be to create a folder in ~/.config/mycli/auth.json with a username/password as well as a few configuration details like regional information.I want to automatically have each CLI invocation check a file in the ~/.config/mysite folder and use the existing session cookies if they exist, and check a generated time for guessing TTL and re-authenticating.