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
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 batch_meter_usage =
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 productCode =
flag "product-code" (optional string) ~doc:"STRING ProductCode"
and usageRecords =
flag "usage-records" (required json_arg) ~doc:"JSON UsageRecordList" in
fun () ->
call ?endpoint_url ?profile:cli_profile ?region:cli_region
Io.batch_meter_usage
(Values.BatchMeterUsageRequest.make ?productCode
~usageRecords:(Values.UsageRecordList.of_json usageRecords) ())
(Some Values.BatchMeterUsageResult.to_json)
(Some Values.BatchMeterUsageResult.error_to_json)])
let meter_usage =
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 usageQuantity =
flag "usage-quantity" (optional int) ~doc:"INT UsageQuantity"
and dryRun = flag "dry-run" (optional bool) ~doc:"BOOL Boolean"
and usageAllocations =
flag "usage-allocations" (optional json_arg)
~doc:"JSON UsageAllocations"
and clientToken =
flag "client-token" (optional string) ~doc:"STRING ClientToken"
and productCode =
flag "product-code" (required string) ~doc:"STRING ProductCode"
and timestamp =
flag "timestamp" (required json_arg) ~doc:"JSON Timestamp"
and usageDimension =
flag "usage-dimension" (required string)
~doc:"STRING UsageDimension" in
fun () ->
call ?endpoint_url ?profile:cli_profile ?region:cli_region
Io.meter_usage
(Values.MeterUsageRequest.make ?usageQuantity ?dryRun
?usageAllocations:(Option.map
~f:Values.UsageAllocations.of_json
usageAllocations) ?clientToken
~productCode ~timestamp:(Values.Timestamp.of_json timestamp)
~usageDimension ()) (Some Values.MeterUsageResult.to_json)
(Some Values.MeterUsageResult.error_to_json)])
let register_usage =
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 nonce = flag "nonce" (optional string) ~doc:"STRING Nonce"
and productCode =
flag "product-code" (required string) ~doc:"STRING ProductCode"
and publicKeyVersion =
flag "public-key-version" (required int) ~doc:"INT VersionInteger" in
fun () ->
call ?endpoint_url ?profile:cli_profile ?region:cli_region
Io.register_usage
(Values.RegisterUsageRequest.make ?nonce ~productCode
~publicKeyVersion ()) (Some Values.RegisterUsageResult.to_json)
(Some Values.RegisterUsageResult.error_to_json)])
let resolve_customer =
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 registrationToken =
flag "registration-token" (required string)
~doc:"STRING NonEmptyString" in
fun () ->
call ?endpoint_url ?profile:cli_profile ?region:cli_region
Io.resolve_customer
(Values.ResolveCustomerRequest.make ~registrationToken ())
(Some Values.ResolveCustomerResult.to_json)
(Some Values.ResolveCustomerResult.error_to_json)])
let main =
Command.group
~summary:((Awso.Service.to_string Values.service) ^ " commands")
[("batch-meter-usage", batch_meter_usage);
("meter-usage", meter_usage);
("register-usage", register_usage);
("resolve-customer", resolve_customer)]