Check if a refresh is needed. A refresh is needed if the expiry time associated with the temporary credentials is less than the provided ``refresh_in``. If ``time_delta`` is not provided, ``self.advisory_refresh_needed`` will be used. For example, if your t
(self, refresh_in=None)
| 520 | return total_seconds(delta) |
| 521 | |
| 522 | def refresh_needed(self, refresh_in=None): |
| 523 | """Check if a refresh is needed. |
| 524 | |
| 525 | A refresh is needed if the expiry time associated |
| 526 | with the temporary credentials is less than the |
| 527 | provided ``refresh_in``. If ``time_delta`` is not |
| 528 | provided, ``self.advisory_refresh_needed`` will be used. |
| 529 | |
| 530 | For example, if your temporary credentials expire |
| 531 | in 10 minutes and the provided ``refresh_in`` is |
| 532 | ``15 * 60``, then this function will return ``True``. |
| 533 | |
| 534 | :type refresh_in: int |
| 535 | :param refresh_in: The number of seconds before the |
| 536 | credentials expire in which refresh attempts should |
| 537 | be made. |
| 538 | |
| 539 | :return: True if refresh needed, False otherwise. |
| 540 | |
| 541 | """ |
| 542 | if self._expiry_time is None: |
| 543 | # No expiration, so assume we don't need to refresh. |
| 544 | return False |
| 545 | |
| 546 | if refresh_in is None: |
| 547 | refresh_in = self._advisory_refresh_timeout |
| 548 | # The credentials should be refreshed if they're going to expire |
| 549 | # in less than 5 minutes. |
| 550 | if self._seconds_remaining() >= refresh_in: |
| 551 | # There's enough time left. Don't refresh. |
| 552 | return False |
| 553 | logger.debug("Credentials need to be refreshed.") |
| 554 | return True |
| 555 | |
| 556 | def _is_expired(self): |
| 557 | # Checks if the current credentials are expired. |