AWSScriptBehaviorS3.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #include <AzCore/std/string/string.h>
  11. namespace AWSCore
  12. {
  13. //! AWS Script Behavior notifications for ScriptCanvas behaviors that interact with AWS S3
  14. class AWSScriptBehaviorS3Notifications
  15. : public AZ::EBusTraits
  16. {
  17. public:
  18. ///////////////////////////////////////////////////////////////////////////////////
  19. // EBusTraits overrides
  20. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
  21. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
  22. //! Called when a successful script behavior s3 head object call has occurred
  23. virtual void OnHeadObjectSuccess(const AZStd::string& resultBody) = 0;
  24. //! Called when script behavior s3 head object call has failed
  25. virtual void OnHeadObjectError(const AZStd::string& errorBody) = 0;
  26. //! Called when a successful script behavior s3 get object call has occurred
  27. virtual void OnGetObjectSuccess(const AZStd::string& resultBody) = 0;
  28. //! Called when script behavior s3 get object call has failed
  29. virtual void OnGetObjectError(const AZStd::string& errorBody) = 0;
  30. };
  31. using AWSScriptBehaviorS3NotificationBus = AZ::EBus<AWSScriptBehaviorS3Notifications>;
  32. class AWSScriptBehaviorS3NotificationBusHandler
  33. : public AWSScriptBehaviorS3NotificationBus::Handler
  34. , public AZ::BehaviorEBusHandler
  35. {
  36. public:
  37. AZ_EBUS_BEHAVIOR_BINDER(AWSScriptBehaviorS3NotificationBusHandler, "{CB7E8710-F256-48A6-BC03-D3E3001AEB1E}",
  38. AZ::SystemAllocator, OnHeadObjectSuccess, OnHeadObjectError, OnGetObjectSuccess, OnGetObjectError);
  39. void OnHeadObjectSuccess(const AZStd::string& resultBody) override
  40. {
  41. Call(FN_OnHeadObjectSuccess, resultBody);
  42. }
  43. void OnHeadObjectError(const AZStd::string& errorBody) override
  44. {
  45. Call(FN_OnHeadObjectError, errorBody);
  46. }
  47. void OnGetObjectSuccess(const AZStd::string& resultBody) override
  48. {
  49. Call(FN_OnGetObjectSuccess, resultBody);
  50. }
  51. void OnGetObjectError(const AZStd::string& errorBody) override
  52. {
  53. Call(FN_OnGetObjectError, errorBody);
  54. }
  55. };
  56. class AWSScriptBehaviorS3
  57. {
  58. static constexpr const char AWSScriptBehaviorS3Name[] = "AWSScriptBehaviorS3";
  59. static constexpr const char OutputFileIsEmptyErrorMessage[] = "Request validation failed, output file is empty.";
  60. static constexpr const char OutputFileFailedToResolveErrorMessage[] = "Request validation failed, cannot resolve the output file path.";
  61. static constexpr const char OutputFileIsDirectoryErrorMessage[] = "Request validation failed, output file is a directory.";
  62. static constexpr const char OutputFileDirectoryNotExistErrorMessage[] = "Request validation failed, output file directory doesn't exist.";
  63. static constexpr const char OutputFileIsReadOnlyErrorMessage[] = "Request validation failed, output file is read-only.";
  64. static constexpr const char BucketNameIsEmptyErrorMessage[] = "Request validation failed, bucket name is empty";
  65. static constexpr const char ObjectKeyNameIsEmptyErrorMessage[] = "Request validation failed, object key name is empty.";
  66. static constexpr const char RegionNameIsEmptyErrorMessage[] = "Request validation failed, region name is empty.";
  67. public:
  68. AZ_RTTI(AWSScriptBehaviorS3, "{7F4E956C-7463-4236-B320-C992D36A9C6E}");
  69. AWSScriptBehaviorS3() = default;
  70. virtual ~AWSScriptBehaviorS3() = default;
  71. static void Reflect(AZ::ReflectContext* context);
  72. static void GetObject(const AZStd::string& bucketResourceKey, const AZStd::string& objectKey, const AZStd::string& outFile);
  73. static void GetObjectRaw(const AZStd::string& bucket, const AZStd::string& objectKey, const AZStd::string& region, const AZStd::string& outFile);
  74. static void HeadObject(const AZStd::string& bucketResourceKey, const AZStd::string& objectKey);
  75. static void HeadObjectRaw(const AZStd::string& bucket, const AZStd::string& objectKey, const AZStd::string& region);
  76. private:
  77. using S3NotificationFunctionType = void(AWSScriptBehaviorS3Notifications::*)(const AZStd::string&);
  78. static bool ValidateGetObjectRequest(S3NotificationFunctionType notificationFunc,
  79. const AZStd::string& bucket, const AZStd::string& objectKey, const AZStd::string& region, AZStd::string& outFile);
  80. static bool ValidateHeadObjectRequest(S3NotificationFunctionType notificationFunc,
  81. const AZStd::string& bucket, const AZStd::string& key, const AZStd::string& region);
  82. };
  83. }