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
open! Awso_common.Jane_compat
open Values
type ('i, 'o, 'e) t =
| CancelResourceRequest: (CancelResourceRequestInput.t,
CancelResourceRequestOutput.t, CancelResourceRequestOutput.error) t
| CreateResource: (CreateResourceInput.t, CreateResourceOutput.t,
CreateResourceOutput.error) t
| DeleteResource: (DeleteResourceInput.t, DeleteResourceOutput.t,
DeleteResourceOutput.error) t
| GetResource: (GetResourceInput.t, GetResourceOutput.t,
GetResourceOutput.error) t
| GetResourceRequestStatus: (GetResourceRequestStatusInput.t,
GetResourceRequestStatusOutput.t, GetResourceRequestStatusOutput.error) t
| ListResourceRequests: (ListResourceRequestsInput.t,
ListResourceRequestsOutput.t, ListResourceRequestsOutput.error) t
| ListResources: (ListResourcesInput.t, ListResourcesOutput.t,
ListResourcesOutput.error) t
| UpdateResource: (UpdateResourceInput.t, UpdateResourceOutput.t,
UpdateResourceOutput.error) t
let method_of_endpoint : type i o e. (i, o, e) t -> _ =
function
| CancelResourceRequest -> `POST
| CreateResource -> `POST
| DeleteResource -> `POST
| GetResource -> `POST
| GetResourceRequestStatus -> `POST
| ListResourceRequests -> `POST
| ListResources -> `POST
| UpdateResource -> `POST
let uri_of_endpoint : type i o e. (i, o, e) t -> i -> Uri.t =
((fun endpoint x ->
match endpoint with
| CancelResourceRequest -> (Format.kasprintf Uri.of_string) "/"
| CreateResource -> (Format.kasprintf Uri.of_string) "/"
| DeleteResource -> (Format.kasprintf Uri.of_string) "/"
| GetResource -> (Format.kasprintf Uri.of_string) "/"
| GetResourceRequestStatus -> (Format.kasprintf Uri.of_string) "/"
| ListResourceRequests -> (Format.kasprintf Uri.of_string) "/"
| ListResources -> (Format.kasprintf Uri.of_string) "/"
| UpdateResource -> (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
| CancelResourceRequest ->
let json = CancelResourceRequestInput.to_json req in
let body = Yojson.Safe.to_string json in
let =
Awso.Http.Headers.of_list
[("Content-Type", "application/x-amz-json-1.0");
("X-Amz-Target", "CloudApiService.CancelResourceRequest")] in
Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
| CreateResource ->
let json = CreateResourceInput.to_json req in
let body = Yojson.Safe.to_string json in
let =
Awso.Http.Headers.of_list
[("Content-Type", "application/x-amz-json-1.0");
("X-Amz-Target", "CloudApiService.CreateResource")] in
Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
| DeleteResource ->
let json = DeleteResourceInput.to_json req in
let body = Yojson.Safe.to_string json in
let =
Awso.Http.Headers.of_list
[("Content-Type", "application/x-amz-json-1.0");
("X-Amz-Target", "CloudApiService.DeleteResource")] in
Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
| GetResource ->
let json = GetResourceInput.to_json req in
let body = Yojson.Safe.to_string json in
let =
Awso.Http.Headers.of_list
[("Content-Type", "application/x-amz-json-1.0");
("X-Amz-Target", "CloudApiService.GetResource")] in
Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
| GetResourceRequestStatus ->
let json = GetResourceRequestStatusInput.to_json req in
let body = Yojson.Safe.to_string json in
let =
Awso.Http.Headers.of_list
[("Content-Type", "application/x-amz-json-1.0");
("X-Amz-Target", "CloudApiService.GetResourceRequestStatus")] in
Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
| ListResourceRequests ->
let json = ListResourceRequestsInput.to_json req in
let body = Yojson.Safe.to_string json in
let =
Awso.Http.Headers.of_list
[("Content-Type", "application/x-amz-json-1.0");
("X-Amz-Target", "CloudApiService.ListResourceRequests")] in
Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
| ListResources ->
let json = ListResourcesInput.to_json req in
let body = Yojson.Safe.to_string json in
let =
Awso.Http.Headers.of_list
[("Content-Type", "application/x-amz-json-1.0");
("X-Amz-Target", "CloudApiService.ListResources")] in
Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
| UpdateResource ->
let json = UpdateResourceInput.to_json req in
let body = Yojson.Safe.to_string json in
let =
Awso.Http.Headers.of_list
[("Content-Type", "application/x-amz-json-1.0");
("X-Amz-Target", "CloudApiService.UpdateResource")] 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
| CancelResourceRequest ->
if is_success
then
let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
Ok (CancelResourceRequestOutput.of_json json)
else
Error
(parse_aws_error (Some CancelResourceRequestOutput.error_of_json))
| CreateResource ->
if is_success
then
let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
Ok (CreateResourceOutput.of_json json)
else Error (parse_aws_error (Some CreateResourceOutput.error_of_json))
| DeleteResource ->
if is_success
then
let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
Ok (DeleteResourceOutput.of_json json)
else Error (parse_aws_error (Some DeleteResourceOutput.error_of_json))
| GetResource ->
if is_success
then
let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
Ok (GetResourceOutput.of_json json)
else Error (parse_aws_error (Some GetResourceOutput.error_of_json))
| GetResourceRequestStatus ->
if is_success
then
let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
Ok (GetResourceRequestStatusOutput.of_json json)
else
Error
(parse_aws_error
(Some GetResourceRequestStatusOutput.error_of_json))
| ListResourceRequests ->
if is_success
then
let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
Ok (ListResourceRequestsOutput.of_json json)
else Error (parse_aws_error None)
| ListResources ->
if is_success
then
let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
Ok (ListResourcesOutput.of_json json)
else Error (parse_aws_error (Some ListResourcesOutput.error_of_json))
| UpdateResource ->
if is_success
then
let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
Ok (UpdateResourceOutput.of_json json)
else Error (parse_aws_error (Some UpdateResourceOutput.error_of_json))