Source file cli.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
(* generated by: awso-codegen generate-all --botocore-data vendor/botocore/botocore/data -o aws --runtime-dir lib/runtime/awso --cli-dir awso-cli *)
open Core
open Async
let json_arg = Command.Arg_type.create Yojson.Safe.from_string
let call ?endpoint_url ?profile ?region f m result_to_json error_to_json =
  let region =
    match region with
    | Some region -> Some (Awso.Region.of_string region)
    | None -> None in
  (Awso_async.Cfg.get_exn ?profile ?region ()) >>=
    (fun cfg ->
       (f ?endpoint_url ?cfg:(Some cfg) m) >>=
         (fun result ->
            match result with
            | Error err ->
                (match error_to_json with
                 | None ->
                     failwithf
                       "endpoint error, but no error values defined in boto"
                       ()
                 | Some to_json ->
                     let s = (err |> to_json) |> Yojson.Safe.to_string in
                     failwithf "AWS error: %s" s ())
            | Ok result ->
                ((match result_to_json with
                  | None -> print_endline "ok response from endpoint"
                  | Some to_json ->
                      ((result |> to_json) |> Yojson.Safe.to_string) |>
                        print_endline);
                 return ())))
let cancel_resource_request =
  Command.async ~summary:""
    ([%map_open.Command
       let cli_profile =
         flag "-cli-profile" (optional string) ~doc:"NAME aws profile to use"
       and cli_region =
         flag "-cli-region" (optional string) ~doc:"REGION override region"
       and endpoint_url =
         flag "-endpoint-url" (optional string)
           ~doc:"URL override endpoint url"
       and requestToken =
         flag "request-token" (required string) ~doc:"STRING RequestToken" in
       fun () ->
         call ?endpoint_url ?profile:cli_profile ?region:cli_region
           Io.cancel_resource_request
           (Values.CancelResourceRequestInput.make ~requestToken ())
           (Some Values.CancelResourceRequestOutput.to_json)
           (Some Values.CancelResourceRequestOutput.error_to_json)])
let create_resource =
  Command.async ~summary:""
    ([%map_open.Command
       let cli_profile =
         flag "-cli-profile" (optional string) ~doc:"NAME aws profile to use"
       and cli_region =
         flag "-cli-region" (optional string) ~doc:"REGION override region"
       and endpoint_url =
         flag "-endpoint-url" (optional string)
           ~doc:"URL override endpoint url"
       and typeVersionId =
         flag "type-version-id" (optional string) ~doc:"STRING TypeVersionId"
       and roleArn = flag "role-arn" (optional string) ~doc:"STRING RoleArn"
       and clientToken =
         flag "client-token" (optional string) ~doc:"STRING ClientToken"
       and typeName =
         flag "type-name" (required string) ~doc:"STRING TypeName"
       and desiredState =
         flag "desired-state" (required string) ~doc:"STRING Properties" in
       fun () ->
         call ?endpoint_url ?profile:cli_profile ?region:cli_region
           Io.create_resource
           (Values.CreateResourceInput.make ?typeVersionId ?roleArn
              ?clientToken ~typeName ~desiredState ())
           (Some Values.CreateResourceOutput.to_json)
           (Some Values.CreateResourceOutput.error_to_json)])
let delete_resource =
  Command.async ~summary:""
    ([%map_open.Command
       let cli_profile =
         flag "-cli-profile" (optional string) ~doc:"NAME aws profile to use"
       and cli_region =
         flag "-cli-region" (optional string) ~doc:"REGION override region"
       and endpoint_url =
         flag "-endpoint-url" (optional string)
           ~doc:"URL override endpoint url"
       and typeVersionId =
         flag "type-version-id" (optional string) ~doc:"STRING TypeVersionId"
       and roleArn = flag "role-arn" (optional string) ~doc:"STRING RoleArn"
       and clientToken =
         flag "client-token" (optional string) ~doc:"STRING ClientToken"
       and typeName =
         flag "type-name" (required string) ~doc:"STRING TypeName"
       and identifier =
         flag "identifier" (required string) ~doc:"STRING Identifier" in
       fun () ->
         call ?endpoint_url ?profile:cli_profile ?region:cli_region
           Io.delete_resource
           (Values.DeleteResourceInput.make ?typeVersionId ?roleArn
              ?clientToken ~typeName ~identifier ())
           (Some Values.DeleteResourceOutput.to_json)
           (Some Values.DeleteResourceOutput.error_to_json)])
let get_resource =
  Command.async ~summary:""
    ([%map_open.Command
       let cli_profile =
         flag "-cli-profile" (optional string) ~doc:"NAME aws profile to use"
       and cli_region =
         flag "-cli-region" (optional string) ~doc:"REGION override region"
       and endpoint_url =
         flag "-endpoint-url" (optional string)
           ~doc:"URL override endpoint url"
       and typeVersionId =
         flag "type-version-id" (optional string) ~doc:"STRING TypeVersionId"
       and roleArn = flag "role-arn" (optional string) ~doc:"STRING RoleArn"
       and typeName =
         flag "type-name" (required string) ~doc:"STRING TypeName"
       and identifier =
         flag "identifier" (required string) ~doc:"STRING Identifier" in
       fun () ->
         call ?endpoint_url ?profile:cli_profile ?region:cli_region
           Io.get_resource
           (Values.GetResourceInput.make ?typeVersionId ?roleArn ~typeName
              ~identifier ()) (Some Values.GetResourceOutput.to_json)
           (Some Values.GetResourceOutput.error_to_json)])
let get_resource_request_status =
  Command.async ~summary:""
    ([%map_open.Command
       let cli_profile =
         flag "-cli-profile" (optional string) ~doc:"NAME aws profile to use"
       and cli_region =
         flag "-cli-region" (optional string) ~doc:"REGION override region"
       and endpoint_url =
         flag "-endpoint-url" (optional string)
           ~doc:"URL override endpoint url"
       and requestToken =
         flag "request-token" (required string) ~doc:"STRING RequestToken" in
       fun () ->
         call ?endpoint_url ?profile:cli_profile ?region:cli_region
           Io.get_resource_request_status
           (Values.GetResourceRequestStatusInput.make ~requestToken ())
           (Some Values.GetResourceRequestStatusOutput.to_json)
           (Some Values.GetResourceRequestStatusOutput.error_to_json)])
let list_resource_requests =
  Command.async ~summary:""
    ([%map_open.Command
       let cli_profile =
         flag "-cli-profile" (optional string) ~doc:"NAME aws profile to use"
       and cli_region =
         flag "-cli-region" (optional string) ~doc:"REGION override region"
       and endpoint_url =
         flag "-endpoint-url" (optional string)
           ~doc:"URL override endpoint url"
       and maxResults =
         flag "max-results" (optional int) ~doc:"INT MaxResults"
       and nextToken =
         flag "next-token" (optional string) ~doc:"STRING NextToken"
       and resourceRequestStatusFilter =
         flag "resource-request-status-filter" (optional json_arg)
           ~doc:"JSON ResourceRequestStatusFilter" in
       fun () ->
         call ?endpoint_url ?profile:cli_profile ?region:cli_region
           Io.list_resource_requests
           (Values.ListResourceRequestsInput.make ?maxResults ?nextToken
              ?resourceRequestStatusFilter:(Option.map
                                              ~f:Values.ResourceRequestStatusFilter.of_json
                                              resourceRequestStatusFilter) ())
           (Some Values.ListResourceRequestsOutput.to_json)
           (Some Values.ListResourceRequestsOutput.error_to_json)])
let list_resources =
  Command.async ~summary:""
    ([%map_open.Command
       let cli_profile =
         flag "-cli-profile" (optional string) ~doc:"NAME aws profile to use"
       and cli_region =
         flag "-cli-region" (optional string) ~doc:"REGION override region"
       and endpoint_url =
         flag "-endpoint-url" (optional string)
           ~doc:"URL override endpoint url"
       and typeVersionId =
         flag "type-version-id" (optional string) ~doc:"STRING TypeVersionId"
       and roleArn = flag "role-arn" (optional string) ~doc:"STRING RoleArn"
       and nextToken =
         flag "next-token" (optional string) ~doc:"STRING HandlerNextToken"
       and maxResults =
         flag "max-results" (optional int) ~doc:"INT MaxResults"
       and resourceModel =
         flag "resource-model" (optional string) ~doc:"STRING Properties"
       and typeName =
         flag "type-name" (required string) ~doc:"STRING TypeName" in
       fun () ->
         call ?endpoint_url ?profile:cli_profile ?region:cli_region
           Io.list_resources
           (Values.ListResourcesInput.make ?typeVersionId ?roleArn ?nextToken
              ?maxResults ?resourceModel ~typeName ())
           (Some Values.ListResourcesOutput.to_json)
           (Some Values.ListResourcesOutput.error_to_json)])
let update_resource =
  Command.async ~summary:""
    ([%map_open.Command
       let cli_profile =
         flag "-cli-profile" (optional string) ~doc:"NAME aws profile to use"
       and cli_region =
         flag "-cli-region" (optional string) ~doc:"REGION override region"
       and endpoint_url =
         flag "-endpoint-url" (optional string)
           ~doc:"URL override endpoint url"
       and typeVersionId =
         flag "type-version-id" (optional string) ~doc:"STRING TypeVersionId"
       and roleArn = flag "role-arn" (optional string) ~doc:"STRING RoleArn"
       and clientToken =
         flag "client-token" (optional string) ~doc:"STRING ClientToken"
       and typeName =
         flag "type-name" (required string) ~doc:"STRING TypeName"
       and identifier =
         flag "identifier" (required string) ~doc:"STRING Identifier"
       and patchDocument =
         flag "patch-document" (required string) ~doc:"STRING PatchDocument" in
       fun () ->
         call ?endpoint_url ?profile:cli_profile ?region:cli_region
           Io.update_resource
           (Values.UpdateResourceInput.make ?typeVersionId ?roleArn
              ?clientToken ~typeName ~identifier ~patchDocument ())
           (Some Values.UpdateResourceOutput.to_json)
           (Some Values.UpdateResourceOutput.error_to_json)])
let main =
  Command.group
    ~summary:((Awso.Service.to_string Values.service) ^ " commands")
    [("cancel-resource-request", cancel_resource_request);
    ("create-resource", create_resource);
    ("delete-resource", delete_resource);
    ("get-resource", get_resource);
    ("get-resource-request-status", get_resource_request_status);
    ("list-resource-requests", list_resource_requests);
    ("list-resources", list_resources);
    ("update-resource", update_resource)]