auths_core/ports/
config_store.rs1use std::path::PathBuf;
4
5use thiserror::Error;
6
7#[derive(Debug, Error)]
9pub enum ConfigStoreError {
10 #[error("failed to read config from {path}")]
12 Read {
13 path: PathBuf,
15 #[source]
17 source: std::io::Error,
18 },
19 #[error("failed to write config to {path}")]
21 Write {
22 path: PathBuf,
24 #[source]
26 source: std::io::Error,
27 },
28}
29
30impl auths_crypto::AuthsErrorInfo for ConfigStoreError {
31 fn error_code(&self) -> &'static str {
32 match self {
33 Self::Read { .. } => "AUTHS-E3951",
34 Self::Write { .. } => "AUTHS-E3952",
35 }
36 }
37
38 fn suggestion(&self) -> Option<&'static str> {
39 match self {
40 Self::Read { .. } => Some("Check that ~/.auths/config.toml exists and is readable"),
41 Self::Write { .. } => Some("Check file permissions for ~/.auths/config.toml"),
42 }
43 }
44}
45
46pub trait ConfigStore: Send + Sync {
57 fn read(&self, path: &std::path::Path) -> Result<Option<String>, ConfigStoreError>;
60
61 fn write(&self, path: &std::path::Path, content: &str) -> Result<(), ConfigStoreError>;
63}