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
(* 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 =
  | CloseTunnel: (CloseTunnelRequest.t, CloseTunnelResponse.t,
  CloseTunnelResponse.error) t 
  | DescribeTunnel: (DescribeTunnelRequest.t, DescribeTunnelResponse.t,
  DescribeTunnelResponse.error) t 
  | ListTagsForResource: (ListTagsForResourceRequest.t,
  ListTagsForResourceResponse.t, ListTagsForResourceResponse.error) t 
  | ListTunnels: (ListTunnelsRequest.t, ListTunnelsResponse.t,
  ListTunnelsResponse.error) t 
  | OpenTunnel: (OpenTunnelRequest.t, OpenTunnelResponse.t,
  OpenTunnelResponse.error) t 
  | RotateTunnelAccessToken: (RotateTunnelAccessTokenRequest.t,
  RotateTunnelAccessTokenResponse.t, RotateTunnelAccessTokenResponse.error) t
  
  | TagResource: (TagResourceRequest.t, TagResourceResponse.t,
  TagResourceResponse.error) t 
  | UntagResource: (UntagResourceRequest.t, UntagResourceResponse.t,
  UntagResourceResponse.error) t 
let method_of_endpoint : type i o e. (i, o, e) t -> _ =
  function
  | CloseTunnel -> `POST
  | DescribeTunnel -> `POST
  | ListTagsForResource -> `POST
  | ListTunnels -> `POST
  | OpenTunnel -> `POST
  | RotateTunnelAccessToken -> `POST
  | TagResource -> `POST
  | UntagResource -> `POST
let uri_of_endpoint : type i o e. (i, o, e) t -> i -> Uri.t =
  ((fun endpoint x ->
      match endpoint with
      | CloseTunnel -> (Format.kasprintf Uri.of_string) "/"
      | DescribeTunnel -> (Format.kasprintf Uri.of_string) "/"
      | ListTagsForResource -> (Format.kasprintf Uri.of_string) "/"
      | ListTunnels -> (Format.kasprintf Uri.of_string) "/"
      | OpenTunnel -> (Format.kasprintf Uri.of_string) "/"
      | RotateTunnelAccessToken -> (Format.kasprintf Uri.of_string) "/"
      | TagResource -> (Format.kasprintf Uri.of_string) "/"
      | UntagResource -> (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
  | CloseTunnel ->
      let json = CloseTunnelRequest.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.1");
          ("X-Amz-Target", "IoTSecuredTunneling.CloseTunnel")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | DescribeTunnel ->
      let json = DescribeTunnelRequest.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.1");
          ("X-Amz-Target", "IoTSecuredTunneling.DescribeTunnel")] 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.1");
          ("X-Amz-Target", "IoTSecuredTunneling.ListTagsForResource")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | ListTunnels ->
      let json = ListTunnelsRequest.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.1");
          ("X-Amz-Target", "IoTSecuredTunneling.ListTunnels")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | OpenTunnel ->
      let json = OpenTunnelRequest.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.1");
          ("X-Amz-Target", "IoTSecuredTunneling.OpenTunnel")] in
      Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
  | RotateTunnelAccessToken ->
      let json = RotateTunnelAccessTokenRequest.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.1");
          ("X-Amz-Target", "IoTSecuredTunneling.RotateTunnelAccessToken")] 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.1");
          ("X-Amz-Target", "IoTSecuredTunneling.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.1");
          ("X-Amz-Target", "IoTSecuredTunneling.UntagResource")] 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
  | CloseTunnel ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (CloseTunnelResponse.of_json json)
      else Error (parse_aws_error (Some CloseTunnelResponse.error_of_json))
  | DescribeTunnel ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (DescribeTunnelResponse.of_json json)
      else
        Error (parse_aws_error (Some DescribeTunnelResponse.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))
  | ListTunnels ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (ListTunnelsResponse.of_json json)
      else Error (parse_aws_error None)
  | OpenTunnel ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (OpenTunnelResponse.of_json json)
      else Error (parse_aws_error (Some OpenTunnelResponse.error_of_json))
  | RotateTunnelAccessToken ->
      if is_success
      then
        let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
        Ok (RotateTunnelAccessTokenResponse.of_json json)
      else
        Error
          (parse_aws_error
             (Some RotateTunnelAccessTokenResponse.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))