asterust-junos 0.5.10

Typed Juniper JunOS config views (interfaces, protocols, routing instances and options, policy options, firewall filters, class of service, system, services) extracted from an asterust config tree.
Documentation
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
//! `system`
//! `system { ... }`.
//!
//! Each statement with children of its own lives in a submodule named after it.
//!
//! # See also
//!
//! - [`[edit system]` hierarchy](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/topic-map/hierarchy-edit-system.html)
//! - [host-name (System)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/host-name-edit-system.html)
//! - [domain-name (System)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/domain-name-edit-system.html)
//! - [time-zone](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/time-zone-edit-system.html)
//! - [domain-search](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/domain-search-edit-system.html)
//! - [authentication-order (System)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/authentication-order-edit-system.html)
//! - [max-configurations-on-flash (System)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/max-configurations-on-flash-edit-system.html)
//! - [no-redirects (IPv4 Traffic)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/no-redirects-edit-system.html)
//! - [default-address-selection](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/default-address-selection-edit-system.html)
//! - [diag-port-authentication](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/diag-port-authentication-edit-system.html)
//! - [pic-console-authentication](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/pic-console-authentication-edit-system.html)
//! - [boot-loader-authentication](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/boot-loader-authentication-edit-system.html)
//! - [device-authentication](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/device-authentication-edit-system.html)
//! - [allow-6pe-traceroute](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/allow-6pe-traceroute-edit-system.html)
//! - [allow-l3vpn-traceroute-src-select](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/allow-l3vpn-traceroute-src-select-edit-system.html)
//! - [arp-system-cache-limit](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/arp-system-cache-limit-edit-system.html)
//! - [dual-phase-bootup](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/dual-phase-bootup-edit-system.html)
//! - [extended-echo](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/extended-echo-edit-system.html)
//! - [management-instance](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/management-instance-edit-system.html)
//! - [nd-override-preferred-src](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/nd-override-preferred-src-edit-system.html)
//! - [nd-retransmit-timer](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/nd-retransmit-timer-edit-system.html)
//! - [nd-system-cache-limit](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/nd-system-cache-limit-edit-system.html)
//! - [no-hidden-commands](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/no-hidden-set-system.html)
//! - [node (System)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/node-edit-system.html)
//! - [regex-additive-logic](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/regex-additive-logic-edit-system.html)
//! - [rng](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/rng-edit-system.html)
//! - [saved-core-context (System)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/saved-core-context-edit-system.html)
//! - [saved-core-files (System)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/saved-core-files-edit-system.html)
//! - [unattended-boot](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/unattended-boot-edit-system.html)

mod access_line;
mod accounting;
mod archival;
mod arp;
mod authentication_secret;
mod auto_sw_sync;
mod autoinstallation;
mod backup_router;
mod commit;
mod configuration;
mod configuration_database;
mod ddos_protection;
mod demux_options;
mod dynamic_profile_options;
mod export_format;
mod extensions;
mod fib_streaming;
mod health_monitor;
mod icmp;
mod internet_options;
mod kernel_replication;
mod license;
mod location;
mod login;
mod management_traffic;
mod master_password;
mod monitor;
mod name_server;
mod ntp;
mod packet_forwarding_options;
mod password_options;
mod pixel_tracing;
mod ports;
mod processes;
mod proxy;
mod radius_options;
mod radius_server;
mod resiliency;
mod root_authentication;
mod schema;
mod scripts;
mod services;
mod snapshot;
mod static_host_mapping;
mod syslog;
mod tacplus_options;
mod tacplus_server;
mod tracing;

pub use access_line::{AccessLine, AccessLineAdjustment};
pub use accounting::{Accounting, AccountingDestination};
pub use archival::{Archival, ArchivalConfiguration};
pub use arp::{Arp, ArpInterface};
pub use authentication_secret::AuthenticationSecret;
pub use auto_sw_sync::AutoSwSync;
pub use autoinstallation::{Autoinstallation, AutoinstallationInterface};
pub use backup_router::BackupRouter;
pub use commit::{Commit, CommitPeer, CommitServer};
pub use configuration::ConfigurationInput;
pub use configuration_database::{
    ConfigurationDatabase, DatabaseResize, EphemeralDatabase, EphemeralInstance, VirtualMemoryProcess,
};
pub use ddos_protection::{DdosFlowLevels, DdosFpc, DdosGlobal, DdosPacketType, DdosProtection, DdosProtocolGroup};
pub use demux_options::DemuxOptions;
pub use dynamic_profile_options::DynamicProfileOptions;
pub use export_format::ExportFormat;
pub use extensions::{ExtensionApplication, ExtensionProvider, Extensions, ProviderLicense};
pub use fib_streaming::{FibStreaming, FibStreamingTable};
pub use health_monitor::HealthMonitor;
pub use icmp::Icmp;
pub use internet_options::{IcmpRateLimit, InternetOptions};
pub use kernel_replication::KernelReplication;
pub use license::{License, LicenseAutoupdate, LicenseRenew};
pub use location::Location;
pub use login::{Login, LoginClass, LoginPassword, LoginRetryOptions, LoginUser};
pub use management_traffic::ManagementTrafficProtocol;
pub use master_password::MasterPassword;
pub use monitor::{
    MemoryMonitor, Monitor, ProcessMemoryEvent, ProcessMemoryMonitor, ProcessMemoryThreshold, SystemMemoryEvent,
    SystemMemoryMonitor,
};
pub use name_server::NameServer;
pub use ntp::{Ntp, NtpAuthenticationKey, NtpBroadcast, NtpHost, NtpHostNts, NtpNts, NtpRestriction, NtpThreshold};
pub use packet_forwarding_options::{
    HwMonitorProfile, HwResourceList, HwResourceMonitor, PacketForwardingOptions, PfeFirewall, PfeSystemProfile,
    RecycleBandwidthProfile,
};
pub use password_options::PasswordOptions;
pub use pixel_tracing::PixelTracing;
pub use ports::{Auxiliary, Console, Ports};
pub use processes::{Process, SnoopingFile};
pub use proxy::Proxy;
pub use radius_options::RadiusOptions;
pub use radius_server::RadiusServer;
pub use resiliency::{Resiliency, ResiliencyFile, ResiliencyStore};
pub use root_authentication::RootAuthentication;
pub use schema::Schema;
pub use scripts::{ScriptArgument, ScriptFile, ScriptKind, ScriptOid, Scripts};
pub use services::{
    AaclStatisticsProfile, ConnectionLimits, DhcpLocalServer, DhcpLocalServerGroup, Dns, DnsCacheEntry, DnsDomain,
    DnsProxy, DnsView, Dnssec, ExtensionService, FlowTapDtcp, FlowTapDtcpSsh, FpcLimit, FtpService, GrpcService,
    GrpcSsl, HttpServer, HttpServerTls, InbandZtp, Jeb, JebTls, JetNotification, JtreeResourceType,
    LocalPolicyDecisionFunction, Netconf, NetconfClientIdentity, NetconfDefaultClientIdentity, NetconfHelloMessage,
    NetconfMonitoring, NetconfSsh, NetconfTls, NetconfYangModules, OutboundHttpsAddress, OutboundHttpsClient,
    OutboundSshClient, OutboundSshServer, PicLimit, PortLimit, RedundancyInterface, ResourceMonitor, Rest, RestHttp,
    RestHttps, Reverse, ServiceDeployment, ServiceDeploymentServer, Services, SshModuli, SshService,
    StaticSubscriberGroup, StaticSubscriberProfile, StaticSubscribers, SubscriberLimit, SubscriberManagement,
    SubscriberRedundancy, TelnetService, WebManagement, WebManagementHttp, WebManagementHttps,
    WebManagementVirtualDomain, XnmClearText, XnmSsl,
};
pub use snapshot::{Snapshot, SnapshotRecovery};
pub use static_host_mapping::StaticHostMapping;
pub use syslog::{Syslog, SyslogArchive, SyslogHost, SyslogRule, SyslogStructuredData, SyslogTarget};
pub use tacplus_options::TacplusOptions;
pub use tacplus_server::TacplusServer;
pub use tracing::Tracing;

use crate::{
    active_children, arg_of, args_of, child_block, has_leaf, list_values, split_name, toggle, top_level, unquote,
};
use access_line::parse_access_line;
use accounting::parse_accounting;
use archival::parse_archival;
use arp::parse_arp;
use asterust::config::{Config, ConfigLine};
use authentication_secret::password_secrets;
use auto_sw_sync::auto_sw_sync;
use autoinstallation::parse_autoinstallation;
use backup_router::parse_backup_router;
use commit::parse_commit;
use configuration::parse_configuration;
use configuration_database::parse_configuration_database;
use ddos_protection::parse_ddos_protection;
use demux_options::parse_demux_options;
use dynamic_profile_options::parse_dynamic_profile_options;
use export_format::parse_export_format;
use extensions::parse_extensions;
use fib_streaming::parse_fib_streaming;
use health_monitor::parse_health_monitor;
use icmp::parse_icmp;
use internet_options::parse_internet_options;
use kernel_replication::parse_kernel_replication;
use license::parse_license;
use location::parse_location;
use login::parse_login;
use management_traffic::management_traffic;
use master_password::parse_master_password;
use monitor::parse_monitor;
use name_server::name_servers;
use ntp::parse_ntp;
use packet_forwarding_options::parse_packet_forwarding_options;
use password_options::parse_password_options;
use pixel_tracing::parse_pixel_tracing;
use ports::parse_ports;
use processes::parse_processes;
use proxy::parse_proxy;
use radius_options::parse_radius_options;
use radius_server::radius_servers;
use resiliency::parse_resiliency;
use root_authentication::root_authentication;
use schema::parse_schema;
use scripts::parse_scripts;
use services::parse_services;
use snapshot::parse_snapshot;
use static_host_mapping::static_host_mappings;
use syslog::parse_syslog;
use tacplus_options::parse_tacplus_options;
use tacplus_server::tacplus_servers;
use tracing::parse_tracing;

/// The top-level `system` configuration.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct System {
    pub host_name: Option<String>,
    pub domain_name: Option<String>,
    /// e.g. `"UTC"` or `"America/New_York"`.
    pub time_zone: Option<String>,
    pub domain_search: Vec<String>,
    pub static_host_mappings: Vec<StaticHostMapping>,
    pub backup_router: Option<BackupRouter>,
    pub inet6_backup_router: Option<BackupRouter>,
    /// Methods in the order tried: `password`, `radius`, `tacplus`.
    pub authentication_order: Vec<String>,
    pub radius_servers: Vec<RadiusServer>,
    pub tacplus_servers: Vec<TacplusServer>,
    pub location: Option<Location>,
    pub ports: Option<Ports>,
    pub max_configurations_on_flash: Option<String>,
    pub max_configuration_rollbacks: Option<String>,
    pub no_redirects: bool,
    /// `default-address-selection`: use the loopback as the source of locally generated packets.
    pub default_address_selection: bool,
    pub internet_options: Option<InternetOptions>,
    pub commit: Option<Commit>,
    pub processes: Vec<Process>,
    pub dynamic_profile_options: Option<DynamicProfileOptions>,
    pub extensions: Option<Extensions>,
    pub autoinstallation: Option<Autoinstallation>,
    pub schema: Option<Schema>,
    pub pixel_tracing: Option<PixelTracing>,
    pub scripts: Option<Scripts>,
    pub no_multicast_echo: bool,
    pub no_ping_record_route: bool,
    pub no_ping_time_stamp: bool,
    pub auto_snapshot: bool,
    pub compress_configuration_files: bool,
    pub mirror_flash_on_disk: bool,
    pub switchover_on_routing_crash: bool,
    pub use_imported_time_zones: bool,
    pub archival: Option<Archival>,
    pub accounting: Option<Accounting>,
    pub root_authentication: Option<RootAuthentication>,
    pub master_password: Option<MasterPassword>,
    /// Method name of `diag-port-authentication`, e.g. `encrypted-password`.
    pub diag_port_authentication: Vec<String>,
    /// The passwords of `diag-port-authentication`; empty unless the `secrets` feature is enabled.
    pub diag_port_authentication_secrets: Vec<AuthenticationSecret>,
    /// Method names of `pic-console-authentication`.
    pub pic_console_authentication: Vec<String>,
    /// The passwords of `pic-console-authentication`; empty unless the `secrets` feature is enabled.
    pub pic_console_authentication_secrets: Vec<AuthenticationSecret>,
    pub license: Option<License>,
    pub name_servers: Vec<NameServer>,
    pub ntp: Option<Ntp>,
    pub syslog: Option<Syslog>,
    pub login: Option<Login>,
    pub services: Option<Services>,
    pub arp: Option<Arp>,
    pub icmp: Option<Icmp>,
    pub tracing: Option<Tracing>,
    pub proxy: Option<Proxy>,
    pub demux_options: Option<DemuxOptions>,
    pub kernel_replication: Option<KernelReplication>,
    pub password_options: Option<PasswordOptions>,
    pub radius_options: Option<RadiusOptions>,
    pub tacplus_options: Option<TacplusOptions>,
    pub configuration: Option<ConfigurationInput>,
    pub configuration_database: Option<ConfigurationDatabase>,
    pub export_format: Option<ExportFormat>,
    pub health_monitor: Option<HealthMonitor>,
    pub monitor: Option<Monitor>,
    pub resiliency: Option<Resiliency>,
    pub snapshot: Option<Snapshot>,
    pub access_line: Option<AccessLine>,
    pub ddos_protection: Option<DdosProtection>,
    pub fib_streaming: Option<FibStreaming>,
    pub packet_forwarding_options: Option<PacketForwardingOptions>,
    /// The `protocol <name>` entries of `management-traffic`.
    pub management_traffic: Vec<ManagementTrafficProtocol>,
    /// Junos OS Evolved `auto-sw-sync node <name>` statements.
    pub auto_sw_sync: Vec<AutoSwSync>,
    /// Names from `node { offline <name>; }`.
    pub offline_nodes: Vec<String>,
    /// Method name of `boot-loader-authentication`, e.g. `encrypted-password`.
    pub boot_loader_authentication: Vec<String>,
    /// The passwords of `boot-loader-authentication`; empty unless the `secrets` feature is enabled.
    pub boot_loader_authentication_secrets: Vec<AuthenticationSecret>,
    /// Method name of `device-authentication`, e.g. `encrypted-password`.
    pub device_authentication: Vec<String>,
    /// The passwords of `device-authentication`; empty unless the `secrets` feature is enabled.
    pub device_authentication_secrets: Vec<AuthenticationSecret>,
    pub allow_6pe_traceroute: bool,
    pub allow_l3vpn_traceroute_src_select: bool,
    pub dual_phase_bootup: bool,
    pub extended_echo: bool,
    /// `management-instance`: confine the management interface in the `mgmt_junos` instance.
    pub management_instance: bool,
    pub nd_override_preferred_src: bool,
    pub no_hidden_commands: bool,
    pub regex_additive_logic: bool,
    pub unattended_boot: bool,
    pub arp_system_cache_limit: Option<String>,
    pub nd_retransmit_timer: Option<String>,
    pub nd_system_cache_limit: Option<String>,
    /// `rng`: `dyce`, `fortuna` or `hmac-drbg`.
    pub rng: Option<String>,
    /// `Some(true)` for `saved-core-context`, `Some(false)` for `no-saved-core-context`.
    pub saved_core_context: Option<bool>,
    pub saved_core_files: Option<String>,
}

/// Returns the top-level `system` block, or `None` if there is none.
///
/// # Examples
///
/// ```
/// use asterust::config::juniper;
/// use asterust_junos::system::system;
///
/// let config = juniper::parse_braces("system {\n    host-name pe1;\n}\n");
/// let system = system(&config).unwrap();
/// assert_eq!(system.host_name.as_deref(), Some("pe1"));
/// ```
pub fn system(config: &Config) -> Option<System> {
    let system = top_level(config, "system")?;
    Some(System {
        host_name: arg_of(system, "host-name").map(str::to_string),
        domain_name: arg_of(system, "domain-name").map(str::to_string),
        time_zone: arg_of(system, "time-zone").map(str::to_string),
        domain_search: args_of(system, "domain-search")
            .into_iter()
            .flat_map(list_values)
            .collect(),
        static_host_mappings: static_host_mappings(system),
        backup_router: arg_of(system, "backup-router").map(parse_backup_router),
        inet6_backup_router: arg_of(system, "inet6-backup-router").map(parse_backup_router),
        authentication_order: args_of(system, "authentication-order")
            .into_iter()
            .flat_map(list_values)
            .collect(),
        radius_servers: radius_servers(system, "radius-server"),
        tacplus_servers: tacplus_servers(system, "tacplus-server"),
        location: child_block(system, "location").map(parse_location),
        ports: child_block(system, "ports").map(parse_ports),
        max_configurations_on_flash: arg_of(system, "max-configurations-on-flash").map(str::to_string),
        max_configuration_rollbacks: arg_of(system, "max-configuration-rollbacks").map(str::to_string),
        no_redirects: has_leaf(system, "no-redirects"),
        default_address_selection: has_leaf(system, "default-address-selection"),
        internet_options: child_block(system, "internet-options").map(parse_internet_options),
        commit: child_block(system, "commit").map(parse_commit),
        processes: child_block(system, "processes")
            .map(parse_processes)
            .unwrap_or_default(),
        dynamic_profile_options: child_block(system, "dynamic-profile-options").map(parse_dynamic_profile_options),
        extensions: child_block(system, "extensions").map(parse_extensions),
        autoinstallation: child_block(system, "autoinstallation").map(parse_autoinstallation),
        schema: child_block(system, "schema").map(parse_schema),
        pixel_tracing: child_block(system, "pixel-tracing").map(parse_pixel_tracing),
        scripts: child_block(system, "scripts").map(parse_scripts),
        no_multicast_echo: has_leaf(system, "no-multicast-echo"),
        no_ping_record_route: has_leaf(system, "no-ping-record-route"),
        no_ping_time_stamp: has_leaf(system, "no-ping-time-stamp"),
        auto_snapshot: has_leaf(system, "auto-snapshot"),
        compress_configuration_files: has_leaf(system, "compress-configuration-files"),
        mirror_flash_on_disk: has_leaf(system, "mirror-flash-on-disk"),
        switchover_on_routing_crash: has_leaf(system, "switchover-on-routing-crash"),
        use_imported_time_zones: has_leaf(system, "use-imported-time-zones"),
        archival: child_block(system, "archival").map(parse_archival),
        accounting: child_block(system, "accounting").map(parse_accounting),
        root_authentication: root_authentication(system),
        master_password: child_block(system, "master-password").map(parse_master_password),
        diag_port_authentication: password_methods(system, "diag-port-authentication"),
        diag_port_authentication_secrets: password_secrets(system, "diag-port-authentication"),
        pic_console_authentication: password_methods(system, "pic-console-authentication"),
        pic_console_authentication_secrets: password_secrets(system, "pic-console-authentication"),
        license: child_block(system, "license").map(parse_license),
        name_servers: name_servers(system),
        ntp: child_block(system, "ntp").map(parse_ntp),
        syslog: child_block(system, "syslog").map(parse_syslog),
        login: child_block(system, "login").map(parse_login),
        services: child_block(system, "services").map(parse_services),
        arp: child_block(system, "arp").map(parse_arp),
        icmp: child_block(system, "icmp").map(parse_icmp),
        tracing: child_block(system, "tracing").map(parse_tracing),
        proxy: child_block(system, "proxy").map(parse_proxy),
        demux_options: child_block(system, "demux-options").map(parse_demux_options),
        kernel_replication: child_block(system, "kernel-replication").map(parse_kernel_replication),
        password_options: child_block(system, "password-options").map(parse_password_options),
        radius_options: child_block(system, "radius-options").map(parse_radius_options),
        tacplus_options: child_block(system, "tacplus-options").map(parse_tacplus_options),
        configuration: child_block(system, "configuration").map(parse_configuration),
        configuration_database: child_block(system, "configuration-database").map(parse_configuration_database),
        export_format: child_block(system, "export-format").map(parse_export_format),
        health_monitor: child_block(system, "health-monitor").map(parse_health_monitor),
        monitor: child_block(system, "monitor").map(parse_monitor),
        resiliency: child_block(system, "resiliency").map(parse_resiliency),
        snapshot: child_block(system, "snapshot").map(parse_snapshot),
        access_line: child_block(system, "access-line").map(parse_access_line),
        ddos_protection: child_block(system, "ddos-protection").map(parse_ddos_protection),
        fib_streaming: child_block(system, "fib-streaming").map(parse_fib_streaming),
        packet_forwarding_options: child_block(system, "packet-forwarding-options")
            .map(parse_packet_forwarding_options),
        management_traffic: management_traffic(system),
        auto_sw_sync: auto_sw_sync(system),
        offline_nodes: child_block(system, "node")
            .map(|node| args_of(node, "offline").into_iter().map(str::to_string).collect())
            .unwrap_or_default(),
        boot_loader_authentication: password_methods(system, "boot-loader-authentication"),
        boot_loader_authentication_secrets: password_secrets(system, "boot-loader-authentication"),
        device_authentication: password_methods(system, "device-authentication"),
        device_authentication_secrets: password_secrets(system, "device-authentication"),
        allow_6pe_traceroute: has_leaf(system, "allow-6pe-traceroute"),
        allow_l3vpn_traceroute_src_select: has_leaf(system, "allow-l3vpn-traceroute-src-select"),
        dual_phase_bootup: has_leaf(system, "dual-phase-bootup"),
        extended_echo: has_leaf(system, "extended-echo"),
        management_instance: has_leaf(system, "management-instance"),
        nd_override_preferred_src: has_leaf(system, "nd-override-preferred-src"),
        no_hidden_commands: has_leaf(system, "no-hidden-commands"),
        regex_additive_logic: has_leaf(system, "regex-additive-logic"),
        unattended_boot: has_leaf(system, "unattended-boot"),
        arp_system_cache_limit: arg_of(system, "arp-system-cache-limit").map(str::to_string),
        nd_retransmit_timer: arg_of(system, "nd-retransmit-timer").map(str::to_string),
        nd_system_cache_limit: arg_of(system, "nd-system-cache-limit").map(str::to_string),
        rng: arg_of(system, "rng").map(str::to_string),
        saved_core_context: toggle(system, "saved-core-context"),
        saved_core_files: arg_of(system, "saved-core-files").map(str::to_string),
    })
}

/// Servers written as `<keyword> <address> { ... }`, or as `<keyword> { <address> { ... } }`, with
/// their option lines.
fn servers<'a>(system: &'a ConfigLine, keyword: &str) -> Vec<(&'a str, &'a ConfigLine)> {
    let mut found = Vec::new();
    for child in active_children(system) {
        if child.text == keyword {
            found.extend(active_children(child).map(|server| (unquote(&server.text), server)));
        } else if let Some(arg) = child.arg(keyword) {
            found.push((split_name(arg).0, child));
        }
    }
    found
}

/// The method names of a password setting such as `diag-port-authentication`, written either as
/// `<keyword> encrypted-password "...";` or as a block. The passwords are dropped.
fn password_methods(system: &ConfigLine, keyword: &str) -> Vec<String> {
    let mut methods = Vec::new();
    for child in active_children(system) {
        if child.text == keyword {
            methods.extend(authentication_methods(child));
        } else if let Some(method) = child.arg(keyword).and_then(|arg| arg.split_whitespace().next()) {
            methods.push(method.to_string());
        }
    }
    methods
}

/// The name of each statement in an `authentication` block. Secrets can carry a trailing `##
/// SECRET-DATA` marker, so only the first word is kept.
fn authentication_methods(auth: &ConfigLine) -> Vec<String> {
    active_children(auth)
        .filter_map(|c| c.text.split_whitespace().next())
        .map(str::to_string)
        .collect()
}

#[cfg(test)]
mod tests {
    use crate::system::system;
    use asterust::config::juniper;

    // Not from documentation: written from the CLI Reference syntax pages. See the README "Sources".
    #[test]
    fn extracts_host_name() {
        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
        assert_eq!(system.host_name.as_deref(), Some("pe1"));
    }

    #[test]
    fn host_name_is_optional() {
        let system = system(&juniper::parse_braces("system {\n    domain-name example.net;\n}\n")).unwrap();
        assert_eq!(system.host_name, None);
    }

    #[test]
    fn skips_inactive_host_name() {
        let system = system(&juniper::parse_braces("system {\n    inactive: host-name pe1;\n}\n")).unwrap();
        assert_eq!(system.host_name, None);
    }

    #[test]
    fn extracts_domain_name() {
        let system = system(&juniper::parse_braces(
            "system {\n    host-name pe1;\n    domain-name example.net;\n}\n",
        ))
        .unwrap();
        assert_eq!(system.domain_name.as_deref(), Some("example.net"));
    }

    #[test]
    fn domain_name_is_optional() {
        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
        assert_eq!(system.domain_name, None);
    }

    #[test]
    fn extracts_time_zone() {
        let system = system(&juniper::parse_braces("system {\n    time-zone America/New_York;\n}\n")).unwrap();
        assert_eq!(system.time_zone.as_deref(), Some("America/New_York"));
    }

    #[test]
    fn time_zone_is_optional() {
        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
        assert_eq!(system.time_zone, None);
    }

    #[test]
    fn extracts_configuration_limits_and_no_redirects() {
        let system = system(&juniper::parse_braces(
            "system {\n    max-configurations-on-flash 5;\n    max-configuration-rollbacks 20;\n    no-redirects;\n}\n",
        ))
        .unwrap();
        assert_eq!(system.max_configurations_on_flash.as_deref(), Some("5"));
        assert_eq!(system.max_configuration_rollbacks.as_deref(), Some("20"));
        assert!(system.no_redirects);
    }

    #[test]
    fn configuration_limits_are_optional() {
        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
        assert_eq!(system.max_configurations_on_flash, None);
        assert_eq!(system.max_configuration_rollbacks, None);
        assert!(!system.no_redirects);
    }

    #[test]
    fn extracts_system_flags() {
        let system = system(&juniper::parse_braces(
            "system {\n    no-multicast-echo;\n    no-ping-record-route;\n    no-ping-time-stamp;\n    auto-snapshot;\n    compress-configuration-files;\n    mirror-flash-on-disk;\n    switchover-on-routing-crash;\n    use-imported-time-zones;\n}\n",
        ))
        .unwrap();
        assert!(system.no_multicast_echo);
        assert!(system.no_ping_record_route);
        assert!(system.no_ping_time_stamp);
        assert!(system.auto_snapshot);
        assert!(system.compress_configuration_files);
        assert!(system.mirror_flash_on_disk);
        assert!(system.switchover_on_routing_crash);
        assert!(system.use_imported_time_zones);
    }

    #[test]
    fn system_flags_default_to_off() {
        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
        assert!(!system.no_multicast_echo);
        assert!(!system.auto_snapshot);
        assert!(!system.use_imported_time_zones);
    }

    #[test]
    fn no_system_is_none() {
        assert!(system(&juniper::parse_braces("interfaces {\n    lo0;\n}\n")).is_none());
    }

    #[test]
    fn diag_port_and_pic_console_report_only_the_method() {
        let system = system(&juniper::parse_braces(
            r#"
system {
    diag-port-authentication encrypted-password "$6$salt$hash"; ## SECRET-DATA
    pic-console-authentication {
        encrypted-password "$6$salt$other"; ## SECRET-DATA
    }
}
"#,
        ))
        .unwrap();
        assert_eq!(system.diag_port_authentication, ["encrypted-password"]);
        assert_eq!(system.pic_console_authentication, ["encrypted-password"]);
        let values = |secrets: &[crate::system::AuthenticationSecret]| -> Vec<String> {
            secrets.iter().map(|s| s.value.expose().to_string()).collect()
        };
        let (diag, pic) = if cfg!(feature = "secrets") {
            (vec!["$6$salt$hash".to_string()], vec!["$6$salt$other".to_string()])
        } else {
            (Vec::new(), Vec::new())
        };
        assert_eq!(values(&system.diag_port_authentication_secrets), diag);
        assert_eq!(values(&system.pic_console_authentication_secrets), pic);
    }

    #[test]
    fn secret_settings_are_optional() {
        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
        assert!(system.master_password.is_none());
        assert!(system.diag_port_authentication.is_empty());
        assert!(system.pic_console_authentication.is_empty());
    }

    #[test]
    fn extracts_authentication_order() {
        let system = system(&juniper::parse_braces(
            "system {\n    authentication-order [ tacplus radius password ];\n}\n",
        ))
        .unwrap();
        assert_eq!(system.authentication_order, ["tacplus", "radius", "password"]);
    }

    #[test]
    fn authentication_settings_are_optional() {
        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
        assert!(system.authentication_order.is_empty());
        assert!(system.radius_servers.is_empty());
        assert!(system.tacplus_servers.is_empty());
    }

    #[test]
    fn extracts_domain_search_list() {
        let system = system(&juniper::parse_braces(
            "system {\n    domain-search [ example.net lab.example.net ];\n}\n",
        ))
        .unwrap();
        assert_eq!(system.domain_search, ["example.net", "lab.example.net"]);
    }

    #[test]
    fn addressing_settings_are_optional() {
        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
        assert!(system.domain_search.is_empty());
        assert!(system.static_host_mappings.is_empty());
        assert!(system.backup_router.is_none());
        assert!(system.inet6_backup_router.is_none());
    }

    #[test]
    fn extracts_the_scalar_flags_and_limits() {
        let system = system(&juniper::parse_braces(
            r#"
system {
    allow-6pe-traceroute;
    allow-l3vpn-traceroute-src-select;
    dual-phase-bootup;
    extended-echo;
    management-instance;
    nd-override-preferred-src;
    no-hidden-commands;
    regex-additive-logic;
    unattended-boot;
    arp-system-cache-limit 50000;
    nd-retransmit-timer 2000;
    nd-system-cache-limit 150000;
    rng fortuna;
    saved-core-files 3;
    saved-core-context;
}
"#,
        ))
        .unwrap();
        assert!(system.allow_6pe_traceroute);
        assert!(system.allow_l3vpn_traceroute_src_select);
        assert!(system.dual_phase_bootup);
        assert!(system.extended_echo);
        assert!(system.management_instance);
        assert!(system.nd_override_preferred_src);
        assert!(system.no_hidden_commands);
        assert!(system.regex_additive_logic);
        assert!(system.unattended_boot);
        assert_eq!(system.arp_system_cache_limit.as_deref(), Some("50000"));
        assert_eq!(system.nd_retransmit_timer.as_deref(), Some("2000"));
        assert_eq!(system.nd_system_cache_limit.as_deref(), Some("150000"));
        assert_eq!(system.rng.as_deref(), Some("fortuna"));
        assert_eq!(system.saved_core_files.as_deref(), Some("3"));
        assert_eq!(system.saved_core_context, Some(true));
    }

    #[test]
    fn reads_no_saved_core_context() {
        let system = system(&juniper::parse_braces("system {\n    no-saved-core-context;\n}\n")).unwrap();
        assert_eq!(system.saved_core_context, Some(false));
    }

    #[test]
    fn scalar_flags_and_limits_are_optional() {
        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
        assert!(!system.allow_6pe_traceroute);
        assert!(!system.management_instance);
        assert!(!system.unattended_boot);
        assert_eq!(system.arp_system_cache_limit, None);
        assert_eq!(system.rng, None);
        assert_eq!(system.saved_core_context, None);
        assert!(system.offline_nodes.is_empty());
    }

    #[test]
    fn extracts_offline_nodes() {
        let system = system(&juniper::parse_braces(
            "system {\n    node {\n        offline re1;\n        offline fpc3;\n    }\n}\n",
        ))
        .unwrap();
        assert_eq!(system.offline_nodes, ["re1", "fpc3"]);
    }

    #[test]
    fn boot_loader_and_device_authentication_report_only_the_method() {
        let system = system(&juniper::parse_braces(
            r#"
system {
    boot-loader-authentication {
        encrypted-password "$1$salt$hash"; ## SECRET-DATA
    }
    device-authentication {
        encrypted-password "$6$salt$other"; ## SECRET-DATA
    }
}
"#,
        ))
        .unwrap();
        assert_eq!(system.boot_loader_authentication, ["encrypted-password"]);
        assert_eq!(system.device_authentication, ["encrypted-password"]);
        let values = |secrets: &[crate::system::AuthenticationSecret]| -> Vec<String> {
            secrets.iter().map(|s| s.value.expose().to_string()).collect()
        };
        let (boot, device) = if cfg!(feature = "secrets") {
            (vec!["$1$salt$hash".to_string()], vec!["$6$salt$other".to_string()])
        } else {
            (Vec::new(), Vec::new())
        };
        assert_eq!(values(&system.boot_loader_authentication_secrets), boot);
        assert_eq!(values(&system.device_authentication_secrets), device);
    }
}