apache/libcloud — pull request #178 by Kami (2013-11-13 15:33:50+00:00)
Title: [LIBCLOUD-428] Fix auth token caching and re-use in the OpenStack based drivers

This branch fixes an issue described in LIBCLOUD-436 (https://issues.apache.org/jira/browse/LIBCLOUD-428).

As noted in the ticket description, the problem is that current version of code doesn't properly check if the token has expired before using it. This causes `InvalidCredsError` exception to be thrown if the token has expired.

This is usually a non-issue for short running scripts, but if you are using a driver in a long running process, there is a bigger chance that the token will expire during the life-time of the process and as such, the exception will be thrown.

While working on this bug, I also discovered an issue with `ex_force_auth_token` argument. Currently we support skipping the authentication process by passing a valid auth token to the driver constructor using `ex_force_auth_token` argument.

The problem is that we don't know about the token expiration time when this argument is used. Ss such, we can't invalidate the token when it's about to expire. My solution to this problem was documenting this behavior better in the documentation.

As you can see in the diff, I also needed to update the fixtures for tests to pass. The approach that I used is not ideal since it's basically a ticking time bomb, but I opted for a simple and less time-consuming solution at this point and hopefully we will figure a better one by 2031 :P