Method: Spaceship::Client#has_valid_session
- Defined in:
- spaceship/lib/spaceship/client.rb
#has_valid_session ⇒ Object
Check if we have a cached/valid session
Background: December 4th 2017 Apple introduced a rate limit - which is of course fine by itself - but unfortunately also rate limits successful logins. If you call multiple tools in a lane (e.g. call match 5 times), this would lock you out of the account for a while. By loading existing sessions and checking if they’re valid, we’re sending less login requests. More context on why this change was necessary github.com/fastlane/fastlane/pull/11108
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'spaceship/lib/spaceship/client.rb', line 415 def has_valid_session # If there was a successful manual login before, we have a session on disk if load_session_from_file # Check if the session is still valid here begin # We use the olympus session to determine if the old session is still valid # As this will raise an exception if the old session has expired # If the old session is still valid, we don't have to do anything else in this method # that's why we return true return true if fetch_olympus_session rescue # If the `fetch_olympus_session` method raises an exception # we'll land here, and therefore continue doing a full login process # This happens if the session we loaded from the cache isn't valid any more # which is common, as the session automatically invalidates after x hours (we don't know x) # In this case we don't actually care about the exact exception, and why it was failing # because either way, we'll have to do a fresh login, where we do the actual error handling puts("Available session is not valid any more. Continuing with normal login.") end end # # The user can pass the session via environment variable (Mainly used in CI environments) if load_session_from_env # see above begin # see above return true if fetch_olympus_session rescue puts("Session loaded from environment variable is not valid. Continuing with normal login.") # see above end end # # After this point, we sure have no valid session any more and have to create a new one # return false end |