Source file endpoints.ml

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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
(* generated by: awso-codegen generate-all --botocore-data vendor/botocore/botocore/data -o aws --runtime-dir lib/runtime/awso --cli-dir awso-cli *)
open! Awso_common.Jane_compat
open Values
type ('i, 'o, 'e) t =
  | CreateBatchLoadTask: (CreateBatchLoadTaskRequest.t,
  CreateBatchLoadTaskResponse.t, CreateBatchLoadTaskResponse.error) t 
  | CreateDatabase: (CreateDatabaseRequest.t, CreateDatabaseResponse.t,
  CreateDatabaseResponse.error) t 
  | CreateTable: (CreateTableRequest.t, CreateTableResponse.t,
  CreateTableResponse.error) t 
  | DeleteDatabase: (DeleteDatabaseRequest.t, unit, unit) t 
  | DeleteTable: (DeleteTableRequest.t, unit, unit) t 
  | DescribeBatchLoadTask: (DescribeBatchLoadTaskRequest.t,
  DescribeBatchLoadTaskResponse.t, DescribeBatchLoadTaskResponse.error) t 
  | DescribeDatabase: (DescribeDatabaseRequest.t, DescribeDatabaseResponse.t,
  DescribeDatabaseResponse.error) t 
  | DescribeEndpoints: (DescribeEndpointsRequest.t,
  DescribeEndpointsResponse.t, DescribeEndpointsResponse.error) t 
  | DescribeTable: (DescribeTableRequest.t, DescribeTableResponse.t,
  DescribeTableResponse.error) t 
  | ListBatchLoadTasks: (ListBatchLoadTasksRequest.t,
  ListBatchLoadTasksResponse.t, ListBatchLoadTasksResponse.error) t 
  | ListDatabases: (ListDatabasesRequest.t, ListDatabasesResponse.t,
  ListDatabasesResponse.error) t 
  | ListTables: (ListTablesRequest.t, ListTablesResponse.t,
  ListTablesResponse.error) t 
  | ListTagsForResource: (ListTagsForResourceRequest.t,
  ListTagsForResourceResponse.t, ListTagsForResourceResponse.error) t 
  | ResumeBatchLoadTask: (ResumeBatchLoadTaskRequest.t,
  ResumeBatchLoadTaskResponse.t, ResumeBatchLoadTaskResponse.error) t 
  | TagResource: (TagResourceRequest.t, TagResourceResponse.t,
  TagResourceResponse.error) t 
  | UntagResource: (UntagResourceRequest.t, UntagResourceResponse.t,
  UntagResourceResponse.error) t 
  | UpdateDatabase: (UpdateDatabaseRequest.t, UpdateDatabaseResponse.t,
  UpdateDatabaseResponse.error) t 
  | UpdateTable: (UpdateTableRequest.t, UpdateTableResponse.t,
  UpdateTableResponse.error) t 
  | WriteRecords: (WriteRecordsRequest.t, WriteRecordsResponse.t,
  WriteRecordsResponse.error) t 
let method_of_endpoint : type i o e. (i, o, e) t -> _ =
  function
  | CreateBatchLoadTask -> `POST
  | CreateDatabase -> `POST
  | CreateTable -> `POST
  | DeleteDatabase -> `POST
  | DeleteTable -> `POST
  | DescribeBatchLoadTask -> `POST
  | DescribeDatabase -> `POST
  | DescribeEndpoints -> `POST
  | DescribeTable -> `POST
  | ListBatchLoadTasks -> `POST
  | ListDatabases -> `POST
  | ListTables -> `POST
  | ListTagsForResource -> `POST
  | ResumeBatchLoadTask -> `POST
  | TagResource -> `POST
  | UntagResource -> `POST
  | UpdateDatabase -> `POST
  | UpdateTable -> `POST
  | WriteRecords -> `POST
let uri_of_endpoint : type i o e. (i, o, e) t -> i -> Uri.t =
  ((fun endpoint x ->
      match endpoint with
      | CreateBatchLoadTask -> (Format.kasprintf Uri.of_string) "/"
      | CreateDatabase -> (Format.kasprintf Uri.of_string) "/"
      | CreateTable -> (Format.kasprintf Uri.of_string) "/"
      | DeleteDatabase -> (Format.kasprintf Uri.of_string) "/"
      | DeleteTable -> (Format.kasprintf Uri.of_string) "/"
      | DescribeBatchLoadTask -> (Format.kasprintf Uri.of_string) "/"
      | DescribeDatabase -> (Format.kasprintf Uri.of_string) "/"
      | DescribeEndpoints -> (Format.kasprintf Uri.of_string) "/"
      | DescribeTable -> (Format.kasprintf Uri.of_string) "/"
      | ListBatchLoadTasks -> (Format.kasprintf Uri.of_string) "/"
      | ListDatabases -> (Format.kasprintf Uri.of_string) "/"
      | ListTables -> (Format.kasprintf Uri.of_string) "/"
      | ListTagsForResource -> (Format.kasprintf Uri.of_string) "/"
      | ResumeBatchLoadTask -> (Format.kasprintf Uri.of_string) "/"
      | TagResource -> (Format.kasprintf Uri.of_string) "/"
      | UntagResource -> (Format.kasprintf Uri.of_string) "/"
      | UpdateDatabase -> (Format.kasprintf Uri.of_string) "/"
      | UpdateTable -> (Format.kasprintf Uri.of_string) "/"
      | WriteRecords -> (Format.kasprintf Uri.of_string) "/")
  [@ocaml.warning "-27"])
let to_request (type i) (type o) (type e) (endp : (i, o, e) t) (req : i) =
  match endp with
  | CreateBatchLoadTask ->
      let json = CreateBatchLoadTaskRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.CreateBatchLoadTask")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | CreateDatabase ->
      let json = CreateDatabaseRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.CreateDatabase")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | CreateTable ->
      let json = CreateTableRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.CreateTable")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | DeleteDatabase ->
      let json = DeleteDatabaseRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.DeleteDatabase")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | DeleteTable ->
      let json = DeleteTableRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.DeleteTable")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | DescribeBatchLoadTask ->
      let json = DescribeBatchLoadTaskRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.DescribeBatchLoadTask")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | DescribeDatabase ->
      let json = DescribeDatabaseRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.DescribeDatabase")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | DescribeEndpoints ->
      let json = DescribeEndpointsRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.DescribeEndpoints")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | DescribeTable ->
      let json = DescribeTableRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.DescribeTable")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | ListBatchLoadTasks ->
      let json = ListBatchLoadTasksRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.ListBatchLoadTasks")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | ListDatabases ->
      let json = ListDatabasesRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.ListDatabases")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | ListTables ->
      let json = ListTablesRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.ListTables")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | ListTagsForResource ->
      let json = ListTagsForResourceRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.ListTagsForResource")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | ResumeBatchLoadTask ->
      let json = ResumeBatchLoadTaskRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.ResumeBatchLoadTask")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | TagResource ->
      let json = TagResourceRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.TagResource")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | UntagResource ->
      let json = UntagResourceRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.UntagResource")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | UpdateDatabase ->
      let json = UpdateDatabaseRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.UpdateDatabase")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | UpdateTable ->
      let json = UpdateTableRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.UpdateTable")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | WriteRecords ->
      let json = WriteRecordsRequest.to_json req in
      let body = Yojson.Safe.to_string json in
      let headers =
        Awso.Http.Headers.of_list
          [("Content-Type", "application/x-amz-json-1.0");
          ("X-Amz-Target", "Timestream_20181101.WriteRecords")] 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_json =
    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_json, ((code >= 400) && (code <= 599))) with
    | (Some error_of_json, true) ->
        let json = Yojson.Safe.from_string body in
        (match json |> (Yojson.Safe.Util.member "__type") with
         | `String error_type -> error_of_json error_type json
         | `Null -> bail ()
         | _ ->
             failwith
               (sprintf "Error '__type' did not have string type: %s" body))
    | (None, _) | (_, false) -> bail () in
  let _ = parse_aws_error in
  let _ = resp in
  match endpoint with
  | CreateBatchLoadTask ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (CreateBatchLoadTaskResponse.of_json json)
      else
        Error
          (parse_aws_error (Some CreateBatchLoadTaskResponse.error_of_json))
  | CreateDatabase ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (CreateDatabaseResponse.of_json json)
      else
        Error (parse_aws_error (Some CreateDatabaseResponse.error_of_json))
  | CreateTable ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (CreateTableResponse.of_json json)
      else Error (parse_aws_error (Some CreateTableResponse.error_of_json))
  | DeleteDatabase ->
      if is_success then Ok () else Error (parse_aws_error None)
  | DeleteTable -> if is_success then Ok () else Error (parse_aws_error None)
  | DescribeBatchLoadTask ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (DescribeBatchLoadTaskResponse.of_json json)
      else
        Error
          (parse_aws_error (Some DescribeBatchLoadTaskResponse.error_of_json))
  | DescribeDatabase ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (DescribeDatabaseResponse.of_json json)
      else
        Error (parse_aws_error (Some DescribeDatabaseResponse.error_of_json))
  | DescribeEndpoints ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (DescribeEndpointsResponse.of_json json)
      else
        Error
          (parse_aws_error (Some DescribeEndpointsResponse.error_of_json))
  | DescribeTable ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (DescribeTableResponse.of_json json)
      else Error (parse_aws_error (Some DescribeTableResponse.error_of_json))
  | ListBatchLoadTasks ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (ListBatchLoadTasksResponse.of_json json)
      else
        Error
          (parse_aws_error (Some ListBatchLoadTasksResponse.error_of_json))
  | ListDatabases ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (ListDatabasesResponse.of_json json)
      else Error (parse_aws_error (Some ListDatabasesResponse.error_of_json))
  | ListTables ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (ListTablesResponse.of_json json)
      else Error (parse_aws_error (Some ListTablesResponse.error_of_json))
  | ListTagsForResource ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (ListTagsForResourceResponse.of_json json)
      else
        Error
          (parse_aws_error (Some ListTagsForResourceResponse.error_of_json))
  | ResumeBatchLoadTask ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (ResumeBatchLoadTaskResponse.of_json json)
      else
        Error
          (parse_aws_error (Some ResumeBatchLoadTaskResponse.error_of_json))
  | TagResource ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (TagResourceResponse.of_json json)
      else Error (parse_aws_error (Some TagResourceResponse.error_of_json))
  | UntagResource ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (UntagResourceResponse.of_json json)
      else Error (parse_aws_error (Some UntagResourceResponse.error_of_json))
  | UpdateDatabase ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (UpdateDatabaseResponse.of_json json)
      else
        Error (parse_aws_error (Some UpdateDatabaseResponse.error_of_json))
  | UpdateTable ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (UpdateTableResponse.of_json json)
      else Error (parse_aws_error (Some UpdateTableResponse.error_of_json))
  | WriteRecords ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (WriteRecordsResponse.of_json json)
      else Error (parse_aws_error (Some WriteRecordsResponse.error_of_json))