EndpointProvider.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 1999-2019 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_ENDPOINTPROVIDER_H_
  17. #define CORE_INCLUDE_ALIBABACLOUD_CORE_ENDPOINTPROVIDER_H_
  18. #include <alibabacloud/core/location/LocationClient.h>
  19. #include <alibabacloud/core/CoreClient.h>
  20. #include <string>
  21. #include <chrono>
  22. #include <list>
  23. #include <map>
  24. #include <memory>
  25. #include <mutex>
  26. namespace AlibabaCloud {
  27. class ALIBABACLOUD_CORE_EXPORT EndpointProvider :
  28. public Location::LocationClient {
  29. public:
  30. typedef Outcome<Error, std::string> EndpointOutcome;
  31. EndpointProvider(
  32. const std::shared_ptr<Location::LocationClient>& locationClient,
  33. const std::string regionId,
  34. const std::string product,
  35. const std::string serviceCode = std::string(),
  36. int durationSeconds = 3600);
  37. EndpointProvider(
  38. const Credentials &credentials,
  39. const ClientConfiguration &configuration,
  40. const std::string &regionId,
  41. const std::string &product,
  42. const std::string &serviceCode = std::string(),
  43. int durationSeconds = 3600);
  44. ~EndpointProvider();
  45. EndpointOutcome getEndpoint();
  46. using LocationClient::describeEndpoints;
  47. private:
  48. EndpointOutcome loadRemoteEndpoint();
  49. bool checkExpiry()const;
  50. bool loadLocalProductsInfo();
  51. std::string localEndpoint(const std::string regionId,
  52. const std::string product);
  53. std::mutex cachedMutex_;
  54. std::string cachedEndpoint_;
  55. int durationSeconds_;
  56. std::chrono::system_clock::time_point expiry_;
  57. std::string regionId_;
  58. std::string product_;
  59. std::string serviceCode_;
  60. };
  61. } // namespace AlibabaCloud
  62. #endif // CORE_INCLUDE_ALIBABACLOUD_CORE_ENDPOINTPROVIDER_H_