EndpointProvider.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 ALIBABACLOUD_CORE_ENDPOINTPROVIDER_H_
  17. #define ALIBABACLOUD_CORE_ENDPOINTPROVIDER_H_
  18. #include <string>
  19. #include <chrono>
  20. #include <list>
  21. #include <map>
  22. #include <mutex>
  23. #include <alibabacloud/core/location/LocationClient.h>
  24. #include <alibabacloud/core/CoreClient.h>
  25. namespace AlibabaCloud
  26. {
  27. class ALIBABACLOUD_CORE_EXPORT EndpointProvider : public Location::LocationClient
  28. {
  29. public:
  30. typedef Outcome<Error, std::string> EndpointOutcome;
  31. EndpointProvider(const std::shared_ptr<Location::LocationClient>& locationClient,
  32. const std::string regionId,
  33. const std::string product,
  34. const std::string serviceCode = std::string(),
  35. int durationSeconds = 3600);
  36. EndpointProvider(
  37. const Credentials &credentials,
  38. const ClientConfiguration &configuration,
  39. const std::string &regionId,
  40. const std::string &product,
  41. const std::string &serviceCode = std::string(),
  42. int durationSeconds = 3600);
  43. ~EndpointProvider();
  44. EndpointOutcome getEndpoint();
  45. using LocationClient::describeEndpoints;
  46. private:
  47. struct Product
  48. {
  49. std::string code;
  50. std::string locationServiceCode;
  51. std::string documentId;
  52. std::map<std::string, std::string> regionalEndpoints;
  53. std::string globalEndpoint;
  54. std::string regionalEndpointPattern;
  55. };
  56. EndpointOutcome loadRemoteEndpoint();
  57. bool checkExpiry()const;
  58. bool loadInternalProductsInfo();
  59. std::string internalEndpoint(const std::string regionId, const std::string product);
  60. std::mutex cachedMutex_;
  61. std::string cachedEndpoint_;
  62. int durationSeconds_;
  63. std::chrono::system_clock::time_point expiry_;
  64. std::string regionId_;
  65. std::string product_;
  66. std::string serviceCode_;
  67. std::list<Product> internalProductsInfo_;
  68. };
  69. }
  70. #endif