signstar_config/config/
error.rs1use std::path::PathBuf;
4
5#[cfg(feature = "nethsm")]
6use nethsm::{KeyId, NamespaceId, SystemWideUserId, UserId};
7
8use crate::{SystemUserId, config::Config};
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 #[error("No SSH authorized key provided!")]
144 NoAuthorizedKeys,
145
146 #[error("No mapping found where a system user matches the name {name}")]
148 NoMatchingMappingForSystemUser {
149 name: String,
151 },
152
153 #[error(
156 "Shamir's Secret Sharing not used for administrative secret handling, but the following users are setup to handle shares: {share_users:?}"
157 )]
158 NoSssButShareUsers {
159 share_users: Vec<SystemUserId>,
161 },
162
163 #[cfg(feature = "nethsm")]
165 #[error("User data invalid: {0}")]
166 User(#[from] nethsm::UserError),
167
168 #[error("SSH key error: {0}")]
170 SshKey(#[from] ssh_key::Error),
171
172 #[error("YAML deserialization error while {context}:\n{source}")]
174 YamlDeserialize {
175 context: String,
179 source: serde_saphyr::Error,
181 },
182
183 #[error("YAML serialization error while {context}:\n{source}")]
185 YamlSerialize {
186 context: &'static str,
190 source: serde_saphyr::ser_error::Error,
192 },
193}