Skip to main content

Module config

Module config 

Source
Expand description

A module 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,
    cli::{Config, ConfigCredentials, ConfigInteractivity, ConfigSettings},
};
use tempfile::TempDir;

// 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 temp_dir = TempDir::new()?;
let tmpfile = temp_dir.path().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))?;

Re-exportsยง

pub use credentials::ConfigCredentials;
pub use file::Config;
pub use file::ConfigInteractivity;
pub use file::ConfigName;
pub use file::ConfigSettings;
pub use file::DeviceConfig;
pub use file::Error;
pub use prompt::PassphrasePrompt;
pub use prompt::UserPrompt;

Modulesยง

credentials ๐Ÿ”’
file ๐Ÿ”’
prompt ๐Ÿ”’