sozuctl 0.13.0

command line application to configure a sozu instance
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
use sozu_command::proxy::{LoadBalancingAlgorithms, TlsVersion};
use std::net::SocketAddr;

#[derive(StructOpt, PartialEq, Debug)]
pub struct App {
  #[structopt(short="c", long = "config", help = "Sets a custom config file")]
  pub config: Option<String>,
  #[structopt(short="t", long = "timeout", help = "Sets a custom timeout for commands (in milliseconds). 0 disables the timeout")]
  pub timeout: Option<u64>,
  #[structopt(subcommand)]
  pub cmd: SubCmd,
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum SubCmd {
  #[structopt(name = "shutdown", about = "shuts down the proxy")]
  Shutdown {
    #[structopt(long = "hard", help = "do not wait for connections to finish")]
    hard: bool,
    #[structopt(short = "w", long = "worker", help = "shuts down the worker with this id")]
    worker: Option<u32>,
  },
  #[structopt(name = "upgrade", about = "upgrade the proxy")]
  Upgrade {
    #[structopt(short = "w", long = "worker", help = "Upgrade the worker with this id")]
    worker: Option<u32>,
  },
  #[structopt(name = "status", about = "gets information on the running workers")]
  Status {
    #[structopt(short = "j", long = "json", help = "Print the command result in JSON format")]
    json: bool
  },
  #[structopt(name = "metrics", about = "gets statistics on the main process and its workers")]
  Metrics {
    #[structopt(short = "j", long = "json", help = "Print the command result in JSON format")]
    json: bool
  },
  #[structopt(name = "logging", about = "change logging level")]
  Logging {
    #[structopt(short = "l", long = "level", help = "change logging level")]
    level: String
  },
  #[structopt(name = "state", about = "state management")]
  State {
    #[structopt(subcommand)]
    cmd: StateCmd,
  },
  #[structopt(name = "reload", about = "Reloads routing configuration (applications, frontends and backends)")]
  Reload{
    #[structopt(short = "f", long = "file", help = "use a different configuration file from the current one")]
    file: Option<String>,
    #[structopt(short = "j", long = "json", help = "Print the command result in JSON format")]
    json: bool
  },
  #[structopt(name = "application", about = "application management")]
  Application {
    #[structopt(subcommand)]
    cmd: ApplicationCmd,
  },
  #[structopt(name = "backend", about = "backend management")]
  Backend {
    #[structopt(subcommand)]
    cmd: BackendCmd,
  },
  #[structopt(name = "frontend", about = "frontend management")]
  Frontend {
    #[structopt(subcommand)]
    cmd: FrontendCmd,
  },
  #[structopt(name  = "listener", about = "listener management")]
  Listener {
    #[structopt(subcommand)]
    cmd: ListenerCmd
  },
  #[structopt(name = "certificate", about = "certificate management")]
  Certificate {
    #[structopt(subcommand)]
    cmd: CertificateCmd,
  },
  #[structopt(name = "query", about = "configuration state verification")]
  Query {
    #[structopt(short = "j", long = "json", help = "Print the command result in JSON format")]
    json: bool,
    #[structopt(subcommand)]
    cmd: QueryCmd,
  },
  #[structopt(name = "config", about = "configuration file management")]
  Config {
    #[structopt(subcommand)]
    cmd: ConfigCmd
  },
  #[structopt(name = "events", about = "receive sozu events")]
  Events
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum StateCmd {
  #[structopt(name = "save", about = "Save state to that file")]
  Save {
    #[structopt(short = "f", long = "file")]
    file: String,
  },
  #[structopt(name = "load", about = "Load state from that file")]
  Load {
    #[structopt(short = "f", long = "file")]
    file: String,
  },
  #[structopt(name = "dump", about = "Dump current state to STDOUT")]
  Dump {
    #[structopt(short = "j", long = "json", help = "Print the command result in JSON format")]
    json: bool
  },
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum ApplicationCmd {
  #[structopt(name = "remove", about = "Remove an application")]
  Remove {
    #[structopt(short = "i", long = "id")]
    id: String,
  },
  #[structopt(name = "add", about = "Add an application")]
  Add{
    #[structopt(short = "i", long = "id")]
    id: String,
    #[structopt(short = "s", long = "sticky-session")]
    sticky_session: bool,
    #[structopt(short = "h", long = "https-redirect")]
    https_redirect: bool,
    #[structopt(long = "send-proxy", help = "Enforces use of the PROXY protocol version 2 over any connection established to this server.")]
    send_proxy: bool,
    #[structopt(long = "expect-proxy", help = "Configures the client-facing connection to receive a PROXY protocol header version 2")]
    expect_proxy: bool,
    #[structopt(long = "load-balancing-policy", help = "Configures the load balancing policy. Possible values are 'roundrobin', 'random' or 'leastconnections'")]
    load_balancing_policy: LoadBalancingAlgorithms,
  },
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum BackendCmd {
  #[structopt(name = "remove", about = "Remove a backend")]
  Remove {
    #[structopt(short = "i", long = "id")]
    id: String,
    #[structopt(long = "backend-id")]
    backend_id: String,
    #[structopt(short = "a", long = "address", help = "server address, format: IP:port")]
    address: SocketAddr,
  },
  #[structopt(name = "add", about = "Add a backend")]
  Add {
    #[structopt(short = "i", long = "id")]
    id: String,
    #[structopt(long = "backend-id")]
    backend_id: String,
    #[structopt(short = "a", long = "address", help = "server address, format: IP:port")]
    address: SocketAddr,
    #[structopt(short = "s", long = "sticky-id", help = "value for the sticky session cookie")]
    sticky_id: Option<String>,
    #[structopt(short = "b", long = "backup", help = "set backend as a backup backend")]
    backup: Option<bool>,
  },
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum FrontendCmd {
  #[structopt(name = "http", about = "HTTP frontend management")]
  Http {
    #[structopt(subcommand)]
    cmd: HttpFrontendCmd,
  },
  #[structopt(name = "https", about = "HTTPS frontend management")]
  Https {
    #[structopt(subcommand)]
    cmd: HttpFrontendCmd,
  },
  #[structopt(name = "tcp", about = "TCP frontend management")]
  Tcp {
    #[structopt(subcommand)]
    cmd: TcpFrontendCmd,
  },
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum HttpFrontendCmd {
  #[structopt(name = "add")]
  Add {
    #[structopt(short = "a", long = "address", help = "frontend address, format: IP:port")]
    address: SocketAddr,
    #[structopt(short = "i", long = "id", help = "app id of the frontend")]
    id: String,
    #[structopt(short = "host", long = "hostname")]
    hostname: String,
    #[structopt(short = "p", long = "path", help="URL prefix of the frontend")]
    path_begin: Option<String>,
  },
  #[structopt(name = "remove")]
  Remove {
    #[structopt(short = "a", long = "address", help = "frontend address, format: IP:port")]
    address: SocketAddr,
    #[structopt(short = "i", long = "id", help = "app id of the frontend")]
    id: String,
    #[structopt(short = "host", long = "hostname")]
    hostname: String,
    #[structopt(short = "p", long = "path", help="URL prefix of the frontend")]
    path_begin: Option<String>,
  },
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum TcpFrontendCmd {
  #[structopt(name = "add")]
  Add {
    #[structopt(short = "i", long = "id", help = "app id of the frontend")]
    id: String,
    #[structopt(short = "a", long = "address", help = "frontend address, format: IP:port")]
    address: SocketAddr,
  },
  #[structopt(name = "remove")]
  Remove {
    #[structopt(short = "i", long = "id", help = "app id of the frontend")]
    id: String,
    #[structopt(short = "a", long = "address", help = "frontend address, format: IP:port")]
    address: SocketAddr,
  },
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum ListenerCmd {
  #[structopt(name = "http", about = "HTTP listener management")]
  Http {
    #[structopt(subcommand)]
    cmd: HttpListenerCmd,
  },
  #[structopt(name = "https", about = "HTTPS listener management")]
  Https {
    #[structopt(subcommand)]
    cmd: HttpsListenerCmd,
  },
  #[structopt(name = "tcp", about = "TCP listener management")]
  Tcp {
    #[structopt(subcommand)]
    cmd: TcpListenerCmd,
  },
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum HttpListenerCmd {
  #[structopt(name = "add")]
  Add {
    #[structopt(short = "a")]
    address: SocketAddr,
    #[structopt(long = "public-address", help = "a different IP than the one the socket sees, for logs and forwarded headers")]
    public_address: Option<SocketAddr>,
    #[structopt(long = "answer-404", help = "path to file of the 404 answer sent to the client when a frontend is not found")]
    answer_404: Option<String>,
    #[structopt(long = "answer-503", help = "path to file of the 503 answer sent to the client when an application has no backends available")]
    answer_503: Option<String>,
    #[structopt(long = "expect-proxy", help = "Configures the client socket to receive a PROXY protocol header")]
    expect_proxy: bool,
    #[structopt(long = "sticky-name", help = "sticky session cookie name")]
    sticky_name: Option<String>
  },
  #[structopt(name = "remove")]
  Remove {
    #[structopt(short = "a", long = "address", help = "listener address, format: IP:port")]
    address: SocketAddr,
  },
  #[structopt(name = "activate")]
  Activate {
    #[structopt(short = "a", long = "address", help = "listener address, format: IP:port")]
    address: SocketAddr
  },
  #[structopt(name = "deactivate")]
  Deactivate {
    #[structopt(short = "a", long = "address", help = "listener address, format: IP:port")]
    address: SocketAddr
  }
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum HttpsListenerCmd {
  #[structopt(name = "add")]
  Add {
    #[structopt(short = "a")]
    address: SocketAddr,
    #[structopt(long = "public-address", help = "a different IP than the one the socket sees, for logs and forwarded headers")]
    public_address: Option<SocketAddr>,
    #[structopt(long = "answer-404", help = "path to file of the 404 answer sent to the client when a frontend is not found")]
    answer_404: Option<String>,
    #[structopt(long = "answer-503", help = "path to file of the 503 answer sent to the client when an application has no backends available")]
    answer_503: Option<String>,
    #[structopt(long = "tls-versions", help = "list of TLS versions to use")]
    tls_versions: Vec<TlsVersion>,
    #[structopt(long = "tls-ciphers-list", help = "list of OpenSSL TLS ciphers to use")]
    cipher_list: Option<String>,
    #[structopt(long = "rustls-cipher-list", help = "list of RustTLS ciphers to use")]
    rustls_cipher_list: Vec<String>,
    #[structopt(long = "expect-proxy", help = "Configures the client socket to receive a PROXY protocol header")]
    expect_proxy: bool,
    #[structopt(long = "sticky-name", help = "sticky session cookie name")]
    sticky_name: Option<String>
  },
  #[structopt(name = "remove")]
  Remove {
    #[structopt(short = "a", long = "address", help = "listener address, format: IP:port")]
    address: SocketAddr,
  },
  #[structopt(name = "activate")]
  Activate {
    #[structopt(short = "a", long = "address", help = "listener address, format: IP:port")]
    address: SocketAddr
  },
  #[structopt(name = "deactivate")]
  Deactivate {
    #[structopt(short = "a", long = "address", help = "listener address, format: IP:port")]
    address: SocketAddr
  }
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum TcpListenerCmd {
  #[structopt(name = "add")]
  Add {
    #[structopt(short = "a", long = "address", help = "listener address, format: IP:port")]
    address: SocketAddr,
    #[structopt(long = "public-address", help = "a different IP than the one the socket sees, for logs and forwarded headers")]
    public_address: Option<SocketAddr>,
    #[structopt(long = "expect-proxy", help = "Configures the client socket to receive a PROXY protocol header")]
    expect_proxy: bool
  },
  #[structopt(name = "remove")]
  Remove {
    #[structopt(short = "a", long = "address", help = "listener address, format: IP:port")]
    address: SocketAddr,
  },
  #[structopt(name = "activate")]
  Activate {
    #[structopt(short = "a", long = "address", help = "listener address, format: IP:port")]
    address: SocketAddr
  },
  #[structopt(name = "deactivate")]
  Deactivate {
    #[structopt(short = "a", long = "address", help = "listener address, format: IP:port")]
    address: SocketAddr
  }
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum CertificateCmd {
  #[structopt(name = "add", about = "Add a certificate")]
  Add {
    #[structopt(short = "a", long = "address", help = "listener address, format: IP:port")]
    address: SocketAddr,
    #[structopt(long = "certificate", help = "path to the certificate")]
    certificate: String,
    #[structopt(long = "certificate-chain", help = "path to the certificate chain")]
    chain: String,
    #[structopt(long = "key", help = "path to the key")]
    key: String,
    #[structopt(long = "tls-versions", help = "accepted TLS versions for this certificate",
                parse(try_from_str = parse_tls_versions))]
    tls_versions: Vec<TlsVersion>,
  },
  #[structopt(name = "remove", about = "Remove a certificate")]
  Remove {
    #[structopt(short = "a", long = "address", help = "listener address, format: IP:port")]
    address: SocketAddr,
    #[structopt(short = "cert", long = "certificate", help = "path to the certificate")]
    certificate: Option<String>,
    #[structopt(short = "f", long = "fingerprint", help = "certificate fingerprint")]
    fingerprint: Option<String>,
  },
  #[structopt(name = "replace", about = "Replace an existing certificate")]
  Replace {
    #[structopt(short = "a", long = "address", help = "listener address, format: IP:port")]
    address: SocketAddr,
    #[structopt(long = "new-certificate", help = "path to the new certificate")]
    certificate: String,
    #[structopt(long = "new-certificate-chain", help = "path to the new certificate chain")]
    chain: String,
    #[structopt(long = "new-key", help = "path to the new key")]
    key: String,
    #[structopt(short = "old-cert", long = "old-certificate", help = "path to the old certificate")]
    old_certificate: Option<String>,
    #[structopt(short = "f", long = "fingerprint", help = "old certificate fingerprint")]
    old_fingerprint: Option<String>,
    #[structopt(long = "tls-versions", help = "accepted TLS versions for this certificate",
                parse(try_from_str = parse_tls_versions))]
    tls_versions: Vec<TlsVersion>,
  }
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum QueryCmd {
  #[structopt(name = "applications", about = "Query applications matching a specific filter")]
  Applications {
    #[structopt(short = "i", long="id", help="application identifier")]
    id: Option<String>,
    #[structopt(short = "d", long="domain", help="application domain name")]
    domain: Option<String>
  },

  #[structopt(name = "certificates", about = "Query certificates matching a specific filter")]
  Certificates {
    #[structopt(short = "f", long="fingerprint", help="certificate fingerprint")]
    fingerprint: Option<String>,
    #[structopt(short = "d", long="domain", help="domain name")]
    domain: Option<String>
  }
}

#[derive(StructOpt, PartialEq, Debug)]
pub enum ConfigCmd {
  #[structopt(name = "check", about = "check configuration file syntax and exit")]
  Check {}
}

fn parse_tls_versions(i: &str) -> Result<TlsVersion, String> {
    match i {
        "TLSv1" => Ok(TlsVersion::TLSv1_0),
        "TLSv1.1" => Ok(TlsVersion::TLSv1_1),
        "TLSv1.2" => Ok(TlsVersion::TLSv1_2),
        "TLSv1.3" => Ok(TlsVersion::TLSv1_2),
        s => return Err(format!("unrecognized TLS version: {}", s)),
    }
}