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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
extern crate clap;
extern crate rocl;
use clap::{crate_authors, crate_version, Arg, Command};
use rocl::apis::configuration::Configuration;
use rocs::cli;
use std::error::Error;
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let matches = Command::new("rocs")
.version(crate_version!())
.author(crate_authors!())
.about("Rust OSB Client 'Super'")
.subcommand_required(true)
.arg_required_else_help(true)
.arg(
Arg::new("broker_url")
.short('b')
.long("broker")
.env("ROCS_BROKER_URL")
.takes_value(true)
.required(true),
)
.arg(
Arg::new("broker_user")
.short('u')
.long("username")
.env("ROCS_BROKER_USERNAME")
.takes_value(true)
.required(true),
)
.arg(
Arg::new("broker_pass")
.short('a')
.long("password")
.env("ROCS_BROKER_PASSWORD")
.takes_value(true)
.required(true),
)
.arg(
Arg::new("json")
.help("Prints result in JSON format")
.long("json")
.takes_value(false)
.required(false),
)
.arg(
Arg::new("sync")
.help("Execute provisioning and binding synchronously")
.long("sync")
.takes_value(false)
.required(false),
)
.arg(
Arg::new("curl")
.help("Prints cURL command")
.long("curl")
.takes_value(false)
.required(false),
)
.subcommand(
Command::new("provision")
.about("Service Instance provisioning")
.arg(
Arg::new("service")
.short('s')
.long("service")
.takes_value(true)
.required(true)
.help("service offering to use for provision"),
)
.arg(
Arg::new("plan")
.short('p')
.long("plan")
.takes_value(true)
.required(true)
.help("service plan to use for provision"),
)
.arg(
Arg::new("parameters")
.short('P')
.long("params")
.multiple_values(true)
.takes_value(true)
.help("parameters to provision service instances. ex: region=us-east-1 other=value"),
)
.arg(
Arg::new("context")
.short('C')
.long("context")
.multiple_values(true)
.takes_value(true)
.help("context to provision service instances. ex: account_id=123 other=value"),
)
.arg(
Arg::new("wait")
.short('w')
.long("wait")
.takes_value(false)
.help("wait service instance provisioning to finish"),
),
)
.subcommand(
Command::new("deprovision")
.about("Service Instance deprovisioning")
.arg(
Arg::new("instance")
.short('i')
.long("instance")
.takes_value(true)
.required(true)
.help("service instance id to deprovision"),
),
)
.subcommand(
Command::new("bind")
.about("Service Binding request")
.arg(
Arg::new("instance")
.short('i')
.long("instance")
.takes_value(true)
.help("instance ID or name to bind")
.required(true),
)
.arg(
Arg::new("binding")
.short('b')
.long("binding")
.takes_value(true)
.help("binding ID to fetch if bindings are fetchable")
)
.arg(
Arg::new("parameters")
.short('P')
.long("params")
.multiple_values(true)
.takes_value(true)
.help("parameters to provision service bindings. ex: param1=value1 param2=value2"),
)
.arg(
Arg::new("context")
.short('C')
.long("context")
.multiple_values(true)
.takes_value(true)
.help("context to provision service bindings. ex: account_id=123 other=value"),
)
.arg(
Arg::new("wait")
.short('w')
.long("wait")
.takes_value(false)
.help("wait service binding provisioning to finish")
)
)
.subcommand(
Command::new("unbind")
.about("Service Binding removal")
.arg(
Arg::new("instance")
.short('i')
.long("instance")
.takes_value(true)
.help("instance ID or name to bind")
.required(true),
)
.arg(
Arg::new("binding")
.short('b')
.long("binding")
.takes_value(true)
.help("Binding ID to unbind")
.required(true),
),
)
.subcommand(
Command::new("catalog")
.about("Catalog request")
.alias("cat"),
)
.subcommand(
Command::new("info")
.about("Fetch Service Instances information")
.arg(
Arg::new("instance")
.short('i')
.long("instance")
.takes_value(true)
.help("instance ID to fetch information")
.required(true),
)
)
.subcommand(
Command::new("extension")
.about("Extension interaction")
.alias("ext")
.arg(
Arg::new("instance")
.short('i')
.help("Instance ID to access extension")
.takes_value(true)
.required(true)
)
.arg(
Arg::new("id")
.short('I')
.help("Extension ID")
.takes_value(true)
.required(true)
)
.arg(
Arg::new("operation")
.short('o')
.help("Operation to perform")
.takes_value(true)
.required_unless_present("list")
)
.arg(
Arg::new("parameters")
.short('P')
.help("All parameters required for this action including path parameters")
.takes_value(true)
.multiple_values(true)
)
.arg(
Arg::new("body")
.short('B')
.help("Request body with required fields")
.takes_value(true)
)
.arg(
Arg::new("list")
.short('l')
.help("List operations and parameters available for an extension")
.takes_value(false)
)
)
.get_matches();
let mut cfg = Configuration::new();
cfg.user_agent = Some(cli::USER_AGENT.to_string());
cfg.basic_auth = Some((
matches.value_of("broker_user").unwrap().to_owned(),
Some(matches.value_of("broker_pass").unwrap().to_owned()),
));
cfg.base_path = matches.value_of("broker_url").unwrap().to_owned();
let options = cli::Options {
json_output: matches.is_present("json"),
curl_output: matches.is_present("curl"),
synchronous: matches.is_present("sync"),
};
match matches.subcommand_name() {
Some("catalog") => {
cli::catalog(matches.subcommand_matches("catalog").unwrap(), cfg, options).await
}
Some("provision") => {
cli::provision(
matches.subcommand_matches("provision").unwrap(),
cfg,
options,
)
.await
}
Some("deprovision") => {
cli::deprovision(
matches.subcommand_matches("deprovision").unwrap(),
cfg,
options,
)
.await
}
Some("bind") => cli::bind(matches.subcommand_matches("bind").unwrap(), cfg, options).await,
Some("unbind") => {
cli::unbind(matches.subcommand_matches("unbind").unwrap(), cfg, options).await
}
Some("info") => cli::info(matches.subcommand_matches("info").unwrap(), cfg, options).await,
/*Some("extension") => ext::command(
matches.subcommand_matches("extension").unwrap(),
client,
options,
&matches,
),*/
_ => Err(Box::from("unknown command")),
}
}