1
#pragma once
2

            
3
#include "envoy/common/pure.h"
4
#include "envoy/http/message.h"
5

            
6
#include "source/extensions/common/aws/credentials_provider.h"
7

            
8
namespace Envoy {
9
namespace Extensions {
10
namespace Common {
11
namespace Aws {
12

            
13
class Signer {
14
public:
15
530
  virtual ~Signer() = default;
16

            
17
  /**
18
   * Sign an AWS request.
19
   * @param message an AWS API request message.
20
   * @param sign_body include the message body in the signature. The body must be fully buffered.
21
   * @param override_region override the default region that has to be used to sign the request
22
   * @return absl::Status::OK if the request was signed successfully.
23
   * @return absl::NotFoundError if credentials are pending.
24
   */
25
  virtual absl::Status sign(Http::RequestMessage& message, bool sign_body,
26
                            const absl::string_view override_region = "") PURE;
27

            
28
  /**
29
   * Sign an AWS request without a payload (empty string used as content hash).
30
   * @param headers AWS API request headers.
31
   * @param override_region override the default region that has to be used to sign the request
32
   * @return absl::Status::OK if the request was signed successfully.
33
   * @return absl::NotFoundError if credentials are pending.
34
   */
35
  virtual absl::Status signEmptyPayload(Http::RequestHeaderMap& headers,
36
                                        const absl::string_view override_region = "") PURE;
37

            
38
  /**
39
   * Sign an AWS request using the literal string UNSIGNED-PAYLOAD in the canonical request.
40
   * @param headers AWS API request headers.
41
   * @param override_region override the default region that has to be used to sign the request
42
   * @return absl::Status::OK if the request was signed successfully.
43
   * @return absl::NotFoundError if credentials are pending.
44
   */
45
  virtual absl::Status signUnsignedPayload(Http::RequestHeaderMap& headers,
46
                                           const absl::string_view override_region = "") PURE;
47

            
48
  /**
49
   * Sign an AWS request.
50
   * @param headers AWS API request headers.
51
   * @param content_hash The Hex encoded SHA-256 of the body of the AWS API request.
52
   * @param override_region override the default region that has to be used to sign the request
53
   * @return absl::Status::OK if the request was signed successfully.
54
   * @return absl::NotFoundError if credentials are pending.
55
   */
56
  virtual absl::Status sign(Http::RequestHeaderMap& headers, const std::string& content_hash,
57
                            const absl::string_view override_region = "") PURE;
58

            
59
  /**
60
   * @param cb A callback that will be called when credentials (from async providers) are no longer
61
   * pending.
62
   * @return true if credentials are pending and the callback has been added to the queue.
63
   * @return false if credentials are not pending and it is safe to continue signing immediately.
64
   */
65
  virtual bool addCallbackIfCredentialsPending(CredentialsPendingCallback&& cb) PURE;
66
};
67

            
68
using SignerPtr = std::unique_ptr<Signer>;
69

            
70
} // namespace Aws
71
} // namespace Common
72
} // namespace Extensions
73
} // namespace Envoy