2
0

AccessKeyFetcher.h 869 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include <atomic> // or std::atomic
  3. #include <functional> // for function
  4. #include <memory> // for shared_ptr
  5. #include <string> // for string
  6. namespace cspot {
  7. struct Context;
  8. class AccessKeyFetcher {
  9. public:
  10. AccessKeyFetcher(std::shared_ptr<cspot::Context> ctx);
  11. /**
  12. * @brief Checks if key is expired
  13. * @returns true when currently held access key is not valid
  14. */
  15. bool isExpired();
  16. /**
  17. * @brief Fetches a new access key
  18. * @remark In case the key is expired, this function blocks until a refresh is done.
  19. * @returns access key
  20. */
  21. std::string getAccessKey();
  22. /**
  23. * @brief Forces a refresh of the access key
  24. */
  25. void updateAccessKey();
  26. private:
  27. std::shared_ptr<cspot::Context> ctx;
  28. std::atomic<bool> keyPending = false;
  29. std::string accessKey;
  30. long long int expiresAt;
  31. };
  32. } // namespace cspot