routinator 0.10.2

An RPKI relying party software.
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
//! Handling of the metrics endpoint.

use std::{cmp, fmt};
use std::fmt::Write;
use chrono::Utc;
use hyper::{Body, Request, Response};
use crate::metrics::{
    HttpServerMetrics, Metrics, PublicationMetrics, RrdpRepositoryMetrics,
    RsyncModuleMetrics, SharedRtrServerMetrics, VrpMetrics
};
use crate::payload::SharedHistory;
use super::errors::initial_validation;


//------------ handle_get ----------------------------------------------------

pub async fn handle_get(
    req: &Request<Body>,
    history: &SharedHistory,
    http: &HttpServerMetrics,
    rtr: &SharedRtrServerMetrics,
) -> Option<Response<Body>> {
    match req.uri().path() {
        "/metrics" => Some(handle_metrics(history, http, rtr).await),
        _ => None
    }
}


//------------ handle_metrics ------------------------------------------------

async fn handle_metrics(
    history: &SharedHistory,
    http: &HttpServerMetrics,
    rtr: &SharedRtrServerMetrics,
) -> Response<Body> {
    let (metrics, serial, start, done, duration) = {
        let history = history.read();
        (
            match history.metrics() {
                Some(metrics) => metrics,
                None => return initial_validation(),
            },
            history.serial(),
            history.last_update_start(),
            history.last_update_done(),
            history.last_update_duration(),
        )
    };

    let mut target = Target::default();

    // Update times.
    let now = Utc::now();
    target.single(
        Metric::new(
            "last_update_start",
            "seconds since the start of the last update",
            MetricType::Gauge,
        ),
        now.signed_duration_since(start).num_seconds()   
    );

    let metric = Metric::new(
        "last_update_duration",
        "duration of the last update in seconds",
        MetricType::Gauge,
    );
    match duration {
        Some(duration) => target.single(metric, duration.as_secs()),
        None => target.single(metric, "NaN")
    }

    let metric = Metric::new(
        "last_update_done",
        "seconds since the end of the last update",
        MetricType::Gauge,
    );
    match done {
        Some(instant) => {
            target.single(
                metric, 
                now.signed_duration_since(instant).num_seconds()
            )
        }
        None => target.single(metric, "NaN")
    }

    // Serial number.
    target.single(
        Metric::new(
            "serial", "current RTR serial number", MetricType::Gauge
        ),
        serial
    );

    // Per-TA metrics.
    pub_point_metrics(
        &mut target, Group::Ta,
        metrics.tals.iter().map(|m| (m.tal.name(), &m.publication))
    );
    object_metrics(
        &mut target, Group::Ta,
        metrics.tals.iter().map(|m| (m.tal.name(), &m.publication))
    );
    vrp_metrics(
        &mut target, Group::Ta,
        metrics.tals.iter().map(|m| (m.tal.name(), &m.vrps))
    );

    // Per-repository metrics.
    pub_point_metrics(
        &mut target, Group::Repository,
        metrics.repositories.iter().map(|m| (m.uri.as_ref(), &m.publication))
    );
    object_metrics(
        &mut target, Group::Repository,
        metrics.repositories.iter().map(|m| (m.uri.as_ref(), &m.publication))
    );
    vrp_metrics(
        &mut target, Group::Repository,
        metrics.repositories.iter().map(|m| (m.uri.as_ref(), &m.vrps))
    );

    // Locally added VRPs
    target.single(
        Metric::new(
            "vrps_added_locally",
            "VRPs added from local exceptions",
            MetricType::Gauge
        ),
        metrics.local.contributed
    );

    // Collector metrics.
    rrdp_metrics(&mut target, &metrics.rrdp);
    rsync_metrics(&mut target, &metrics.rsync);

    // Server metrics.
    rtr_metrics(&mut target, rtr).await;
    http_metrics(&mut target, http);

    //  Deprecated metrics.
    deprecated_metrics(&mut target, &metrics);

    target.into_response()
}

fn pub_point_metrics<'a>(
    target: &mut Target, group: Group,
    metrics: impl Iterator<Item = (&'a str, &'a PublicationMetrics)>
) {
    let metric = Metric::with_prefix(
        group.prefix(), "publication_points_total",
        ("publication points per ", group.help()),
        MetricType::Gauge
    );
    target.header(metric);
    for (name, metrics) in metrics {
        target.multi(metric).label(group.label(), name)
            .label("state", "valid")
            .value(metrics.valid_points);
        target.multi(metric).label(group.label(), name)
            .label("state", "rejected")
            .value(metrics.rejected_points);
    }
}

fn object_metrics<'a>(
    target: &mut Target, group: Group,
    metrics: impl Iterator<Item = (&'a str, &'a PublicationMetrics)>
) {
    let metric = Metric::with_prefix(
        group.prefix(), "objects_total",
        ("VRPs per ", group.help()),
        MetricType::Gauge
    );
    target.header(metric);
    for (name, metrics) in metrics {
        target.multi(metric).label(group.label(), name)
            .label("type", "manifest")
            .label("state", "valid")
            .value(metrics.valid_manifests);
        target.multi(metric).label(group.label(), name)
            .label("type", "manifest")
            .label("state", "invalid")
            .value(metrics.invalid_manifests);
        target.multi(metric).label(group.label(), name)
            .label("type", "manifest")
            .label("state", "stale")
            .value(metrics.stale_manifests);
        target.multi(metric).label(group.label(), name)
            .label("type", "manifest")
            .label("state", "missing")
            .value(metrics.missing_manifests);

        target.multi(metric).label(group.label(), name)
            .label("type", "crl")
            .label("state", "valid")
            .value(metrics.valid_crls);
        target.multi(metric).label(group.label(), name)
            .label("type", "crl")
            .label("state", "invalid")
            .value(metrics.invalid_crls);
        target.multi(metric).label(group.label(), name)
            .label("type", "crl")
            .label("state", "stale")
            .value(metrics.stale_crls);
        target.multi(metric).label(group.label(), name)
            .label("type", "crl")
            .label("state", "stray")
            .value(metrics.stray_crls);

        target.multi(metric).label(group.label(), name)
            .label("type", "ca_cert")
            .label("state", "valid")
            .value(metrics.valid_ca_certs);
        target.multi(metric).label(group.label(), name)
            .label("type", "router_cert")
            .label("state", "valid")
            .value(metrics.valid_ee_certs);
        target.multi(metric).label(group.label(), name)
            .label("type", "cert")
            .label("state", "invalid")
            .value(metrics.invalid_certs);

        target.multi(metric).label(group.label(), name)
            .label("type", "roa")
            .label("state", "valid")
            .value(metrics.valid_roas);
        target.multi(metric).label(group.label(), name)
            .label("type", "roa")
            .label("state", "invalid")
            .value(metrics.invalid_roas);

        target.multi(metric).label(group.label(), name)
            .label("type", "gbr")
            .label("state", "valid")
            .value(metrics.valid_gbrs);
        target.multi(metric).label(group.label(), name)
            .label("type", "gbr")
            .label("state", "invalid")
            .value(metrics.invalid_gbrs);

        target.multi(metric).label(group.label(), name)
            .label("type", "other")
            .label("state", "invalid")
            .value(metrics.others);
    }
}

fn vrp_metrics<'a>(
    target: &mut Target, group: Group,
    metrics: impl Iterator<Item = (&'a str, &'a VrpMetrics)>
) {
    let valid_metric = Metric::with_prefix(
        group.prefix(), "valid_vrps_total",
        ("overall number of VRPs per ", group.help()),
        MetricType::Gauge
    );
    let unsafe_metric = Metric::with_prefix(
        group.prefix(), "unsafe_vrps_total",
        (
            "number of VRPs overlapping with rejected publication points per ",
            group.help()
        ),
        MetricType::Gauge
    );
    let filtered_metric = Metric::with_prefix(
        group.prefix(), "locally_filtered_vrps_total",
        ("number of VRPs filtered out by local exceptions per ", group.help()),
        MetricType::Gauge
    );
    let duplicate_metric = Metric::with_prefix(
        group.prefix(), "duplicate_vrps_total",
        ("number of duplicate VRPs per ", group.help()),
        MetricType::Gauge
    );
    let contributed_metric = Metric::with_prefix(
        group.prefix(), "contributed_vrps_total",
        ("number of VRPs contributed to the final set per ", group.help()),
        MetricType::Gauge
    );

    target.header(valid_metric);
    target.header(unsafe_metric);
    target.header(filtered_metric);
    target.header(duplicate_metric);
    target.header(contributed_metric);
    for (name, metrics) in metrics {
        target.multi(valid_metric).label(group.label(), name)
            .value(metrics.valid);
        target.multi(unsafe_metric).label(group.label(), name)
            .value(metrics.marked_unsafe);
        target.multi(filtered_metric).label(group.label(), name)
            .value(metrics.locally_filtered);
        target.multi(duplicate_metric).label(group.label(), name)
            .value(metrics.duplicate);
        target.multi(contributed_metric).label(group.label(), name)
            .value(metrics.contributed);
    }
}

fn rrdp_metrics(target: &mut Target, metrics: &[RrdpRepositoryMetrics]) {
    let status = Metric::new(
        "rrdp_status",
        "combined status code for RRDP update requests",
        MetricType::Gauge
    );
    target.header(status);
    let notify_status = Metric::new(
        "rrdp_notification_status",
        "status code for getting the RRDP notification file",
        MetricType::Gauge
    );
    target.header(notify_status);
    let payload_status = Metric::new(
        "rrdp_payload_status",
        "status code for getting RRDP payload files",
        MetricType::Gauge
    );
    target.header(payload_status);
    let duration = Metric::new(
        "rrdp_duration",
        "duration of RRDP update in seconds",
        MetricType::Gauge
    );
    target.header(duration);
    let serial = Metric::new(
        "rrdp_serial_info",
        "serial number of the last RRDP update",
        MetricType::Gauge
    );
    target.header(serial);

    for rrdp in metrics {
        target.multi(status).label("uri", &rrdp.notify_uri).value(
            rrdp.status().into_i16()
        );
        target.multi(notify_status).label("uri", &rrdp.notify_uri).value(
            rrdp.notify_status.into_i16()
        );
        target.multi(payload_status).label("uri", &rrdp.notify_uri).value(
            rrdp.payload_status.map(|status| status.into_i16()).unwrap_or(0)
        );
        if let Ok(value) = rrdp.duration {
            target.multi(duration).label("uri", &rrdp.notify_uri).value(
                format_args!(
                    "{}.{:03}",
                    value.as_secs(),
                    value.subsec_millis(),
                )
            )
        }
        if let Some(value) = rrdp.serial {
            target.multi(serial).label("uri", &rrdp.notify_uri).value(value)
        }
    }
}

fn rsync_metrics(target: &mut Target, metrics: &[RsyncModuleMetrics]) {
    let status = Metric::new(
        "rsync_status", "exit status of the rsync command", MetricType::Gauge
    );
    target.header(status);
    let duration = Metric::new(
        "rsync_duration",
        "duration of the rsync command in seconds",
        MetricType::Gauge
    );
    target.header(duration);

    for rsync in metrics {
        target.multi(status).label("uri", &rsync.module).value(
            match rsync.status {
                Ok(status) => status.code().unwrap_or(-1),
                Err(_) => -1
            }
        );
        if let Ok(value) = rsync.duration {
            target.multi(duration).label("uri", &rsync.module).value(
                format_args!(
                    "{}.{:03}",
                    value.as_secs(),
                    value.subsec_millis(),
                )
            );
        }
    }
}

async fn rtr_metrics(target: &mut Target, metrics: &SharedRtrServerMetrics) {
    let detailed = metrics.detailed();
    let metrics = metrics.read().await;

    target.single(
        Metric::new(
            "rtr_current_connections",
            "number of currently open RTR connections",
            MetricType::Gauge
        ),
        metrics.current_connections()
    );
    target.single(
        Metric::new(
            "rtr_bytes_read",
            "total number of bytes read from RTR connections",
            MetricType::Counter
        ),
        metrics.bytes_read()
    );
    target.single(
        Metric::new(
            "rtr_bytes_written",
            "total number of bytes written to RTR connections",
            MetricType::Counter
        ),
        metrics.bytes_written()
    );

    if detailed {
        let item = Metric::new(
            "rtr_client_connections",
            "number of currently open connections per client address",
            MetricType::Gauge
        );
        target.header(item);
        metrics.fold_clients(0, |count, client| {
            if client.is_open() {
                *count += 1
            }
        }).for_each(|(addr, count)| {
            target.multi(item).label("addr", addr).value(count)
        });

        let item = Metric::new(
            "rtr_client_serial",
            "last serial seen by a client address",
            MetricType::Gauge
        );
        target.header(item);
        metrics.fold_clients(None, |serial, client| {
            *serial = match (*serial, client.serial().map(u32::from)) {
                (Some(left), Some(right)) => Some(cmp::max(left, right)),
                (Some(left), None) => Some(left),
                (None, Some(right)) => Some(right),
                (None, None) => None
            };
        }).for_each(|(addr, count)| {
            match count {
                Some(count) => {
                    target.multi(item).label("addr", addr).value(count);
                }
                None => {
                    target.multi(item).label("addr", addr).value(-1);
                }
            }
        });

        let item = Metric::new(
            "rtr_client_last_update_seconds",
            "seconds since last update by a client address",
            MetricType::Gauge
        );
        target.header(item);
        metrics.fold_clients(None, |update, client| {
            *update = match (*update, client.updated()) {
                (Some(left), Some(right)) => Some(cmp::max(left, right)),
                (Some(left), None) => Some(left),
                (None, Some(right)) => Some(right),
                (None, None) => None
            };
        }).for_each(|(addr, update)| {
            match update {
                Some(update) => {
                    let duration = Utc::now() - update;
                    target.multi(item).label("addr", addr).value(
                        format_args!(
                            "{}.{:03}",
                            duration.num_seconds(),
                            duration.num_milliseconds() % 1000,
                        )
                    );
                }
                None => {
                    target.multi(item).label("addr", addr).value(-1)
                }
            }
        });

        let item = Metric::new(
            "rtr_client_read_bytes",
            "number of bytes read from a client address",
            MetricType::Counter,
        );
        target.header(item);
        metrics.fold_clients(0, |count, client| {
            *count += client.bytes_read();
        }).for_each(|(addr, count)| {
            target.multi(item).label("addr", addr).value(count)
        });

        let item = Metric::new(
            "rtr_client_written_bytes",
            "number of bytes written to a client address",
            MetricType::Counter
        );
        target.header(item);
        metrics.fold_clients(0, |count, client| {
            *count += client.bytes_written();
        }).for_each(|(addr, count)| {
            target.multi(item).label("addr", addr).value(count)
        });
    }
}

fn http_metrics(target: &mut Target, metrics: &HttpServerMetrics) {
    target.single(
        Metric::new(
            "http_connections",
            "total number of HTTP connections opened",
            MetricType::Counter
        ),
        metrics.conn_open()
    );
    target.single(
        Metric::new(
            "http_current_connections",
            "number of currently open HTTP connections",
            MetricType::Gauge
        ),
        metrics.conn_open() - metrics.conn_close()
    );
    target.single(
        Metric::new(
            "http_bytes_read",
            "number of bytes read from HTTP connections",
            MetricType::Counter
        ),
        metrics.bytes_read()
    );
    target.single(
        Metric::new(
            "http_bytes_written",
            "number of bytes written to HTTP connections",
            MetricType::Counter
        ),
        metrics.bytes_written()
    );
    target.single(
        Metric::new(
            "http_requests",
            "number of HTTP requests received",
            MetricType::Counter
        ),
        metrics.requests()
    );
}

fn deprecated_metrics(target: &mut Target, metrics: &Metrics) {
    // Old-style per-TAL metrics.
    let valid_roas = Metric::new(
        "valid_roas", "number of valid ROAs seen", MetricType::Gauge
    );
    target.header(valid_roas);
    let total_vrps = Metric::new(
        "total_vrps", "number of valid VRPs per TAL", MetricType::Gauge
    );
    target.header(total_vrps);
    let vrps_unsafe = Metric::new(
        "vrps_unsafe",
        "VRPs overlapping with rejected publication points",
        MetricType::Gauge
    );
    target.header(vrps_unsafe);
    let vrps_filtered = Metric::new(
        "vrps_filtered_locally",
        "VRPs filtered based on local exceptions",
        MetricType::Gauge
    );
    target.header(vrps_filtered);
    let vrps_duplicate = Metric::new(
        "vrps_duplicate",
        "number of duplicate VRPs per TAL",
        MetricType::Gauge
    );
    target.header(vrps_duplicate);
    for tal in &metrics.tals {
        let name = tal.tal.name();
        target.multi(valid_roas).label("tal", name).value(
            tal.publication.valid_roas
        );
        target.multi(total_vrps).label("tal", name).value(
            tal.vrps.valid
        );
        target.multi(vrps_unsafe).label("tal", name).value(
            tal.vrps.marked_unsafe
        );
        target.multi(vrps_filtered).label("tal", name).value(
            tal.vrps.locally_filtered
        );
        target.multi(vrps_duplicate).label("tal", name).value(
            tal.vrps.duplicate
        );
    }

    target.single(
        Metric::new(
            "vrps_final", "final number of VRPs", MetricType::Gauge
        ),
        metrics.vrps.contributed
    );

    // Overall number of stale objects
    target.single(
        Metric::new(
            "stale_objects",
            "total number of stale manifests and CRLs",
            MetricType::Gauge
        ),
        metrics.publication.stale_objects()
    );
}


//------------ Target --------------------------------------------------------

#[derive(Clone, Debug, Default)]
struct Target {
    buf: String,
}

impl Target {
    pub fn into_response(self) -> Response<Body> {
        Response::builder()
        .header("Content-Type", "text/plain; version=0.0.4")
        .body(self.buf.into())
        .expect("finalizing HTTP response")
    }

    pub fn single(&mut self, metric: Metric, value: impl fmt::Display) {
        metric.header(self);
        metric.single(self, value);
    }

    pub fn header(&mut self, metric: Metric) {
        metric.header(self)
    }
    
    pub fn multi(&mut self, metric: Metric) -> LabelValue {
        metric.multi(self)
    }
}


//------------ Metric --------------------------------------------------------

#[derive(Clone, Copy, Debug)]
struct Metric {
    prefix: &'static str,
    name: &'static str,
    help: (&'static str, &'static str),
    mtype: MetricType,
}

impl Metric {
    pub fn new(
        name: &'static str, help: &'static str, mtype: MetricType
    ) -> Self {
        Metric {
            prefix: "",
            name,
            help: (help, ""),
            mtype
        }
    }

    pub fn with_prefix(
        prefix: &'static str,
        name: &'static str,
        help: (&'static str, &'static str),
        mtype: MetricType
    ) -> Self {
        Metric {
            prefix, name, help, mtype
        }
    }

    pub fn header(self, target: &mut Target) {
        writeln!(&mut target.buf,
            "# HELP routinator{}_{} {}{}\n\
             # TYPE routinator{}_{} {}",
            self.prefix, self.name, self.help.0, self.help.1,
            self.prefix, self.name, self.mtype,
        ).expect("writing to string");
    }

    fn single(self, target: &mut Target, value: impl fmt::Display) {
        writeln!(&mut target.buf,
            "routinator{}_{} {}",
            self.prefix, self.name, value
        ).expect("writing to string");
    }

    fn multi(self, target: &mut Target) -> LabelValue {
        LabelValue::new(self, target)
    }
}


//------------ LabelValue ----------------------------------------------------

struct LabelValue<'a> {
    target: &'a mut Target,
    first: bool,
}

impl<'a> LabelValue<'a> {
    fn new(metric: Metric, target: &'a mut Target) -> Self {
        write!(
            &mut target.buf, "routinator{}_{}{{", metric.prefix, metric.name
        ).expect("writing to string");
        LabelValue { target, first: true }
    }

    pub fn label(mut self, name: &str, value: impl fmt::Display) -> Self {
        if self.first {
            self.first = false;
        }
        else {
            self.target.buf.push_str(", ");
        }
        write!(
            &mut self.target.buf, "{}=\"{}\"", name, value
        ).expect("writing to string");
        self
    }

    pub fn value(self, value: impl fmt::Display) {
        writeln!(
            &mut self.target.buf, "}} {}", value
        ).expect("writing to string");
    }
}


//------------ MetricType ----------------------------------------------------

#[derive(Clone, Copy, Debug)]
enum MetricType {
    Counter,
    Gauge,
    /* Not currently used:
    Histogram,
    Summary,
    */
}

impl fmt::Display for MetricType {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str(
            match *self {
                MetricType::Counter => "counter",
                MetricType::Gauge => "gauge",
                /*
                MetricType::Histogram => "histogram",
                MetricType::Summary => "summary",
                */
            }
        )
    }
}


//------------ Group ---------------------------------------------------------

#[derive(Clone, Copy, Debug)]
enum Group {
    Repository,
    Ta,
}

impl Group {
    pub fn prefix(self) -> &'static str {
        match self {
            Group::Repository => "_repository",
            Group::Ta => "_ta",
        }
    }

    pub fn help(self) -> &'static str {
        match self {
            Group::Repository => "repository",
            Group::Ta => "trust anchor",
        }
    }

    pub fn label(self) -> &'static str {
        match self {
            Group::Repository => "uri",
            Group::Ta => "name",
        }
    }
}