ServiceRequestJobConfig.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <Framework/ServiceClientJobConfig.h>
  10. namespace AWSCore
  11. {
  12. class IServiceRequestJobConfig
  13. : public virtual IServiceClientJobConfig
  14. {
  15. public:
  16. virtual const Aws::String& GetRequestUrl() = 0;
  17. virtual std::shared_ptr<Aws::Auth::AWSCredentialsProvider> GetCredentialsProvider() = 0;
  18. virtual bool IsValid() const = 0;
  19. };
  20. // warning C4250: 'AWSCore::ServiceRequestJobConfig<RequestType>' : inherits 'AWSCore::AwsApiJobConfig::AWSCore::AwsApiJobConfig::GetJobContext' via dominance
  21. // Thanks to http://stackoverflow.com/questions/11965596/diamond-inheritance-scenario-compiles-fine-in-g-but-produces-warnings-errors for the explanation
  22. // This is the expected and desired behavior. The warning is superfluous.
  23. AZ_PUSH_DISABLE_WARNING(4250, "-Wunknown-warning-option")
  24. template<class RequestType>
  25. class ServiceRequestJobConfig
  26. : public ServiceClientJobConfig<typename RequestType::ServiceTraits>
  27. , public virtual IServiceRequestJobConfig
  28. {
  29. public:
  30. AZ_CLASS_ALLOCATOR(ServiceRequestJobConfig, AZ::SystemAllocator);
  31. using InitializerFunction = AZStd::function<void(ServiceClientJobConfig<typename RequestType::ServiceTraits>& config)>;
  32. using ServiceClientJobConfigType = ServiceClientJobConfig<typename RequestType::ServiceTraits>;
  33. /// Initialize an ServiceRequestJobConfig object.
  34. ///
  35. /// \param defaultConfig - the config object that provides values when
  36. /// no override has been set in this object. The default is nullptr, which
  37. /// will cause a default value to be used.
  38. ///
  39. /// \param initializer - a function called to initialize this object.
  40. /// This simplifies the initialization of static instances. The default
  41. /// value is nullptr, in which case no initializer will be called.
  42. ServiceRequestJobConfig(AwsApiJobConfig* defaultConfig = nullptr, InitializerFunction initializer = nullptr)
  43. : ServiceClientJobConfigType{ defaultConfig }
  44. {
  45. if (initializer)
  46. {
  47. initializer(*this);
  48. }
  49. }
  50. const Aws::String& GetRequestUrl() override
  51. {
  52. ServiceClientJobConfigType::EnsureSettingsApplied();
  53. return m_requestUrl;
  54. }
  55. bool IsValid() const override
  56. {
  57. // If we failed to get mappings we'll have no URL and should not try to make a request
  58. return (m_requestUrl.length() > 0);
  59. }
  60. std::shared_ptr<Aws::Auth::AWSCredentialsProvider> GetCredentialsProvider() override
  61. {
  62. ServiceClientJobConfigType::EnsureSettingsApplied();
  63. return m_credentialsProvider;
  64. }
  65. void ApplySettings() override
  66. {
  67. ServiceClientJobConfigType::ApplySettings();
  68. m_requestUrl = GetServiceUrl().c_str();
  69. if (m_requestUrl.length())
  70. {
  71. m_requestUrl += RequestType::Path();
  72. }
  73. m_credentialsProvider = AwsApiJobConfig::GetCredentialsProvider();
  74. }
  75. private:
  76. Aws::String m_requestUrl;
  77. std::shared_ptr<Aws::Auth::AWSCredentialsProvider> m_credentialsProvider;
  78. };
  79. AZ_POP_DISABLE_WARNING
  80. } // namespace AWSCore