(self)
| 558 | return self.refresh_needed(refresh_in=0) |
| 559 | |
| 560 | def _refresh(self): |
| 561 | # In the common case where we don't need a refresh, we |
| 562 | # can immediately exit and not require acquiring the |
| 563 | # refresh lock. |
| 564 | if not self.refresh_needed(self._advisory_refresh_timeout): |
| 565 | return |
| 566 | |
| 567 | # acquire() doesn't accept kwargs, but False is indicating |
| 568 | # that we should not block if we can't acquire the lock. |
| 569 | # If we aren't able to acquire the lock, we'll trigger |
| 570 | # the else clause. |
| 571 | if self._refresh_lock.acquire(False): |
| 572 | try: |
| 573 | if not self.refresh_needed(self._advisory_refresh_timeout): |
| 574 | return |
| 575 | is_mandatory_refresh = self.refresh_needed( |
| 576 | self._mandatory_refresh_timeout |
| 577 | ) |
| 578 | self._protected_refresh(is_mandatory=is_mandatory_refresh) |
| 579 | return |
| 580 | finally: |
| 581 | self._refresh_lock.release() |
| 582 | elif self.refresh_needed(self._mandatory_refresh_timeout): |
| 583 | # If we're within the mandatory refresh window, |
| 584 | # we must block until we get refreshed credentials. |
| 585 | with self._refresh_lock: |
| 586 | if not self.refresh_needed(self._mandatory_refresh_timeout): |
| 587 | return |
| 588 | self._protected_refresh(is_mandatory=True) |
| 589 | |
| 590 | def _protected_refresh(self, is_mandatory): |
| 591 | # precondition: this method should only be called if you've acquired |
no test coverage detected