AWSCredentialBus.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 <AzCore/EBus/EBus.h>
  10. namespace Aws
  11. {
  12. namespace Auth
  13. {
  14. class AWSCredentialsProvider;
  15. }
  16. } // namespace Aws
  17. namespace AWSCore
  18. {
  19. enum CredentialHandlerOrder
  20. {
  21. CVAR_CREDENTIAL_HANDLER = 0,
  22. COGNITO_IDENITY_POOL_CREDENTIAL_HANDLER = 20,
  23. DEFAULT_CREDENTIAL_HANDLER = 30,
  24. };
  25. //! Aggregates credentials provider results returned by all handlers
  26. //! which takes the first valid credential provider following the order
  27. struct AWSCredentialResult
  28. {
  29. std::shared_ptr<Aws::Auth::AWSCredentialsProvider> result;
  30. AWSCredentialResult() : result(nullptr){}
  31. //! Overloads the assignment operator to aggregate a new value with
  32. //! the existing aggregated value using rvalue
  33. void operator=(std::shared_ptr<Aws::Auth::AWSCredentialsProvider>&& rhs)
  34. {
  35. if (!result)
  36. {
  37. result = AZStd::move(rhs);
  38. }
  39. }
  40. };
  41. //! AWSCredential request interface
  42. class AWSCredentialRequests : public AZ::EBusTraits
  43. {
  44. public:
  45. // Allow multiple threads to concurrently make requests
  46. using MutexType = AZStd::recursive_mutex;
  47. //////////////////////////////////////////////////////////////////////////
  48. // EBusTraits overrides
  49. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::MultipleAndOrdered;
  50. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
  51. //////////////////////////////////////////////////////////////////////////
  52. //! Determines the order in which handlers get credentials provider.
  53. struct BusHandlerOrderCompare
  54. {
  55. AZ_FORCE_INLINE bool operator()(AWSCredentialRequests* left, AWSCredentialRequests* right) const
  56. {
  57. return left->GetCredentialHandlerOrder() < right->GetCredentialHandlerOrder();
  58. }
  59. };
  60. //! GetCredentialHandlerOrder
  61. //! Get the order of credential handler
  62. //! @return The value of credential handler order
  63. virtual int GetCredentialHandlerOrder() const = 0;
  64. //! GetCredentialsProvider
  65. //! Get credential provider to supply required AWS credential for making requests
  66. //! to Amazon Web Services
  67. //! @return The credential provider
  68. virtual std::shared_ptr<Aws::Auth::AWSCredentialsProvider> GetCredentialsProvider() = 0;
  69. };
  70. using AWSCredentialRequestBus = AZ::EBus<AWSCredentialRequests>;
  71. } // namespace AWSCore