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
open! Awso_common.Jane_compat
open Values
type ('i, 'o, 'e) t =
| GetExport: (GetExportRequest.t, GetExportResponse.t,
GetExportResponse.error) t
| ListExports: (ListExportsRequest.t, ListExportsResponse.t,
ListExportsResponse.error) t
| StartDomainExport: (StartDomainExportRequest.t,
StartDomainExportResponse.t, StartDomainExportResponse.error) t
let method_of_endpoint : type i o e. (i, o, e) t -> _ =
function
| GetExport -> `POST
| ListExports -> `POST
| StartDomainExport -> `POST
let uri_of_endpoint : type i o e. (i, o, e) t -> i -> Uri.t =
((fun endpoint x ->
match endpoint with
| GetExport -> (Format.kasprintf Uri.of_string) "/v2/GetExport"
| ListExports -> (Format.kasprintf Uri.of_string) "/v2/ListExports"
| StartDomainExport ->
(Format.kasprintf Uri.of_string) "/v2/StartDomainExport")
[@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
| GetExport ->
let (, body) =
let =
Some ((List.filter_opt []) |> Awso.Http.Headers.of_list) in
let body =
Some
((`Assoc
(List.map
(List.filter_opt
[Some
("exportArn",
(ExportArn.to_value req.GetExportRequest.exportArn))])
~f:(fun (x, y) ->
let value =
Awso.Botodata.Json.value_to_json_scalar y in
(x, value))))
|> Yojson.Safe.to_string) in
(headers, body) in
Awso.Http.Request.make ?headers ?body (method_of_endpoint endp)
| ListExports ->
let (, body) =
let =
Some ((List.filter_opt []) |> Awso.Http.Headers.of_list) in
let body =
Some
((`Assoc
(List.map
(List.filter_opt
[Option.map req.ListExportsRequest.domainName
~f:(fun x -> ("domainName", (DomainName.to_value x)));
Option.map req.ListExportsRequest.maxResults
~f:(fun x -> ("maxResults", (MaxResults.to_value x)));
Option.map req.ListExportsRequest.nextToken
~f:(fun x -> ("nextToken", (NextToken.to_value x)))])
~f:(fun (x, y) ->
let value =
Awso.Botodata.Json.value_to_json_scalar y in
(x, value))))
|> Yojson.Safe.to_string) in
(headers, body) in
Awso.Http.Request.make ?headers ?body (method_of_endpoint endp)
| StartDomainExport ->
let (, body) =
let =
Some ((List.filter_opt []) |> Awso.Http.Headers.of_list) in
let body =
Some
((`Assoc
(List.map
(List.filter_opt
[Option.map req.StartDomainExportRequest.clientToken
~f:(fun x ->
("clientToken", (IdempotencyToken.to_value x)));
Some
("domainName",
(DomainName.to_value
req.StartDomainExportRequest.domainName));
Some
("s3Bucket",
(S3BucketName.to_value
req.StartDomainExportRequest.s3Bucket));
Option.map req.StartDomainExportRequest.s3KeyPrefix
~f:(fun x ->
("s3KeyPrefix", (S3KeyPrefix.to_value x)));
Option.map req.StartDomainExportRequest.s3SseAlgorithm
~f:(fun x ->
("s3SseAlgorithm", (S3SseAlgorithm.to_value x)));
Option.map req.StartDomainExportRequest.s3SseKmsKeyId
~f:(fun x ->
("s3SseKmsKeyId", (S3SseKmsKeyId.to_value x)));
Option.map req.StartDomainExportRequest.s3BucketOwner
~f:(fun x ->
("s3BucketOwner", (AwsAccountId.to_value x)))])
~f:(fun (x, y) ->
let value =
Awso.Botodata.Json.value_to_json_scalar y in
(x, value))))
|> Yojson.Safe.to_string) in
(headers, body) in
Awso.Http.Request.make ?headers ?body (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 x_amzn_error_type =
let = Awso.Http.Headers.to_list (Awso.Http.Response.headers resp) in
match List.Assoc.find ~equal:String.Caseless.equal headers
"x-amzn-ErrorType"
with
| None -> None
| Some value ->
(match String.lsplit2 value ~on:':' with
| None -> Some value
| Some (v, _) -> Some v) 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 }) in
match (x_amzn_error_type, error_of_json,
((code >= 400) && (code <= 599)))
with
| (Some error_type, Some error_of_json, true) ->
let json = Yojson.Safe.from_string body in
error_of_json error_type json
| (None, Some error_of_json, true) ->
(try
let json = Yojson.Safe.from_string body in
match json |> (Yojson.Safe.Util.member "__type") with
| `String error_type ->
let error_type =
match String.lsplit2 error_type ~on:'#' with
| Some (_, s) -> s
| None -> error_type in
error_of_json error_type json
| `Null -> bail ()
| _ ->
failwithf "Error '__type' did not have string type: %s" body
()
with | _ -> bail ())
| (None, _, _) | (_, None, _) | (_, _, false) -> bail () in
let response_to_json resp =
Yojson.Safe.from_string (Awso.Http.Response.body resp) in
let _ = parse_aws_error in
let _ = response_to_json in
let _ = resp in
match endpoint with
| GetExport ->
if is_success
then Ok (GetExportResponse.of_json (response_to_json resp))
else Error (parse_aws_error (Some GetExportResponse.error_of_json))
| ListExports ->
if is_success
then Ok (ListExportsResponse.of_json (response_to_json resp))
else Error (parse_aws_error (Some ListExportsResponse.error_of_json))
| StartDomainExport ->
if is_success
then Ok (StartDomainExportResponse.of_json (response_to_json resp))
else
Error
(parse_aws_error (Some StartDomainExportResponse.error_of_json))