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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
open! Awso_common.Jane_compat
open Values
type ('i, 'o, 'e) t =
| AssumeRole: (AssumeRoleRequest.t, AssumeRoleResponse.t,
AssumeRoleResponse.error) t
| AssumeRoleWithSAML: (AssumeRoleWithSAMLRequest.t,
AssumeRoleWithSAMLResponse.t, AssumeRoleWithSAMLResponse.error) t
| AssumeRoleWithWebIdentity: (AssumeRoleWithWebIdentityRequest.t,
AssumeRoleWithWebIdentityResponse.t,
AssumeRoleWithWebIdentityResponse.error) t
| AssumeRoot: (AssumeRootRequest.t, AssumeRootResponse.t,
AssumeRootResponse.error) t
| DecodeAuthorizationMessage: (DecodeAuthorizationMessageRequest.t,
DecodeAuthorizationMessageResponse.t,
DecodeAuthorizationMessageResponse.error) t
| GetAccessKeyInfo: (GetAccessKeyInfoRequest.t, GetAccessKeyInfoResponse.t,
GetAccessKeyInfoResponse.error) t
| GetCallerIdentity: (GetCallerIdentityRequest.t,
GetCallerIdentityResponse.t, GetCallerIdentityResponse.error) t
| GetDelegatedAccessToken: (GetDelegatedAccessTokenRequest.t,
GetDelegatedAccessTokenResponse.t, GetDelegatedAccessTokenResponse.error) t
| GetFederationToken: (GetFederationTokenRequest.t,
GetFederationTokenResponse.t, GetFederationTokenResponse.error) t
| GetSessionToken: (GetSessionTokenRequest.t, GetSessionTokenResponse.t,
GetSessionTokenResponse.error) t
| GetWebIdentityToken: (GetWebIdentityTokenRequest.t,
GetWebIdentityTokenResponse.t, GetWebIdentityTokenResponse.error) t
let method_of_endpoint : type i o e. (i, o, e) t -> _ =
function
| AssumeRole -> `POST
| AssumeRoleWithSAML -> `POST
| AssumeRoleWithWebIdentity -> `POST
| AssumeRoot -> `POST
| DecodeAuthorizationMessage -> `POST
| GetAccessKeyInfo -> `POST
| GetCallerIdentity -> `POST
| GetDelegatedAccessToken -> `POST
| GetFederationToken -> `POST
| GetSessionToken -> `POST
| GetWebIdentityToken -> `POST
let uri_of_endpoint : type i o e. (i, o, e) t -> i -> Uri.t =
((fun endpoint x ->
match endpoint with
| AssumeRole -> (Format.kasprintf Uri.of_string) "/"
| AssumeRoleWithSAML -> (Format.kasprintf Uri.of_string) "/"
| AssumeRoleWithWebIdentity -> (Format.kasprintf Uri.of_string) "/"
| AssumeRoot -> (Format.kasprintf Uri.of_string) "/"
| DecodeAuthorizationMessage -> (Format.kasprintf Uri.of_string) "/"
| GetAccessKeyInfo -> (Format.kasprintf Uri.of_string) "/"
| GetCallerIdentity -> (Format.kasprintf Uri.of_string) "/"
| GetDelegatedAccessToken -> (Format.kasprintf Uri.of_string) "/"
| GetFederationToken -> (Format.kasprintf Uri.of_string) "/"
| GetSessionToken -> (Format.kasprintf Uri.of_string) "/"
| GetWebIdentityToken -> (Format.kasprintf Uri.of_string) "/")
[@ocaml.warning "-27"])
let to_request (type i) (type o) (type e) (endp : (i, o, e) t) (req : i) =
let _req = req in
match endp with
| AssumeRole ->
let =
Awso.Http.Headers.of_list
[("content-type",
"application/x-www-form-urlencoded; charset=utf-8")] in
let body =
let meta = [("Action", ["AssumeRole"]); ("Version", [apiVersion])] in
let query =
(AssumeRoleRequest.to_query req) |> Awso.Client.Query.render in
Some (Uri.encoded_of_query (meta @ query)) in
Awso.Http.Request.make ?body ~headers (method_of_endpoint endp)
| AssumeRoleWithSAML ->
let =
Awso.Http.Headers.of_list
[("content-type",
"application/x-www-form-urlencoded; charset=utf-8")] in
let body =
let meta =
[("Action", ["AssumeRoleWithSAML"]); ("Version", [apiVersion])] in
let query =
(AssumeRoleWithSAMLRequest.to_query req) |>
Awso.Client.Query.render in
Some (Uri.encoded_of_query (meta @ query)) in
Awso.Http.Request.make ?body ~headers (method_of_endpoint endp)
| AssumeRoleWithWebIdentity ->
let =
Awso.Http.Headers.of_list
[("content-type",
"application/x-www-form-urlencoded; charset=utf-8")] in
let body =
let meta =
[("Action", ["AssumeRoleWithWebIdentity"]);
("Version", [apiVersion])] in
let query =
(AssumeRoleWithWebIdentityRequest.to_query req) |>
Awso.Client.Query.render in
Some (Uri.encoded_of_query (meta @ query)) in
Awso.Http.Request.make ?body ~headers (method_of_endpoint endp)
| AssumeRoot ->
let =
Awso.Http.Headers.of_list
[("content-type",
"application/x-www-form-urlencoded; charset=utf-8")] in
let body =
let meta = [("Action", ["AssumeRoot"]); ("Version", [apiVersion])] in
let query =
(AssumeRootRequest.to_query req) |> Awso.Client.Query.render in
Some (Uri.encoded_of_query (meta @ query)) in
Awso.Http.Request.make ?body ~headers (method_of_endpoint endp)
| DecodeAuthorizationMessage ->
let =
Awso.Http.Headers.of_list
[("content-type",
"application/x-www-form-urlencoded; charset=utf-8")] in
let body =
let meta =
[("Action", ["DecodeAuthorizationMessage"]);
("Version", [apiVersion])] in
let query =
(DecodeAuthorizationMessageRequest.to_query req) |>
Awso.Client.Query.render in
Some (Uri.encoded_of_query (meta @ query)) in
Awso.Http.Request.make ?body ~headers (method_of_endpoint endp)
| GetAccessKeyInfo ->
let =
Awso.Http.Headers.of_list
[("content-type",
"application/x-www-form-urlencoded; charset=utf-8")] in
let body =
let meta =
[("Action", ["GetAccessKeyInfo"]); ("Version", [apiVersion])] in
let query =
(GetAccessKeyInfoRequest.to_query req) |> Awso.Client.Query.render in
Some (Uri.encoded_of_query (meta @ query)) in
Awso.Http.Request.make ?body ~headers (method_of_endpoint endp)
| GetCallerIdentity ->
let =
Awso.Http.Headers.of_list
[("content-type",
"application/x-www-form-urlencoded; charset=utf-8")] in
let body =
let meta =
[("Action", ["GetCallerIdentity"]); ("Version", [apiVersion])] in
let query =
(GetCallerIdentityRequest.to_query req) |> Awso.Client.Query.render in
Some (Uri.encoded_of_query (meta @ query)) in
Awso.Http.Request.make ?body ~headers (method_of_endpoint endp)
| GetDelegatedAccessToken ->
let =
Awso.Http.Headers.of_list
[("content-type",
"application/x-www-form-urlencoded; charset=utf-8")] in
let body =
let meta =
[("Action", ["GetDelegatedAccessToken"]);
("Version", [apiVersion])] in
let query =
(GetDelegatedAccessTokenRequest.to_query req) |>
Awso.Client.Query.render in
Some (Uri.encoded_of_query (meta @ query)) in
Awso.Http.Request.make ?body ~headers (method_of_endpoint endp)
| GetFederationToken ->
let =
Awso.Http.Headers.of_list
[("content-type",
"application/x-www-form-urlencoded; charset=utf-8")] in
let body =
let meta =
[("Action", ["GetFederationToken"]); ("Version", [apiVersion])] in
let query =
(GetFederationTokenRequest.to_query req) |>
Awso.Client.Query.render in
Some (Uri.encoded_of_query (meta @ query)) in
Awso.Http.Request.make ?body ~headers (method_of_endpoint endp)
| GetSessionToken ->
let =
Awso.Http.Headers.of_list
[("content-type",
"application/x-www-form-urlencoded; charset=utf-8")] in
let body =
let meta =
[("Action", ["GetSessionToken"]); ("Version", [apiVersion])] in
let query =
(GetSessionTokenRequest.to_query req) |> Awso.Client.Query.render in
Some (Uri.encoded_of_query (meta @ query)) in
Awso.Http.Request.make ?body ~headers (method_of_endpoint endp)
| GetWebIdentityToken ->
let =
Awso.Http.Headers.of_list
[("content-type",
"application/x-www-form-urlencoded; charset=utf-8")] in
let body =
let meta =
[("Action", ["GetWebIdentityToken"]); ("Version", [apiVersion])] in
let query =
(GetWebIdentityTokenRequest.to_query req) |>
Awso.Client.Query.render in
Some (Uri.encoded_of_query (meta @ query)) in
Awso.Http.Request.make ?body ~headers (method_of_endpoint endp)
let of_response (type i) (type o) (type e) (endpoint : (i, o, e) t)
(resp : Awso.Http.Response.t) : (o, e) result=
let code = Awso.Http.Status.to_code (Awso.Http.Response.status resp) in
let is_success = (code >= 200) && (code < 300) in
let parse_aws_error error_of_xml =
let body = Awso.Http.Response.body resp in
let bail () =
raise
(Awso.Http.Io.Error.Bad_response
{ Awso.Http.Io.Error.code = code; body; x_amzn_error_type = None }) in
match (error_of_xml, ((code >= 400) && (code <= 599))) with
| (None, _) | (_, false) -> bail ()
| (Some error_of_xml, true) ->
(match Awso.Xml.parse_response body with
| `Data _ -> bail ()
| `El (((_, "ErrorResponse"), _), _) as error_response_xml ->
let error_xml = Awso.Xml.child_exn error_response_xml "Error" in
(try
let error_code =
match Awso.Xml.child_exn error_xml "Code" with
| `Data error_code -> error_code
| `El (_, children) ->
(List.map children
~f:(function | `Data s -> s | `El _ -> ""))
|> (String.concat ~sep:"") in
error_of_xml (String.strip error_code) error_xml
with | Failure _ -> bail ())
| `El _ -> bail ()) in
let _ = parse_aws_error in
let _ = resp in
match endpoint with
| AssumeRole ->
if is_success
then
let xml = Awso.Xml.parse_response (Awso.Http.Response.body resp) in
Ok (AssumeRoleResponse.of_xml xml)
else Error (parse_aws_error (Some AssumeRoleResponse.error_of_xml))
| AssumeRoleWithSAML ->
if is_success
then
let xml = Awso.Xml.parse_response (Awso.Http.Response.body resp) in
Ok (AssumeRoleWithSAMLResponse.of_xml xml)
else
Error
(parse_aws_error (Some AssumeRoleWithSAMLResponse.error_of_xml))
| AssumeRoleWithWebIdentity ->
if is_success
then
let xml = Awso.Xml.parse_response (Awso.Http.Response.body resp) in
Ok (AssumeRoleWithWebIdentityResponse.of_xml xml)
else
Error
(parse_aws_error
(Some AssumeRoleWithWebIdentityResponse.error_of_xml))
| AssumeRoot ->
if is_success
then
let xml = Awso.Xml.parse_response (Awso.Http.Response.body resp) in
Ok (AssumeRootResponse.of_xml xml)
else Error (parse_aws_error (Some AssumeRootResponse.error_of_xml))
| DecodeAuthorizationMessage ->
if is_success
then
let xml = Awso.Xml.parse_response (Awso.Http.Response.body resp) in
Ok (DecodeAuthorizationMessageResponse.of_xml xml)
else
Error
(parse_aws_error
(Some DecodeAuthorizationMessageResponse.error_of_xml))
| GetAccessKeyInfo ->
if is_success
then
let xml = Awso.Xml.parse_response (Awso.Http.Response.body resp) in
Ok (GetAccessKeyInfoResponse.of_xml xml)
else Error (parse_aws_error None)
| GetCallerIdentity ->
if is_success
then
let xml = Awso.Xml.parse_response (Awso.Http.Response.body resp) in
Ok (GetCallerIdentityResponse.of_xml xml)
else Error (parse_aws_error None)
| GetDelegatedAccessToken ->
if is_success
then
let xml = Awso.Xml.parse_response (Awso.Http.Response.body resp) in
Ok (GetDelegatedAccessTokenResponse.of_xml xml)
else
Error
(parse_aws_error
(Some GetDelegatedAccessTokenResponse.error_of_xml))
| GetFederationToken ->
if is_success
then
let xml = Awso.Xml.parse_response (Awso.Http.Response.body resp) in
Ok (GetFederationTokenResponse.of_xml xml)
else
Error
(parse_aws_error (Some GetFederationTokenResponse.error_of_xml))
| GetSessionToken ->
if is_success
then
let xml = Awso.Xml.parse_response (Awso.Http.Response.body resp) in
Ok (GetSessionTokenResponse.of_xml xml)
else
Error (parse_aws_error (Some GetSessionTokenResponse.error_of_xml))
| GetWebIdentityToken ->
if is_success
then
let xml = Awso.Xml.parse_response (Awso.Http.Response.body resp) in
Ok (GetWebIdentityTokenResponse.of_xml xml)
else
Error
(parse_aws_error (Some GetWebIdentityTokenResponse.error_of_xml))