Skip to main content

nethsm/cli/config/
mod.rs

1//! A module for working with application configuration files for [Nitrokey NetHSM] devices
2//!
3//! Provides configuration file management for custom applications designed around working with
4//! [Nitrokey NetHSM] devices or containers.
5//! Configuration settings allow for individualizing the configuration use and its use-cases
6//! (interactive or non-interactive).
7//!
8//! A module for interactive prompts provides extra convenience around creating applications that
9//! may request further data from their users interactively.
10//!
11//! # Examples
12//!
13//! ```
14//! use nethsm::{
15//!     ConnectionSecurity,
16//!     UserRole,
17//!     cli::{Config, ConfigCredentials, ConfigInteractivity, ConfigSettings},
18//! };
19//! use tempfile::TempDir;
20//!
21//! # fn main() -> testresult::TestResult {
22//! // a configuration for a non-interactive application called "my_app"
23//! let config_settings = ConfigSettings::new(
24//!     "my_app".to_string(),
25//!     ConfigInteractivity::NonInteractive,
26//!     None,
27//! );
28//!
29//! // let's assume a custom configuration file path
30//! let temp_dir = TempDir::new()?;
31//! let tmpfile = temp_dir.path().join("my_app.conf");
32//! let config = Config::new(config_settings, Some(&tmpfile))?;
33//!
34//! // add a first device to commnicate with
35//! config.add_device(
36//!     "nethsm1".to_string(),
37//!     "https://example.org/api/v1".parse()?,
38//!     ConnectionSecurity::Unsafe,
39//! )?;
40//!
41//! // add credentials to communicate with the the device
42//! config.add_credentials(
43//!     "nethsm1".to_string(),
44//!     ConfigCredentials::new(
45//!         UserRole::Administrator,
46//!         "admin1".parse()?,
47//!         Some("my-passphrase".to_string()),
48//!     ),
49//! )?;
50//!
51//! // write configuration to file
52//! config.store(Some(&tmpfile))?;
53//! # Ok(())
54//! # }
55//! ```
56//! [Nitrokey NetHSM]: https://docs.nitrokey.com/nethsm/
57mod credentials;
58mod file;
59mod prompt;
60
61pub use credentials::ConfigCredentials;
62pub use file::{Config, ConfigInteractivity, ConfigName, ConfigSettings, DeviceConfig, Error};
63pub use prompt::{PassphrasePrompt, UserPrompt};