aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSUrlPresigner.cpp
blob: a0bc80883844e2183698740b13ec127d0feb3254 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/core/client/AWSUrlPresigner.h>
#include <aws/core/client/AWSClient.h>
#include <aws/core/http/HttpClientFactory.h>

namespace Aws
{
namespace Client
{

using HttpRequest = Http::HttpRequest;
using HttpMethod = Http::HttpMethod;
using URI = Http::URI;


AWSUrlPresigner::AWSUrlPresigner(const AWSClient& client)
    : m_awsClient(client)
{}


Aws::Client::AWSAuthSigner* AWSUrlPresigner::GetSignerByName(const char* name) const
{
    return m_awsClient.GetSignerByName(name);
}

std::shared_ptr<Aws::Http::HttpRequest>
ConvertToRequestForPresigning(const Aws::AmazonWebServiceRequest& request,
                              const Aws::Http::URI& uri,
                              Aws::Http::HttpMethod method,
                              const Aws::Http::QueryStringParameterCollection& extraParams)
{
    Aws::Http::URI uriCopy = uri;
    request.PutToPresignedUrl(uriCopy);
    std::shared_ptr<HttpRequest> httpRequest = CreateHttpRequest(uriCopy, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);

    for (auto& param : extraParams)
    {
        httpRequest->AddQueryStringParameter(param.first.c_str(), param.second);
    }

    return httpRequest;
}

Aws::String AWSUrlPresigner::GeneratePresignedUrl(const URI& uri,
                                                  HttpMethod method,
                                                  long long expirationInSeconds) const
{
    const char* regionOverride = nullptr;
    const char* serviceNameOverride = nullptr;
    const char* signerName = Aws::Auth::SIGV4_SIGNER;
    return GeneratePresignedUrl(uri, method, regionOverride, serviceNameOverride, signerName, expirationInSeconds);
}

Aws::String AWSUrlPresigner::GeneratePresignedUrl(const URI& uri,
                                                  HttpMethod method,
                                                  const Aws::Http::HeaderValueCollection& customizedHeaders,
                                                  long long expirationInSeconds) const
{
    const char* regionOverride = nullptr;
    const char* serviceNameOverride = nullptr;
    const char* signerName = Aws::Auth::SIGV4_SIGNER;
    return GeneratePresignedUrl(uri, method, regionOverride, serviceNameOverride, signerName, customizedHeaders, expirationInSeconds);
}

Aws::String AWSUrlPresigner::GeneratePresignedUrl(const URI& uri,
                                                  HttpMethod method,
                                                  const char* regionOverride,
                                                  long long expirationInSeconds) const
{
    const char* serviceNameOverride = nullptr;
    const char* signerName = Aws::Auth::SIGV4_SIGNER;
    return GeneratePresignedUrl(uri, method, regionOverride, serviceNameOverride, signerName, expirationInSeconds);
}

Aws::String AWSUrlPresigner::GeneratePresignedUrl(const URI& uri,
                                                  HttpMethod method,
                                                  const char* regionOverride,
                                                  const Aws::Http::HeaderValueCollection& customizedHeaders,
                                                  long long expirationInSeconds) const
{
    const char* serviceNameOverride = nullptr;
    const char* signerName = Aws::Auth::SIGV4_SIGNER;
    return GeneratePresignedUrl(uri, method, regionOverride, serviceNameOverride, signerName, customizedHeaders, expirationInSeconds);
}

Aws::String AWSUrlPresigner::GeneratePresignedUrl(const Aws::Http::URI& uri,
                                                  Aws::Http::HttpMethod method,
                                                  const char* regionOverride,
                                                  const char* serviceNameOverride,
                                                  long long expirationInSeconds) const
{
    const char* signerName = Aws::Auth::SIGV4_SIGNER;
    return GeneratePresignedUrl(uri, method, regionOverride, serviceNameOverride, signerName, expirationInSeconds);
}

Aws::String AWSUrlPresigner::GeneratePresignedUrl(const Aws::Http::URI& uri,
                                                  Aws::Http::HttpMethod method,
                                                  const char* regionOverride,
                                                  const char* serviceNameOverride,
                                                  const Aws::Http::HeaderValueCollection& customizedHeaders,
                                                  long long expirationInSeconds) const
{
    const char* signerName = Aws::Auth::SIGV4_SIGNER;
    return GeneratePresignedUrl(uri, method, regionOverride, serviceNameOverride, signerName, customizedHeaders, expirationInSeconds);
}

Aws::String AWSUrlPresigner::GeneratePresignedUrl(const Aws::Http::URI& uri,
                                                  Aws::Http::HttpMethod method,
                                                  const char* regionOverride,
                                                  const char* serviceNameOverride,
                                                  const char* signerName,
                                                  long long expirationInSeconds) const
{
    const Aws::Http::HeaderValueCollection& customizedHeaders = {};
    return GeneratePresignedUrl(uri, method, regionOverride, serviceNameOverride, signerName, customizedHeaders, expirationInSeconds);
}

Aws::String AWSUrlPresigner::GeneratePresignedUrl(const Aws::Http::URI& uri,
                                                  Aws::Http::HttpMethod method,
                                                  const char* region,
                                                  const char* serviceName,
                                                  const char* signerName,
                                                  const Aws::Http::HeaderValueCollection& customizedHeaders,
                                                  long long expirationInSeconds) const
{
    /* a real method implementation */
    if (!signerName) {
        signerName = Aws::Auth::SIGV4_SIGNER;
    }
    std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);
    for (const auto& it: customizedHeaders)
    {
        request->SetHeaderValue(it.first.c_str(), it.second);
    }
    auto signer = GetSignerByName(signerName);
    if (signer->PresignRequest(*request, region, serviceName, expirationInSeconds))
    {
        return request->GetURIString();
    }

    return {};
}

Aws::String AWSUrlPresigner::GeneratePresignedUrl(const Aws::Endpoint::AWSEndpoint& endpoint,
                                                 Aws::Http::HttpMethod method /* = Http::HttpMethod::HTTP_POST */,
                                                 const Aws::Http::HeaderValueCollection& customizedHeaders /* = {} */,
                                                 uint64_t expirationInSeconds /* = 0 */,
                                                 const char* signerName /* = Aws::Auth::SIGV4_SIGNER */,
                                                 const char* signerRegionOverride /* = nullptr */,
                                                 const char* signerServiceNameOverride /* = nullptr */) const
{
    const Aws::Http::URI& uri = endpoint.GetURI();
    if (endpoint.GetAttributes()) {
        signerName = endpoint.GetAttributes()->authScheme.GetName().c_str();
        if (endpoint.GetAttributes()->authScheme.GetSigningRegion()) {
            signerRegionOverride = endpoint.GetAttributes()->authScheme.GetSigningRegion()->c_str();
        }
        if (endpoint.GetAttributes()->authScheme.GetSigningRegionSet()) {
            signerRegionOverride = endpoint.GetAttributes()->authScheme.GetSigningRegionSet()->c_str();
        }
        if (endpoint.GetAttributes()->authScheme.GetSigningName()) {
            signerServiceNameOverride = endpoint.GetAttributes()->authScheme.GetSigningName()->c_str();
        }
    }

    return GeneratePresignedUrl(uri, method, signerRegionOverride, signerServiceNameOverride, signerName, customizedHeaders, expirationInSeconds);
}

Aws::String AWSUrlPresigner::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request,
                                                  const Aws::Http::URI& uri,
                                                  Aws::Http::HttpMethod method,
                                                  const char* regionOverride,
                                                  const Aws::Http::QueryStringParameterCollection& extraParams,
                                                  long long expirationInSeconds) const
{
    const char* serviceNameOverride = nullptr;
    const char* signerName = Aws::Auth::SIGV4_SIGNER;

    return GeneratePresignedUrl(request, uri, method, regionOverride, serviceNameOverride, signerName, extraParams, expirationInSeconds);
}

Aws::String AWSUrlPresigner::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request,
                                                  const Aws::Http::URI& uri,
                                                  Aws::Http::HttpMethod method,
                                                  const char* regionOverride,
                                                  const char* serviceNameOverride,
                                                  const char* signerName,
                                                  const Aws::Http::QueryStringParameterCollection& extraParams,
                                                  long long expirationInSeconds) const
{
    /* a real method implementation */
    if (!signerName) {
        signerName = Aws::Auth::SIGV4_SIGNER;
    }
    std::shared_ptr<HttpRequest> httpRequest =
            ConvertToRequestForPresigning(request, uri, method, extraParams);
    auto signer = GetSignerByName(signerName);
    if (signer->PresignRequest(*httpRequest, regionOverride, serviceNameOverride, expirationInSeconds))
    {
        return httpRequest->GetURIString();
    }

    return {};
}

Aws::String AWSUrlPresigner::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request,
                                                  const Aws::Http::URI& uri,
                                                  Aws::Http::HttpMethod method,
                                                  const char* regionOverride,
                                                  const char* serviceNameOverride,
                                                  const Aws::Http::QueryStringParameterCollection& extraParams,
                                                  long long expirationInSeconds) const
{
    const char* signerName = Aws::Auth::SIGV4_SIGNER;
    return GeneratePresignedUrl(request, uri, method, regionOverride, serviceNameOverride, signerName, extraParams, expirationInSeconds);
}

Aws::String AWSUrlPresigner::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request,
                                                  const Aws::Http::URI& uri,
                                                  Aws::Http::HttpMethod method,
                                                  const Aws::Http::QueryStringParameterCollection& extraParams,
                                                  long long expirationInSeconds) const
{
    const char* regionOverride = nullptr;
    const char* serviceNameOverride = nullptr;
    const char* signerName = Aws::Auth::SIGV4_SIGNER;

    return GeneratePresignedUrl(request, uri, method, regionOverride, serviceNameOverride, signerName, extraParams, expirationInSeconds);
}

} // namespace Client
} // namespace Aws