signstar_config/config/
error.rs1use std::path::PathBuf;
4
5#[cfg(feature = "nethsm")]
6use nethsm::{KeyId, NamespaceId, SystemWideUserId, UserId};
7
8use crate::config::{Config, SystemUserId};
9
10#[derive(Debug, thiserror::Error)]
12pub enum Error {
13 #[error("No configuration file found in {}.",
15 Config::list_config_dirs().iter().map(|path| path.display().to_string()).collect::<Vec<_>>().join(", ")
16 )]
17 ConfigIsMissing,
18
19 #[error("The Signstar configuration file {path} has no file extension.")]
21 MissingFileExtension {
22 path: PathBuf,
24 },
25
26 #[error(
28 "The Signstar configuration file {path} uses the unsupported file extension {extension}."
29 )]
30 UnsupportedFileExtension {
31 path: PathBuf,
33 extension: String,
35 },
36
37 #[cfg(feature = "nethsm")]
39 #[error("The NetHSM user ID {nethsm_user_id} is used more than once!")]
40 DuplicateNetHsmUserId {
41 nethsm_user_id: UserId,
43 },
44
45 #[error("The SSH public key \"{ssh_public_key}\" is used more than once!")]
47 DuplicateSshPublicKey {
48 ssh_public_key: String,
50 },
51
52 #[cfg(feature = "nethsm")]
54 #[error(
55 "The key ID \"{key_id}\" ({}) is used more than once",
56 if let Some(namespace) = namespace {
57 format!("namespace: \"{namespace}\"")
58 } else {
59 "system-wide".to_string()
60 },
61 )]
62 DuplicateKeyId {
63 key_id: KeyId,
65 namespace: Option<NamespaceId>,
67 },
68
69 #[error("The system user ID {system_user_id} is used more than once!")]
71 DuplicateSystemUserId {
72 system_user_id: SystemUserId,
74 },
75
76 #[cfg(feature = "nethsm")]
78 #[error(
79 "The tag {tag} ({}) is used more than once",
80 if let Some(namespace) = namespace {
81 format!("namespace: \"{namespace}\"")
82 } else {
83 "system-wide".to_string()
84 },
85 )]
86 DuplicateTag {
87 tag: String,
89 namespace: Option<NamespaceId>,
91 },
92
93 #[error("The system user name {name} is invalid")]
95 InvalidSystemUserName {
96 name: String,
98 },
99
100 #[error("The SSH authorized key \"{entry}\" is invalid")]
102 InvalidAuthorizedKeyEntry {
103 entry: String,
105 },
106
107 #[cfg(feature = "nethsm")]
110 #[error("The NetHsm user {metrics_user} is both in the Metrics and Operator role!")]
111 MetricsAlsoOperator {
112 metrics_user: SystemWideUserId,
116 },
117
118 #[cfg(feature = "nethsm")]
121 #[error(
122 "No user in the Administrator role exists ({})",
123 if let Some(namespaces) = namespaces {
124 namespaces.iter().map(|id| id.to_string()).collect::<Vec<_>>().join(", ")
125 } else {
126 "system-wide".to_string()
127 }
128 )]
129 MissingAdministrator {
130 namespaces: Option<Vec<NamespaceId>>,
132 },
133
134 #[error("No system user for downloading shares of a shared secret exists.")]
136 MissingShareDownloadSystemUser,
137
138 #[error("No system user for uploading shares of a shared secret exists.")]
140 MissingShareUploadSystemUser,
141
142 #[cfg(feature = "nethsm")]
144 #[error("No NetHSM section found in the Signstar configuration file.")]
145 NetHsmSectionMissing,
146
147 #[error("No SSH authorized key provided!")]
149 NoAuthorizedKeys,
150
151 #[error("No mapping found where a system user matches the name {name}")]
153 NoMatchingMappingForSystemUser {
154 name: String,
156 },
157
158 #[error(
161 "Shamir's Secret Sharing not used for administrative secret handling, but the following users are setup to handle shares: {share_users:?}"
162 )]
163 NoSssButShareUsers {
164 share_users: Vec<SystemUserId>,
166 },
167
168 #[cfg(feature = "nethsm")]
170 #[error("User data invalid: {0}")]
171 User(#[from] nethsm::UserError),
172
173 #[error("SSH key error: {0}")]
175 SshKey(#[from] ssh_key::Error),
176
177 #[error("YAML deserialization error while {context}:\n{source}")]
179 YamlDeserialize {
180 context: String,
184 source: Box<serde_saphyr::Error>,
186 },
187
188 #[error("YAML serialization error while {context}:\n{source}")]
190 YamlSerialize {
191 context: &'static str,
195 source: Box<serde_saphyr::ser_error::Error>,
197 },
198
199 #[cfg(feature = "yubihsm2")]
201 #[error("No YubiHSM2 section found in the Signstar configuration file.")]
202 YubiHsm2SectionMissing,
203}