nethsm_config/
lib.rs

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
//! A library for working with application configuration files for [Nitrokey NetHSM] devices
//!
//! Provides configuration file management for custom applications designed around working with
//! [Nitrokey NetHSM] devices or containers.
//! Configuration settings allow for individualizing the configuration use and its use-cases
//! (interactive or non-interactive).
//!
//! A module for interactive prompts provides extra convenience around creating applications that
//! may request further data from their users interactively.
//!
//! # Examples
//!
//! ```
//! use nethsm::{ConnectionSecurity, UserRole};
//! use nethsm_config::{Config, ConfigCredentials, ConfigInteractivity, ConfigSettings};
//!
//! # fn main() -> testresult::TestResult {
//! // a configuration for a non-interactive application called "my_app"
//! let config_settings = ConfigSettings::new(
//!     "my_app".to_string(),
//!     ConfigInteractivity::NonInteractive,
//!     None,
//! );
//!
//! // let's assume a custom configuration file path
//! let tmpfile = testdir::testdir!().join("my_app.conf");
//! let config = Config::new(config_settings, Some(&tmpfile))?;
//!
//! // add a first device to commnicate with
//! config.add_device(
//!     "nethsm1".to_string(),
//!     "https://example.org/api/v1".parse()?,
//!     ConnectionSecurity::Unsafe,
//! )?;
//!
//! // add credentials to communicate with the the device
//! config.add_credentials(
//!     "nethsm1".to_string(),
//!     ConfigCredentials::new(
//!         UserRole::Administrator,
//!         "admin1".parse()?,
//!         Some("my-passphrase".to_string()),
//!     ),
//! )?;
//!
//! // write configuration to file
//! config.store(Some(&tmpfile))?;
//! # Ok(())
//! # }
//! ```
//! [Nitrokey NetHSM]: https://docs.nitrokey.com/nethsm/
mod config;
mod credentials;
mod mapping;
mod prompt;

pub use config::{
    AdministrativeSecretHandling,
    Config,
    ConfigInteractivity,
    ConfigName,
    ConfigSettings,
    Connection,
    DeviceConfig,
    Error,
    HermeticParallelConfig,
    NonAdministrativeSecretHandling,
};
pub use credentials::{
    AuthorizedKeyEntry,
    AuthorizedKeyEntryList,
    ConfigCredentials,
    SystemUserId,
    SystemWideUserId,
};
pub use mapping::{NetHsmMetricsUsers, UserMapping};
pub use prompt::{PassphrasePrompt, UserPrompt};